PDA

View Full Version : Lighting and multitexture



jimmiwalker2
02-16-2005, 07:56 AM
Hi all!

My question is, how can lighting be enabled/disabled for texture units independently. I made a simple app and the rendering code is like following:



glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);

glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_AD D);

glBegin(GL_QUADS);
// Front Face
glNormal3f( 0.0f, 0.0f, 1.0f);
glMultiTexCoord2f(GL_TEXTURE0,0.0f, 0.0f);
glMultiTexCoord2f(GL_TEXTURE1,0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glMultiTexCoord2f(GL_TEXTURE0,1.0f, 0.0f);
glMultiTexCoord2f(GL_TEXTURE1,1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 1.0f);
glMultiTexCoord2f(GL_TEXTURE0,1.0f, 1.0f);
glMultiTexCoord2f(GL_TEXTURE1,1.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, 1.0f);
glMultiTexCoord2f(GL_TEXTURE0,0.0f, 1.0f);
glMultiTexCoord2f(GL_TEXTURE1,0.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
{ additional quads }
glEnd();Now it looks like lighting is only enabled for texture unit 0, and for unit 1 it isn't. I tried to change mixing mode (eg. GL_REPLACE instead of GL_ADD), and it didn't change the fact that there is no lighting for unit 1. I got the same result with VBO-s.

Anyone has an idea how I can enable lighting for unit 1?

Thank you in advance.

SeskaPeel
02-16-2005, 08:27 AM
GL_MODULATE

azcoder
02-16-2005, 11:52 AM
I believe that the first texture unit receives the fragment color based on material and lighting effects (if lighting is enabled).

GL_MODULATE causes the previous value to be multiplied by the new one.

GL_ADD causes them to be added, thus it is possible to saturate teh value quickly.

FragColor(Includes Lighting)->TexUnit1->TexUnit2

Thus, each texture unit is not individually lit.

Hope that helps....

jimmiwalker2
02-16-2005, 02:37 PM
Thank you, now I understand it.