Gator, the reason the lighting “disappears” when you set the second texture unit’s texcoords to zero is that setting them to zero will move the texture samples to the bottom left corner of the 2D texture, which is black. Hence, multiplying the two maps will result in… black.
I’m not setting the value to zero, I’m commenting it out. And I figured out why it was disappearing.
I had to completely disable the second texture unit in the main program. I guess enabling the
second texture unit, but not sending it anything, will still affect the first texture unit.
Now, I can see how each texture unit contributes to the final lightmap. It makes more sense.
Leyder Dylan:
I didn’t like the fact that you blended the background color into everything else. I don’t why
you are doing this.
Here, this is much better:
//
//
//
int
DrawGLScene(GLvoid) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clean the screen, the depth buffer
glLoadIdentity(); // Reset The Projection Matrix
if(pass1_flag) {
glDisable(GL_BLEND);
// FLOOR TEXTURE
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Texture_TGA[0].Texture_ID );
glBegin(GL_QUADS);
// The Bottom Quad **********************
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0,0);
glVertex3f(-5.0f, -4, -10.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1,0);
glVertex3f(5.0f, -4, -10.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1,1);
glVertex3f(5.0f, -4, -20.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0,1);
glVertex3f(-5.0f, -4, -20.0f);
// The Top Quad *************************
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1,1);
glVertex3f(-5.0f, 4, -10.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0,1);
glVertex3f(5.0f, 4, -10.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0,0);
glVertex3f(5.0f, 4, -20.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1,0);
glVertex3f(-5.0f, 4, -20.0f);
// The Left Quad ************************
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0,0);
glVertex3f(-5.0f, -4, -10.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1,0);
glVertex3f(-5.0f, -4, -20.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1,1);
glVertex3f(-5.0f, 4, -20.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0,1);
glVertex3f(-5.0f, 4, -10.0f);
// The Right Quad ***********************
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1,0);
glVertex3f(5.0f, -4, -10.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0,0);
glVertex3f(5.0f, -4, -20.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0,1);
glVertex3f(5.0f, 4, -20.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1,1);
glVertex3f(5.0f, 4, -10.0f);
// The Back Quad ************************
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0,0);
glVertex3f(-5.0f, -4, -20.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1,0);
glVertex3f(5.0f, -4, -20.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1,1);
glVertex3f(5.0f, 4, -20.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0,1);
glVertex3f(-5.0f, 4, -20.0f);
glEnd();
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0 );
glDisable(GL_BLEND);
}
if(pass2_flag) {
// this directly adds the texture to the frame buffer
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Texture_TGA[1].Texture_ID);
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Texture_TGA[2].Texture_ID);
// The Per Pixel Lightning
glBegin(GL_QUADS);
// The Bottom Quad **********************
ProcessVertex_DL(-5.0f, -4, -10.0f);
ProcessVertex_DL(5.0f, -4, -10.0f);
ProcessVertex_DL(5.0f, -4, -20.0f);
ProcessVertex_DL(-5.0f, -4, -20.0f);
// The Top Quad *************************
ProcessVertex_DL(-5.0f, 4, -10.0f);
ProcessVertex_DL(5.0f, 4, -10.0f);
ProcessVertex_DL(5.0f, 4, -20.0f);
ProcessVertex_DL(-5.0f, 4, -20.0f);
// The Left Quad ************************
ProcessVertex_DL(-5.0f, -4, -10.0f);
ProcessVertex_DL(-5.0f, -4, -20.0f);
ProcessVertex_DL(-5.0f, 4, -20.0f);
ProcessVertex_DL(-5.0f, 4, -10.0f);
// The Right Quad ***********************
ProcessVertex_DL(5.0f, -4, -10.0f);
ProcessVertex_DL(5.0f, -4, -20.0f);
ProcessVertex_DL(5.0f, 4, -20.0f);
ProcessVertex_DL(5.0f, 4, -10.0f);
// The Back Quad ************************
ProcessVertex_DL(-5.0f, -4, -20.0f);
ProcessVertex_DL(5.0f, -4, -20.0f);
ProcessVertex_DL(5.0f, 4, -20.0f);
ProcessVertex_DL(-5.0f, 4, -20.0f);
glEnd();
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0 );
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0 );
glDisable(GL_BLEND);
}
//////////////////////////////////////////////////////////////////
DrawLightSphere();
return 1;
}
//
//
//
void
DrawLightSphere() {
// Disable texture and blending
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
// We draw a point at the Light Position
glPushMatrix();
glTranslatef(Light_X, Light_Y, Light_Z);
glutSolidSphere(0.1f,10,10);
glPopMatrix();
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
}