draw Line by openGL - Java javax.media.opengl

Java examples for javax.media.opengl:GL

Description

draw Line by openGL

Demo Code


import java.awt.Color;
import javax.media.opengl.GL;

public class Main{
    public static void drawLine(GL gl, Color color, Point one, Point two) {
        setColor(gl, color);/*from  ww  w .  j  av  a  2  s .c om*/
        gl.glBegin(GL.GL_LINES);
        gl.glVertex2i(one.x, one.y);
        gl.glVertex2i(two.x, two.y);
        gl.glEnd();
        gl.glBegin(GL.GL_LINES);
        gl.glVertex2i(one.x, one.y);
        gl.glVertex2i(two.x, two.y);
        gl.glEnd();
    }
    public static void setColor(GL gl, Color color) {
        if (color != null) {
            float red = color.getRed() / 255f;
            float green = color.getGreen() / 255f;
            float blue = color.getBlue() / 255f;
            float alpha = color.getAlpha() / 255f;

            gl.glColor4f(red, green, blue, alpha);
        }
    }
}

Related Tutorials