View Full Version : colored Texture & Light & GL_DECAL/GL_MODULATE
01-24-2007, 05:16 PM
I am new to texture, and my application needs to do the colored texture with GL_DECAL, but the problem is that the light does not work for GL_DECAL, and I ned to set GL_MODULATE for light to work. How could I make these three work together?
01-24-2007, 10:46 PM
GL_DECAL ignores the primary color and just shows the texel.
GL_MODULE multiplies primary color and texel and shows the result.
Now if you have lighting, primary color comes from material color and light color. The lighting mathematics is used here.
So use glLight to set up your light and glMaterial for your polygons.
01-25-2007, 12:24 PM
V-man, thanks for your reply.
My application set up light and material before calling texture environment setting
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
GL_MODULATE works fine for light, and GL_DECAL igores the light and primary color. To make the Texture without blend(GL_DECAL) to work for light, do I need to set up the light and material again after glTexEnvi?
01-26-2007, 02:10 AM
No, because one is independent of the other.
You can read in the red book that GL is a state machine (or websites about GL)
01-26-2007, 06:08 AM
Sorry, it seems that I did not express my question clearly.
It seems that if we specify the following function:
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
The lighting doesn't affect the textured objects.
How could I have GL_DECAL application with lighting ?
01-26-2007, 10:54 AM
I think canned lighting is going to be difficult with decal. Try looking up the environment mode equations in the spec or the programming guide. Decal basically blends between the previous environment (primary color for env 0) and the source texture, based on the texture's alpha, which will produce all light color, all texture color, or something somewhere in between, depending on whether RGB or RGBA textures are used.
Hope it helps...
01-26-2007, 01:19 PM
From the OpenGL FAQ:
21.030 Why doesn't lighting work when I turn on texture mapping?
There are many well-meaning texture map demos available on the Web that set the texture environment to GL_DECAL or GL_REPLACE. These environment modes effectively replace the primitive color with the texture color. Because lighting values are calculated before texture mapping (lighting is a per vertex operation, while texture mapping is a per fragment operation), the texture color replaces the colors calculated by lighting. The result is that lighting appears to stop working when texture mapping is enabled.
The default texture environment is GL_MODULATE, which multiplies the texture color by the primitive (or lighting) color. Most applications that use both OpenGL lighting and texture mapping use the GL_MODULATE texture environment.
Look for the following line in your code:
glTexEnv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); /* or GL_REPLACE */
You should change GL_DECAL to GL_MODULATE, or simply delete the line entirely (since GL_MODULATE is the default).
01-26-2007, 02:33 PM
Thanks for your guys reply.
I am using RGBA texture, and want to ignore the
the primary color and just shows the texture color, so I need to use GL_DECAL in glTexEnvi() setting, but I also want to have lighting affect the textured object, any way to do?
01-26-2007, 02:41 PM
01-26-2007, 03:33 PM
ZbuffeR, thanks for your reply, could you please tell more specific in details?
01-26-2007, 10:48 PM
glColor will work if you call glEnable(GL_COLOR_MATERIAL)
The other way is to use glMaterial.
Why don't you set glMaterial to white for your object. Or describe your problem clearly, with screenshots and your current code is.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.