grid lines

how do you draw 3d grid lines in opengl?
since i want to have a better view of my 3d figure in the viewing plane

any ideas?

thank you

glBegin(GL_LINES);
glVertex(pointA);
glVertex(pointB);
glEnd();

The following pseudo-code will draw a line from point A to point B. To draw a grid of lines, you simply setup 2 loops which span the X,Y, or Z axis, drawing lines as it goes. Very simple stuff man.

you might try:

//dx, dy are thichness parameters of grid
float xmin=-50.0, xmax=50.0, dx=5.0, x;
float ymin=-50.0, ymax=50.0, dy=5.0, y;

glBegin(GL_LINES);

for(x=xmin; x<=xmax; x+=dx)
{
for(y=ymin; y<=ymax; y+=dy)
{
glVertex3f(x, ymin, 0.0);
glVertex3f(x, ymax, 0.0);

 glVertex3f(xmin, y, 0.0);
 glVertex3f(xmax, y, 0.0);

}
}

glEnd();

But I don’t know if that works

[This message has been edited by Tenson (edited 09-29-2003).]

Originally posted by Tenson:

Ok, that’s simple enough, but how do figure out the minimum Xmin, Xmax, Ymin, Ymax values for a grid that will extend out to the edges of a perspective view frustum, but not beyond, reguardless of orientation of the model/grid? Does that make sense?

xmin = -screen.x/2.0;
xmax = screen.x/2.0;
ymin = -screen.y/2.0;
ymax = screen.y/2.0

screen.x & screen.y are the same as in glOrtho() …

Originally posted by Tenson:
[b]xmin = -screen.x/2.0;
xmax = screen.x/2.0;
ymin = -screen.y/2.0;
ymax = screen.y/2.0

screen.x & screen.y are the same as in glOrtho() …[/b]

Right, but I’d like to keep the number of glVertex*() calls to a minimum, so I think I’d rather figure out a way to do this using world coordinates. Or maybe there is a way to calculate a scale for the screen coordinates. Let’s see, maybe gluUnProject() would do it.