Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


Lighting gets darker when texture is aplied


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 msantos   Members   -  Reputation: 103

Like
0Likes
Like

Posted 22 May 2012 - 07:23 AM

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?

Sponsor:

#2 szecs   Members   -  Reputation: 2175

Like
1Likes
Like

Posted 22 May 2012 - 07:53 AM

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, 22 May 2012 - 07:59 AM.


#3 msantos   Members   -  Reputation: 103

Like
0Likes
Like

Posted 22 May 2012 - 09:32 AM

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 :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS