PDA

View Full Version : drawing verticle lines



fox
12-10-2000, 11:11 PM
Hi
I have drawn verticle lines for a grid
glVertex3d(-30.0, -3.0, -16.0);
glVertex3d(-30.0, -3.0, 16.0);
.
.
glVertex3d(30.0, -3.0, -16.0);
glVertex3d(30.0, -3.0, 16.0);

how could I code it more efficiently I thought of doing it in a for-loop but the program hangs up
int vertx, vertz;
for (vertx=-30,vertz=-16; vertx<=30; vertx+2)
for(vertx=-30, vertz=16; vertx<=30;vertx+2)
glMaterialfv(GL_FRONT, GL_AMBIENT, GreenSurface);
glBegin(GL_LINES);
glVertex3d(vertx, -3.0, vertz);
glEnd();

jc
12-10-2000, 11:28 PM
With those two loops, the param vertz is always set to 16 no ???

U should also (that's not a bug) put the loop between ur glBegin()-glEnd();

if i were you, i would try:

glBegin(GL_LINES);
for (vertx = -30 ; vertx <= 30 ; vertx +=2)
{
glVertex3d(vertx, -3.0, -16);
glVertex3d(vertx, -3.0, 16);
}

for (vertz = -16 ; vertz <= 16 ; vertz +=2)
{
glVertex3d(-30.0, -3.0, vertz);
glVertex3d(30.0, -3.0, vertz);
}
glEnd();

Hope it will help you

FooLman
12-10-2000, 11:29 PM
Hi,
If this is an actual snipet from your code, then it simply never gets to glMaterial, as there is a problem with the loop.
The inner loop resets the variable of the outer one making it an endless one.
Try something like this:
int vertx;
glMaterialfv(GL_FROMT, GL_AMBIENT, GreenSurface);
glBegin(GL_LINES);
for (vertx=-30; vertx<=30; vertx+=2)
{
glVertex3d(vertx, -3.0, -16);
glVertex3d(vertx, -3.0, 16);

}
glEnd();

fox
12-11-2000, 12:30 AM
thanx, that works!!