PDA

View Full Version : simple problem= for loops



brispace
05-06-2005, 12:39 AM
what is wrong with this:

int h = 0;
int i = 0;

for (i = 0; i >= 10; i++)
{
glBegin(GL_QUADS);
glVertex3f(i, h, i);
glVertex3f(i, h, i-1);
glVertex3f(i+1, h, i-1);
glVertex3f(i+1, h, i);
glEnd();
}

nothing is displayed when i run it... but when i remove the loop and keep i=0 it works once?

yuguanglong
05-06-2005, 02:00 AM
The glBegin() and glEnd() should not be put into the loop.
Mabye, it will work well like below.

glBegin(GL_QUADS);
for (i = 0; i >= 10; i++)
{
glVertex3f(i, h, i);
glVertex3f(i, h, i-1);
glVertex3f(i+1, h, i-1);
glVertex3f(i+1, h, i);

}
glEnd();

nothing is displayed when i run it... but when i remove the loop and keep i=0 it works once?[/QB][/QUOTE]

Relic
05-06-2005, 02:51 AM
Cool, a "spot the programming error" question. :)

i = 0 is not >= 10. The for-loop is not taken.
You probably wanted < 10 to get 10 iterations.

Rest applies, put the glBegin glEnd outside for performance reasons.
Make sure your projection contains the calculated z-coordinates.
If you look at this in a standard glOrtho projection it's possible to look directly onto the xz-edge, still nothing displayed.

powerpad
05-06-2005, 05:19 AM
look at your loop condition it says
for(i = 0; i >= 10; i++)

this not satisfied for the initial value of
i = 0 ; 0 < 10

you probably meant i <= 10;