# The Industry's Foundation for High Performance Graphics

1. ## Normals (Quads)

I've been having trouble getting normals to show up in my project. I've researched the formula and have calculated normals using it, but in the end, they still look messed up.

Is there a different method for getting normals for quads? Here's some of my code for reference:

Code :
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(1.0, 2.0, 1.0);
glVertex3f(1.0, 0.0, 1.0);
glVertex3f(-1.0, 0.0, 1.0);
glVertex3f(-1.0, 2.0, 1.0);
glPopAttrib();
glPopMatrix();
glEnd();

glPushMatrix();
glBegin(GL_TRIANGLES);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(0.0, 4.0, 0.0);
glVertex3f(1.0, 2.0, 1.0);
glVertex3f(-1.0, 2.0, 1.0);
glPopMatrix();
glEnd();

glPushMatrix();
glColor3f(0.0, 0.0, 1.0);
glNormal3f(0.89, 0, -0.44);
glVertex3f(-1.0, 2.0, 1.0);
glVertex3f(-1.0, 0.0, 1.0);
glVertex3f(-2.0, 0.0, -1.0);
glVertex3f(-2.0, 2.0, -1.0);
glPopMatrix();
glEnd();

Is there anything else I'm doing wrong? Thanks in advance!

2. Originally Posted by lordbittmann
they still look messed up.
Code :
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(1.0, 2.0, 1.0);
glVertex3f(1.0, 0.0, 1.0);
glVertex3f(-1.0, 0.0, 1.0);
glVertex3f(-1.0, 2.0, 1.0);
glPopAttrib();
glPopMatrix();
glEnd();
This is messed up, for sure. What is:
glPopAttrib();
glPopMatrix();
doing between glBegin and glEnd ?
Similarly for your other two tringles and quads.
Your normal calulation depends on whether you want a per vertex normal or a per face normal. For simple objects like yours, per face is reasonable, but you really should specify it, eg insert a new glNormal3f iin the code for glBegin(GL_Triangles) before the glVertex3f command.
Code :
glPushMatrix();
glBegin(GL_TRIANGLES);
glColor3f(1.0, 1.0, 1.0);
glNormal3f (x,y,z);
glVertex3f(0.0, 4.0, 0.0);
glVertex3f(1.0, 2.0, 1.0);
glVertex3f(-1.0, 2.0, 1.0);
glEnd();
glpopmatrix;
strictly speaking, the push/pop is not required either, as you are not altering the modelview matrix by issuing the glVertex3f commands.

3. why dont you use shaders? its lot much easier with shaders..

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•