Sign in to follow this  

Lighting gets darker when texture is aplied

This topic is 2065 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone.
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\n", 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);
}

then I apply the texture to a quad and 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?

Share this post


Link to post
Share on other sites
I assume you don't want everything to be textured. If that's the case, then probably you have forgotten to disable texturing for the non textured objects/triangles (openGL is a state system, that means whatever state you set, that will remain and affect things until you change the state. Texturing is a state too, so as the currently "applied"/bound texture image, so as the lastly set texture coordinates. So in your case, all the drawn primitives will have the color of your texture's corner multiplied by the light color).

GL_MODULATE should be fine, I'm not sure why the textured object appears poorly lit. Maybe you should post a "before-after" image about the issue (no texturing vs texturing and GL_MODULATE) Edited by szecs

Share this post


Link to post
Share on other sites
Yes you were right, I had forgotten to disable texturing in the non textured objects. I tried it before but I did it in the wrong place. Now everything is working fine. Thank you for you help :)

Share this post


Link to post
Share on other sites
Sign in to follow this