View Full Version : grid lines

edwong

09-28-2003, 07:25 PM

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.

Tenson

09-29-2003, 02:52 AM

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 http://www.opengl.org/discussion_boards/ubb/wink.gif

[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?

Tenson

10-01-2003, 05:11 AM

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:

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() ...

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.

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.