Contents / Previous / Next


Lines

In OpenGL, line means line segment, not the mathematician's version that extends to infinity in both directions.


Two Connected Series of Line Segments

As with the points, lines are defined using GL.GL_LINES and by providing the vertices at their endpoints with glVertex:

gl.glBegin (GL.GL_LINES);
 gl.glVertex2i (5, 2);
 gl.glVertex2i (7, 0);
 gl.glVertex3f( 0.25f, -0.25f, 0);
 gl.glVertex3f(-0.25f,  0.25f, 0);
gl.glEnd();

A more Java-like drawLine() method could look like this:

public void drawLine (GL gl, Point p1, Point p2) {
   gl.glBegin (GL.GL_LINES);
     gl.glVertex2i (p1.x, p1.y);
     gl.glVertex2i (p2.x, p2.y);
   gl.glEnd();
}