PDA

View Full Version : Problem with GL_QUADS



jacksmash
12-12-2007, 02:21 PM
Ok, here's the deal. There's something about perspective that I'm obviously not understanding. The following code draws a rectangle just fine:



void drawRect(void)
{
glPushMatrix();
glColor3f(1.0,0.1,1.0);

glTranslatef(0.0, 0.0, -150.0);
glRectf(-10.0, -10.0, 10.0, 10.0);

glPopMatrix();
}


But, if I change the glRectf call with the following:



glEnable(GL_QUADS);
glVertex3f(-10.0, -10.0, 0.0);
glVertex3f(-10.0, 10.0, 0.0);
glVertex3f(10.0, 10.0, 0.0);
glVertex3f(10.0, -10.0, 0.0);
glEnd();


Then nothing displays! Here is my drawScene code if it might be helpful



void drawScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, 1.0, 1.0, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(-cam.roll, 0, 0, 1);
glRotatef(-cam.pitch, 1, 0, 0);
glRotatef(-cam.head, 0, 1, 0);
glTranslatef(-cam.x, -cam.y, -cam.z);

drawRect();

glFlush();
glutSwapBuffers();
}


I hate to post a thread that says basically 'help me fix my code', but it's more the understanding I'm worried about. Why would the Quad not display, but the rectangle shows up fine?

Cheers.

-NiCo-
12-12-2007, 02:27 PM
You should use glBegin(GL_QUADS) instead of glEnable(GL_QUADS).
If that doesn't work, try ordering your glVertexf calls so that the quad is drawn in counterclockwise (CCW) order. Most likely your quad is then being culled right now because it's normal is facing away from the camera.

Cheers,
Nico

jacksmash
12-12-2007, 02:45 PM
Oh man, I'm such an idiot.

I'll see if I can delete this thread somehow. Thanks for pointing it out.