Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: texEnv

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2004
    Posts
    12

    texEnv

    Im trying to make a multi-light bump mapping application which uses texenv's dot3 operation. I can get the bumpmapping working the a white light by using the following setup:
    glClientActiveTextureARB(GL_TEXTURE0_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);

    glActiveTextureARB(GL_TEXTURE1_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);

    This code will draw white and black bumps given a normal map. I was wondering how i can change this so that i can color the bumps to a specific color. Thanks.
    Chris

  2. #2
    Intern Contributor
    Join Date
    Mar 2001
    Location
    Romania
    Posts
    50

    Re: texEnv

    You need an aditional texture stage.
    Just set on third stage a dummy texture (coords not needed) and set the following env op:

    glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, your_bump_color);

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_CONSTANT_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);

    Also don't forget about:
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERANDx_RGB_ARB, GL_SRC_COLOR); // or 1-src_color

    and about setting the proper operations also for alpha (i've got some times weird results with non-setting the alpha operation)

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2004
    Posts
    12

    Re: texEnv

    So now I have:

    //Set up texture environment to do (tex0 dot tex1)*color
    glClientActiveTextureARB(GL_TEXTURE0_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);

    glActiveTextureARB(GL_TEXTURE1_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);

    float f[]={1,1,1,0};
    glClientActiveTextureARB(GL_TEXTURE3_ARB); //set a dummy texture (nothing in there)
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_CONSTANT_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
    glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, f);

    But it still does not work.

  4. #4
    Intern Contributor
    Join Date
    Mar 2001
    Location
    Romania
    Posts
    50

    Re: texEnv

    TEX3 is active ?

    Constant color with alpha = 0 ?

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2004
    Posts
    12

    Re: texEnv

    Just set on third stage a dummy texture (coords not needed) and set the following env op:
    I guess im not sure what you mean by this. I am new to the texEnv functions.

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2004
    Location
    Edmonton Alberta Canada
    Posts
    7

    Re: texEnv

    if you have the crossbar extension, then this should work:

    glActiveTextureARB(GL_TEXTURE0_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE1_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE0_ARB);

    glClientActiveTextureARB(GL_TEXTURE1_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);

    Where the primary color (glColorxx()) is the light color. Alternatively, you can use GL_CONSTANT_COLOR instead of GL_PRIMARY_COLOR and put the lights color int the TexEnv's constant color.

    Does anyone know how often you can set the TexEnv constant color? can it be done for every vertex (ie: use it like a secondary color?)

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2004
    Posts
    12

    Re: texEnv

    sorry, still doesnt want to work.

  8. #8
    Junior Member Newbie
    Join Date
    Jan 2004
    Location
    Edmonton Alberta Canada
    Posts
    7

    Re: texEnv

    give us more information, what isn't working? Its not coloring the light? do you have any blend modes set? is it dot3 but not colored? is it colored but not dot3?

    I notice that you have: glClientActiveTextureARB for Unit 0 but glActiveTextureARB for Unit 1. Mayhaps this is an issue?

  9. #9
    Junior Member Newbie
    Join Date
    Jan 2004
    Posts
    12

    Re: texEnv

    This code will actually apply the bump mapping beautifully with a white light.

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE0_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE1_ARB);

    When I add the following code below the first, it appears that the glColor is applying to the actualy normal map, and the dot3 isnt even doing anything anymore:

    glClientActiveTextureARB(GL_TEXTURE1_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
    glColor4f(1,1,0,1);

    does blending need to be enabled at this time?

  10. #10
    Junior Member Newbie
    Join Date
    Jan 2004
    Location
    Edmonton Alberta Canada
    Posts
    7

    Re: texEnv

    hmmm no blending needed.

    According to: http://www.khronos.org/opengles/docu...veTexture.html

    you should use glActiveTexture, NOT glClientActiveTexture.
    read up on them

    http://www.khronos.org/opengles/docu...veTexture.html

    http://www.khronos.org/opengles/docu...veTexture.html

Posting Permissions

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