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: Texture Changes Color

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    4

    Question Texture Changes Color

    I'm having some issues with my textures affecting the color of non-textured polygons. From the 'Color mixed with texture' thread, I saw this: "Yes, when your glTexEnv mode is MODULATE, then the final color is glColor*texture*lighting."

    How can I arrange it so that my final color is only glColor*lighting? I'm using OpenGL 2.1.

    Right now I've got this:
    Code :
        if (enableLighting)
        {
            glEnable(GL_LIGHTING);
            glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambientDiffuse->toArray());
        }//if enableLighting
        else
        {
            glDisable(GL_LIGHTING);
            glColor4fv(ambientDiffuse->toArray());
        }//else enableLighting
    Last edited by Ebonair; 07-27-2012 at 02:14 PM. Reason: Changed glColor*texture to glColor*lighting

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421
    glDisable(GL_TEXTURE_2D)
    glDisable(GL_TEXTURE_1D)
    glDisable(GL_TEXTURE_3D)
    glDisable(GL_TEXTURE_CUBE_MAP)
    glDisable(.....)
    ------------------------------
    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
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    4
    I've tried using glDisable(GL_TEXTURE_2D), but then I lose all my texture data for my models. This happens even if I call glEnable(GL_TEXTURE_2D) before drawing the model. I'd like to retain my textures, but also be able to draw some non-textured polygons with the appropriate color.

  4. #4
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    302
    You have to reenable texturing again before rendering your textured models:

    glEnable(G_TEXTURE...);
    drawTexturedStuff();
    glDisable(GL_TEXTURE...);
    drawNonTexturedStuff();

    Think of texture enable/disable as a global switch which isn't reset automatically (e.g. each frame), so if you did:

    // one time init code:
    glEnable(G_TEXTURE...);


    // per frame rendering code:
    drawTexturedStuff();
    glDisable(GL_TEXTURE...);
    drawNonTexturedStuff();

    You will only see textured objects in the first frame, because from then on texturing will never be activated again! If you have to switch states in GL, you have to do it each frame.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Jan 2007
    Posts
    965
    Two other options come to mind. One is to port to shaders - you'll have very specific control over how the various parameters are combined. Two is to create a 1x1 all-white texture and use that - you won't need to worry about having to disable/re-enable texturing.

  6. #6
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    4
    You have to reenable texturing again before rendering your textured models:
    This happens even if I call glEnable(GL_TEXTURE_2D) before drawing the model.
    I wonder, do I need to re-bind the textures with glTexImage2D each time?

    mhagain: I'll try the 1x1 texture - sounds easier than porting to shaders.

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    4
    Nevermind! GL_TEXTURE_2D was being disabled again at a different point in the code! Thanks for all the help!

Posting Permissions

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