Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Normals (Quads)

  1. #1
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    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 :
    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!

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,169
    Quote Originally Posted by lordbittmann View Post
    they still look messed up.
    Code :
    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.
    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. #3
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    204
    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
  •