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

Thread: Light with glColor and glEnable(GL_COLOR_MATERIAL)

  1. #1
    Intern Newbie
    Join Date
    Oct 2010
    Posts
    47

    Light with glColor and glEnable(GL_COLOR_MATERIAL)

    Hello,

    After hours of tests to understand how it works I need help...

    I tried to test the colors of the lights and materials but I waste my time : my results change with the order of the calls of the opengl functions...

    For example this order :
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    define GL_LIGHT_MODEL_AMBIENT and light0
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);
    glColor4f(...);
    define geometry
    render


    If I move glEnable(GL_LIGHTING); from the begining after the definition of the geometry I obtain a very different result.
    I tested that because I have read in a forum that glColor must be called before enabling the lighting. But I did not read any things like this in the opengl documentation.

    So what is the correct order of the calls ?

    Thanks in advance.

  2. #2
    Intern Newbie
    Join Date
    Oct 2010
    Posts
    47
    Hello,

    No answer means that the problem is in my code...

    I have another question :
    How is the color of the back faces calculated when culling is disabled and GL_LIGHT_MODEL_TWO_SIDE is FALSE ? (ie back faces to draw but no light calculation on back faces)
    I obtain the same result than for the front faces with light. Is it the rule ?

    Thanks.

  3. #3
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Quote Originally Posted by AllForum View Post
    Hello,

    No answer means that the problem is in my code...

    I have another question :
    How is the color of the back faces calculated when culling is disabled and GL_LIGHT_MODEL_TWO_SIDE is FALSE ? (ie back faces to draw but no light calculation on back faces)
    I obtain the same result than for the front faces with light. Is it the rule ?

    Thanks.
    You can call glColor whenever you like but you must call it just before you render your object. GL is a state machine. It remembers the call.
    If glColorMaterial is giving you trouble, then don't use it and don't use glColor. Use glMaterial instead when you use lighting and use glColor when you aren't using lighting.

    When GL_LIGHT_MODEL_TWO_SIDE is TRUE, GL checks the sign of the dot product between the normal and the light vector. If it is negative, it flips the direction of the normal and does the lighting calculation as usual.

    When GL_LIGHT_MODEL_TWO_SIDE is FALSE, it doesn't flip the normal. Yes, you are right, you get the same result as for front faces.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  4. #4
    Intern Newbie
    Join Date
    Oct 2010
    Posts
    47
    glColor is used in an existing code ; That's why I have to use it.

    Quote Originally Posted by V-man View Post
    When GL_LIGHT_MODEL_TWO_SIDE is FALSE, it doesn't flip the normal. Yes, you are right, you get the same result as for front faces.
    Ok, it is doing a rendering but with the same normal.
    In my case (with cull face disabled) I have no gain to set GL_LIGHT_MODEL_TWO_SIDE to FALSE because it does a rendering. Setting it to TRUE will give a more "realistic" result.

    Thanks for your answer.

Posting Permissions

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