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 7 of 7

Thread: glNormal?

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2001
    Posts
    19

    glNormal?

    I'm having some trouble understanging what the glNormal command does between glBegin and glEnd. I understand what a normal to a plane is and everything but i just don't see how this book is useing normals to create a better looking sphere. How do normals take a bunch of triangles (making up a 20 sided object) and create a sphere. Anyhelp gere would be great thanx

  2. #2
    Guest

    Re: glNormal?

    The normals are used in shading calculations, not in the construction of the underlying geometry. And with smooth shading your choppy looking 20 sided object will look more closely like a sphere.

    -Paul

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2001
    Posts
    19

    Re: glNormal?

    but there were 2 sets of code:

    glBegin(GL_TRIANGLES);
    for (i = 0; i < 20; i++) {

    glVertexfv(...)
    glVertexfv(...)
    glVertexfv(...)

    }

    glEnd();

    where that created 20 sided 3d object

    and :

    glBegin(GL_TRIANGLES);
    for (i = 0; i < 20; i++) {

    glNormal3fv(...);
    glVertexfv(...);
    glNormal3fv(...);
    glVertexfv(...);
    glNormal3fv(...);
    glVertexfv(...);

    }

    and this one takes that 20 sided object and makes it into a more sphericle object. I'm just asking if there is any real reason why this works with glNormal?

    glEnd();

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,982

    Re: glNormal?

    glNormal does not make the object itself more spherical, it makes it look more spherical.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Italy
    Posts
    124

    Re: glNormal?

    With glNormal you set tha normal for the current vertex, that will enter the ogl pipeline with the following glVertex instruction.
    Since the 'brightness' of the face color depends by the angle between the normal and the vector from light to face, you can get some different results changing the normals.
    Flat shading (uniform color for all the face) is obtained specifing normals perpendicular to the face plane. This is used with object like cubes, ecc.
    Smooth shading (a different color for all the vertices of the face, that is filled with interpolated values) is a way to approx curved surfaces with a relatively small amount of polys. With falt shading this does not works because the edges are between different colors, resulting in a discontinuous color. The trick is to assign the same color to vertices shared between different faces. If face 1,5,7 & 8 have a common vertex at 1.0,2.0,1.0 you assign at this vertex (each time you create a face that shares this vertex) a normal that is the average of all the normals you would use for flat shading of these faces...

    Now I can't understand what I wrote... hope you'll understand!
    Bye
    tFz

  6. #6
    Junior Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Canada
    Posts
    173

    Re: glNormal?

    By calling glNormal just before each glvertex call you can assign a smooth shading to the 3d object.
    To do this, glNormal (before each vertex) is the result of the average of the normals of each face that share that particular vertex.
    Billy

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,982

    Re: glNormal?

    Averagin the normal of all faces sharing a specific vertex is a simple way to appproximate the vertex normal. Most of the time it will give you a satifying result, even though it might not be exact. Just as a sidenote.

Posting Permissions

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