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: Ambient does not affect textured meshes

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    659

    Ambient does not affect textured meshes

    Hi All,

    Why when I draw a mesh with the following settings the ambient value is not used? I can even set full white without altering the mesh color.

    Code :
    glMaterialfv(GL_FRONT_AND_BACK, gl_AMBIENT, [0.2, 0.2, 0.2, 1]);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [0, 0, 0, 1]);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0);
     
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [1, 1, 1, 1 ]);
     
    glEnable(GL_TEXTURE_1D);
    glBindTexture(GL_TEXTURE_1D, textureName);
     
    glBegin(GL_TRIANGLES);
     
    ...
    Thanks,

    Alberto

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,575

    Re: Ambient does not affect textured meshes

    Is the typo gl_AMBIENT instead of GL_AMBIENT also in your code ?
    Otherwise, check value for glLightModelfv GL_LIGHT_MODEL_AMBIENT (if you did not touch it, default should be good).
    http://www.opengl.org/sdk/docs/man/x...LightModel.xml
    Some advice about deprecated GL lighting model and what to set as material ambient and light ambient values :
    http://www.sjbaker.org/steve/omniv/opengl_lighting.html

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    659

    Re: Ambient does not affect textured meshes

    Hi ZbuffeR,

    We only have one call to:

    Code :
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, [ .15f, .15f, .15f, 1]);
    Do you confirm that a triangle with a solid blue texture shall look like a triangle with the three vertices color as 0,0,255 for the same material parameters?

    Can the material 1,1,1,1 DIFFUSE value totally override the material AMBIENT component?

    Thanks.

    Alberto

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,575

    Re: Ambient does not affect textured meshes

    You did not say a word about the typo I noted : is it on your code too ?

    To have 0,0,255 when only using ambient, you should have set :
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, [ 1.0f, 1.0f, 1.0f, 1.0f]);
    Otherwise you will have 0,0,38 (255*0.18f).

    Diffuse and Ambient are separate.

    EDIT : just saw you mentionned texturing. Try without any texture, until you have the expected result.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    659

    Re: Ambient does not affect textured meshes

    Yes, the typo is ok in my code, sorry.

    The point is that I can't see the ambient effect when I draw the model using 1D textures like in my first post.

    I supposed that setting material ambient as 1,1,1,1 will result in a almost white model (as it happens when I don't use the 1D texture), what do you think?

    What parameter can make the 1D texture drawing immune from material AMBIENT ?

    Thanks,

    Alberto

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    894

    Re: Ambient does not affect textured meshes

    Have you set glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) or something along those lines?

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    659

    Re: Ambient does not affect textured meshes

    Yes carsten,

    We did also this test:

    Code :
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [0.2, 0.2, 0.2, 1]);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [0, 0, 0, 1]);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0);
     
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [1, 1, 1, 1 ]);
     
    glEnable(GL_TEXTURE_1D);
    glBindTexture(GL_TEXTURE_1D, textureName);
    glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // <- HERE
    glBegin(GL_TRIANGLES);
     
    ...

    without success...

    Is it in the correct position?

    Thanks,

    Alberto

Posting Permissions

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