Lighting get darker when texture is aplied. why?

I have this problem. I have a 3d scene and when I apply a texture to the floor the lighting gets darker. If I remove the texture the lights gets back to normal. I can’t understand why because even the menu characters that are not affected by light get darker. It’s weird because I only have this problem with some textures.

It seems like the darker the color of the texture is, the less light I have.
I tried to change glTexEnvf, I replaced GL_MODULATE and started to use GL_DECAL so the texture doesn’t get affected by lights. It worked, the texture has its original color, but everything else gets white with no shapes (like a 3d object with lighting off)

here’s my code

void LoadTexture(const char * bitmap_file)
{
glbmp_t bitmap;

	if(!glbmp_LoadBitmap(bitmap_file, 0, &bitmap))
	{
		fprintf(stderr, "Error loading bitmap file: %s

", bitmap_file);
exit(1);
}
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texname);
glGenTextures(1, &texname);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bitmap.width, bitmap.height,
0, GL_RGB, GL_UNSIGNED_BYTE, bitmap.rgb_data);
glbmp_FreeBitmap(&bitmap);
}

and then I load the image that I want as texture. Maybe I have something missing or I have some code in the wrong place. Does anybody know how to solve this problem?

Have you remembered to disable texturing afterwards, if the other objects are not meant to be textured?


glDisable(GL_TEXTURE_2D);

If you’ve got texturing enabled by accident and are not providing new texture coordinates for each new vertex, you will simply be sampling the same point of the texture each time, so the darker the point in the texture being sampled, the darker your scene will appear to change to.

Think about the way GL_MODULATE works - if you have a texture that’s at 50% colour intensity, and a light that’s also at 50% colour intensity, then the output is going to be texture * light = 25%. So yes, getting darker is the expected behaviour.

If you really don’t want this you can look at a GL_COMBINE/GL_RGB_SCALE setup instead, using a 2x or 4x scale to bring the colour intensity back up. So for the example I gave above, and assuming a 2x scale, you’ll get an output of 50% instead, which seems to be more like what you want.

If you’re drawing other objects that you don’t want to be affected by the light then you should either (1) switch off lighting, or (2) switch your glTexEnv to GL_REPLACE, or (3) (preferably) do both.

Thank you for your answer, it makes sense what you said, the problem could be that. I didn’t remeber to disable texturing, but I did it now after drawing all the quads but it’s still the same. If I couldn’t find how to solve this I’ll try to find which point of the texture is being sampled.

[QUOTE=Dan Bartlett;1237807]Have you remembered to disable texturing afterwards, if the other objects are not meant to be textured?


glDisable(GL_TEXTURE_2D);

If you’ve got texturing enabled by accident and are not providing new texture coordinates for each new vertex, you will simply be sampling the same point of the texture each time, so the darker the point in the texture being sampled, the darker your scene will appear to change to.[/QUOTE]

I understand what you are saying, and that could be the problem. I didn’t have disable texturing, I did it now after drawing all the quads but it’s still the same

[QUOTE=mhagain;1237811]Think about the way GL_MODULATE works - if you have a texture that’s at 50% colour intensity, and a light that’s also at 50% colour intensity, then the output is going to be texture * light = 25%. So yes, getting darker is the expected behaviour.

If you really don’t want this you can look at a GL_COMBINE/GL_RGB_SCALE setup instead, using a 2x or 4x scale to bring the colour intensity back up. So for the example I gave above, and assuming a 2x scale, you’ll get an output of 50% instead, which seems to be more like what you want.

If you’re drawing other objects that you don’t want to be affected by the light then you should either (1) switch off lighting, or (2) switch your glTexEnv to GL_REPLACE, or (3) (preferably) do both.[/QUOTE]

for what you said, that could be the solution of the problem. Scale it to the original values. but it is said that GL_COMBINE or GL_RGB_SCALE are undefined. Can you give me an example how to use it?

Another question: When I use GL_DECAL, all other objects turn white like there was no lighting. Any idea why?

It’s solved. I thought that the problem was bigger. I was just enabling and disabling texturing in the wrong places. I disabled textures before each primitive to be drawn without texture and it works fine, now even GL_DECAL is working as I wanted

Thank you for your answers