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: Color mixed with texture

  1. #1
    Intern Contributor
    Join Date
    Mar 2012
    Posts
    50

    Color mixed with texture

    My previous colors are mysteriously being mixed together with my texture. I first use glColor4f to produce a green and red (alpha) colors for some quads. Then i make a quad that holds just my texture. And from this, somehow the green from drawing previous quads has leaked onto the texture ?

    I found two option, none of which work:
    #1
    Use
    Code :
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    This successfully removes the leaked colors onto the textures, but now the textures fails to work with basic OGL lighting.


    #2
    Using no glTexEnvi (Which is what OpenGL FAQ suggested i do in this situation)
    This leaks the previous colors onto the texture, but now successfully works with basic OGL lighting.

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421
    It sounds like you need glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
    and set all the glMaterial parameters to white.
    ------------------------------
    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);

  3. #3
    Intern Contributor
    Join Date
    Mar 2012
    Posts
    50
    Modulate produced the same results as REPLACE.

    Setting glColor to white actually solves the problem

    However, i'd like to know what the pipeline is the final color of each fragment in OpenGL.

    Is it->
    Code :
    Final color = glColor*texture*lighting;

    If so, is that why multiplying the glColor white (all 1's) has no effect on final color?

  4. #4
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421
    If you had to use glColor instead of glMaterial, then you had enable material color tracking.
    Yes, when your glTexEnv mode is MODULATE, then the final color is glColor*texture*lighting.
    ------------------------------
    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);

  5. #5
    Intern Contributor
    Join Date
    Mar 2012
    Posts
    50
    I'v been using glColor always and instead of glMaterial, i dont know if thats a bad thing, but i haven't had any problems.
    Normally i dont set any texture environment. Is MODULATE the same having the texture environment at default?

  6. #6
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421
    I'm not saying that enabling color tracking is bad. I'm just saying that you had not indicated in your post so I said use glMaterial.
    Yes, the default is MODULATE.
    Overall, all this is ancient history and eventually, you should move to GL 3.3 or 4.0.
    ------------------------------
    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);

Posting Permissions

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