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

Thread: combining GL_REPLACE and lighting?

  1. #1
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    combining GL_REPLACE and lighting?

    After having tried to figure out why the hell my textures weren't affected I found out it was caused by setting GL_REPLACE with glTexEnv by commenting it out.
    As I've learned previously from one of my earlier question is this used to prevent the modulating of textures with any previously drawn texture/colors.
    Now, my question is will this result in modulation again (I can't see it quite well from my scene) ? If so, how can I combine these two settings?

    Please don't be shy of writing a big piece of text. Every little bit of information is welcome and can very well be used by this newbie.

  2. #2
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    Re: combining GL_REPLACE and lighting?

    The lighting appears to cause another problem:
    http://www.geocities.com/structual/bla.html?ogl2.jpg

    As you can see is the bottom plane a tad dark-grey-ish, while it is supposed to be red.
    I've tested it without lighting and it's nice and red there.
    Please, does anyone know what this could be?

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,797

    Re: combining GL_REPLACE and lighting?

    glTexEnv is used to define the behavior of how a polygon has a texture applied.

    GL_MODULATE (the default) causes it to modulte with the color of that polygon. Lighting affects the color of the polygon, so if you want a textured object to be affected by lighting, you have to use this mode.

    GL_REPLACE causes the texture to just replace the color (and thus any lighting effects.)

    Generally, if you use GL_MODULATE, you set the color to be white, unless you want another color to be modulated.

    If you are using lighting, however, you set material properties with glMaterial to determine the color, not glColor. (You can use glColor if you enable GL_COLOR_MATERIAL, but that just causes glColor to affect the material properties.)
    Deiussum
    Software Engineer and OpenGL enthusiast

  4. #4
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    Re: combining GL_REPLACE and lighting?

    Thanks, the colored polygons get their color now.
    Textures modulate with the last painted color now, but that is solved by setting the color back to white.
    Is the only way to solve this to set the color back to white after having drawn the colored polygon, or is there another setting for it?

  5. #5
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    Re: combining GL_REPLACE and lighting?

    oh, and another thing... how can I prevent a COLOR to modulate with a texture?

    TY

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,797

    Re: combining GL_REPLACE and lighting?

    Yes, the only way to do that is to set it back to white. That is because OpenGL is a state machine. The color stays what you set it until you set it to something else. Think of it as setting global variables.

    currentColor = yellow;
    drawObject1withCurrentColor();

    drawObject2withCurrentColor();

    You wouldn't expect Object2 to be drawn with white because you never set currentColor to white again.

    The same thing goes for the texture environment settings. If you want some drawn with GL_MODULATE and some with GL_REPLACE, you need to explicitly set the mode before you draw those objects.

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    drawObjectWithModulate();

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    drawObjectWithReplace();
    Deiussum
    Software Engineer and OpenGL enthusiast

Posting Permissions

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