PDA

View Full Version : 3d grid in opengl



majumder
01-27-2004, 07:05 PM
anybody can help me to write a 3d mesh(grid) in opengl.

SofaSurfa
01-28-2004, 04:49 PM
float worldsize = 25.0f;
float y = 0.0f
float step = 0.5f
for(float x = -worldsize; x <= worldsize; x += step)
{
glBegin(GL_TRIANGLE_STRIP);
for(float z = -worldsize; z <= worldsize; z +=step)
{
glVertex3f(x, y, z);
glVertex3f(x, y, z + step);
}
glEnd();
}

That will give you a grid of triangle strips.
Hope this is what you wanted. Use glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); if you wanted to see the lines.

Regards,
Troy