Skip to main content
gamedev.net
🔒 Locked

Texturing light dependance?

Started by anique 2 replies 1.3k views
Original Post
anique
anique
I use the following code and get nice red cubes on a white plane:

glColor3f(1,1,1);
for(int z=0;z<100;z++){
for(int x=0;x<100;x++){
if(pathMap[x][z]==1){
glPushMatrix();
glColor3f(1,0,0);
glTranslatef(x,0,z);
glutSolidCube(1);
glColor3f(1,1,1);
glPopMatrix();
}//else{


//tm->BindTexture(TEX_GROUND);
glBegin(GL_QUADS);
glNormal3d(0,1,0);
//glTexCoord2f(0.0f, 0.0f);
glVertex3f(x, 0, z);

//glTexCoord2f(1.0f, 0.0f);
glVertex3f(x, 0, z+1);

//glTexCoord2f(1.0f, 1.0f);
glVertex3f(x+1, 0, z+1);

glTexCoord2f(0.0f, 1.0f);
glVertex3f(x+1, 0, z);
glEnd();


Then i remove the comments to apply the texturing and the cubes darken. Any idea whats happening?
How does texturing the ground darken these cubes?
SaTANO
SaTANO
I am not sure what exactly you are trying to render but from what I read:
- you are rendering cubes vs planes in loop
- you want your cubes to be red and plane has texture applied
If your [color=#880000][font=CourierNew, monospace][size=2]BindTexture [/font]function also enable texturing you should disable it before rendering cube

so if you are using multiple texture units you should activate it
- glActiveTexture(GL_TEXTURE0)
and disable texturing by
- glDisable(GL_TEXTURE_2D)
anique
anique
That solved the problem. thx
I'm curious though. Why does enabling texture reduce the brightness of an object?
21st Century Moose
21st Century Moose
By default a texture is modulated by the light value, so the end result is texture * light. If you have a light of 0.5 with texturing disabled, you'll get 0.5 out. If you enable texturing, and if the average intensity of the texture is also 0.5, the end result will be 0.5 * 0.5 which is 0.25 - darker. A texture can never go above an intensity of 1.0 (well floating-point formats can, but let's ignore them for the purposes of this discussion) so the best you'll ever get is from a fully white texture and will be the same as if no texture was used. Any colour at all will always imply values less than 1.0, which will darken the scene. Yes, that sucks, but it's the way colours work on computers.

If you don't want that, look at GL_ARB_texture_env_combine - especially the RGB scale modes. An RGB scale of 2, when applied to light 0.5 and texture 0.5, will give an end result of 0.5, which is probably what you want.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.