PDA

View Full Version : Normals (Quads)



lordbittmann
02-19-2013, 02:48 AM
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:



glBegin(GL_QUADS);
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();
glBegin(GL_QUADS);
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!

BionicBytes
02-19-2013, 05:55 AM
they still look messed up.


glBegin(GL_QUADS);
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.


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.

debonair
02-19-2013, 06:56 AM
why dont you use shaders? its lot much easier with shaders..