Results 1 to 7 of 7

Thread: Lighting objects

  1. #1

    Lighting objects

    I am at a point where I am lighting objects now and I noticed that if you creat one light source(diffuse, ambient, position), and you draw two different cubes, one using the command glutSolidCube, and the other using GL_QUADS, and rotate both of them the lighting have very different effects. the one with glutSolidCube reacts fine to the light, but the one with GL_QUADS gets dark once it rotates a certain amount, then lights up again, and it recures with every full rotation. can somebody explain this.
    same results with nehes lighting tutorial

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Dec 2007

    Re: Lighting objects

    You need to build vertex normals in order to perform lighting! They are specified with glNormal*(*) and tell opengl in which direction the vertex is "pointing". For a cube, you will want flat shading, which means that the normal for every of the 4 vertices of the quad are the same, which will get you sharp edges. You can get the normal with a crossproduct of two adjacent edges of the quad. Note that the crossproduct is a right handed system, and that the vectors given to opengl must have the length one.

  3. #3

    Re: Lighting objects

    thanks for you help, I got it working now. here is what i did:







    this is the first time doing normals in openGL, is normal just a vector that is perpendicular and pointed in the front direction of a plane? when I did a search, there is a lot( alot is not a word ) of talk of calculating normals, why calculated them if you can tell by looking at the plane? is there something more to this?

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Shreveport, LA, USA

    Re: Lighting objects

    Yes, there are basically two different important types of normals. Face normals, and vertex normals. It is not always obvious what a vertex normal is, so you calculate them using the face normals and connectivity info.

  5. #5

    Re: Lighting objects

    can you please give me an example of a vertex normal and explain its applications??

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Dec 2007

    Re: Lighting objects

    When lighting with plane normals, you will always be able to distinguish the faces (think of a sphere for this example).
    Now, in opengl you can average the normals in a certain vertex. So you have calculated the lighting per vertex. Then opengl interpolates the resulting vertex color over the face. Thus, you have a "smooth" looking sphere which you couldn't get with a normal per face. You will still be able to see the edges at the outline of the sphere though...
    This technuiqe is called "Gouraud-shading".

  7. #7
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Nov 2010

Similar Threads

  1. Having a problem with lighting - 3D objects C++
    By vvv9703 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 06-07-2016, 11:55 AM
  2. Lighting - Are objects actually smooth..?
    By Sagar G in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-18-2013, 03:38 PM
  3. Lighting objects more realistic?
    By Andy Gilbert in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-15-2010, 10:44 AM
  4. Static lighting in objects
    By Coluna in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-15-2003, 08:33 PM
  5. Lighting on non-textured objects.
    By nexusone in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 02-26-2002, 09:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean