PDA

View Full Version : Texture Changes Color



Ebonair
07-27-2012, 02:09 PM
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:


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

V-man
07-27-2012, 04:24 PM
glDisable(GL_TEXTURE_2D)
glDisable(GL_TEXTURE_1D)
glDisable(GL_TEXTURE_3D)
glDisable(GL_TEXTURE_CUBE_MAP)
glDisable(.....)

Ebonair
07-27-2012, 04:32 PM
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.

menzel
07-28-2012, 12:34 AM
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.

mhagain
07-28-2012, 06:24 AM
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.

Ebonair
07-30-2012, 11:11 AM
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.

Ebonair
07-30-2012, 11:47 AM
Nevermind! GL_TEXTURE_2D was being disabled again at a different point in the code! Thanks for all the help!