Clear The Buffer

Drawing basic 3d shapes and notice that when I start using the glVertex3f(x,y,z) commands between a glBegin(CL_LINES) and glEnd(), a line is drawn from somewhere in space to my first point. How can I “clear the drawing buffer” so that I only start from my first point and draw until I get to the last point. I believe that the system starts drawing from a point in space until it gets to my first point. I index my values in x,y and z and incrementally step through in a fashion by using the commands: glVertex3f(x(index),y(index),z(index)) and glVertex3f(x(index+1),y(index+1),z(index+1)) in a loop until all points are drawn. A response will be appreciated. Not a complex user but only use OpenGL to “picture” the results of my mathematical computations to visualize curve development from numerical data.

This is incorrect. With GL_LINES, a line segment is drawn between each pair of points: 0-1, 2-3, 4-5, etc.

Check that you’re actually setting the first element of the array.

It sounds like you’d be better off with GL_LINE_STRIP.

Typo, meant to say glBegin(GL_LINES). Also, using fortran and the first element of the array is Index = 1 and it is set. Yet, when I draw the curve info, all is correct except when the system goes to the first point, it comes from a location at x,y,z=n where n is a large number, not sure why. Additionally, why would GL_LINE_STRIP be different?

This suggests an issue in your code.

Note that OpenGL doesn’t have a concept of “current vertex position”. It does have a current value for the other attributes (texture coordinates, normal, colour), but not the position. If it’s using a vertex with garbage coordinates, those coordinates are being passed to it from the application code somehow.

GL_LINE_STRIP avoids the need to pass all of the interior (non-endpoint) vertices twice. Also, if you have an array of vertices (rather than separate arrays for the x, y and z components), you could just use glDrawArrays() rather than a loop.