http://www.cc.gatech.edu/~jtan34/shadowMappingTutorial.html
The idea is to project a texture onto a simple cube. Where in my code below do I have to bind the actual texture? Because when the shadow map is bound, I cannot bind the texture anymore.
Also, I suspect that in my case I only have to render the scene twice: once for creating the depth map from the perspective of the projector and once from the perspective of the camera. As opposed to the tutorial where the scene is rendered three times. Currently the code follows the tutorial exactly.
I did find some info about projective texturing, however not a lot and also not very concrete. That is why I am using this shadow map tutorial.
void RenWin::drawGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Step 1: Place camera at projector position and determine visibility */ // set projector viewport glViewport(0, 0, m_pcProjector->getWidth(), m_pcProjector->getHeight()); // set projector projection matrix Matrix4x4 cProjProjectionMat; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPerspective(30.0f, (GLfloat) m_pcProjector->getWidth() / (GLfloat) m_pcProjector->getHeight(), 0.1f, 400.0f); glGetFloatv(GL_PROJECTION_MATRIX, cProjProjectionMat); // set projector view matrix Matrix4x4 cProjViewMat; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); gluLookAt(0.0f, 20.0f, -50.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); glGetFloatv(GL_MODELVIEW_MATRIX, cProjViewMat); // draw scene glShadeModel(GL_FLAT); glColorMask(0, 0, 0, 0); glutSolidCube(10.0f); // pop state glViewport(0, 0, m_uiWidth, m_uiHeight); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); /* Step 2: Create depth map*/ // create depth map GLuint gluiDepthMapId; glGenTextures(1, &gluiDepthMapId); glBindTexture(GL_TEXTURE_2D, gluiDepthMapId); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, m_pcProjector->getWidth(), m_pcProjector->getHeight(), 0); // place camera gluLookAt(0.0f, 0.0f, -50.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); // render again TODO: Necessary? glShadeModel(GL_SMOOTH); glColorMask(1, 1, 1, 1); glClear(GL_DEPTH_BUFFER); glEnable(GL_LIGHT1); glEnable(GL_LIGHTING); glutSolidCube(10.0f); /* Step 3: Render illuminated part i.e. with texture */ // Set up texture matrix Matrix4x4 cBiasMat( 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f ); Matrix4x4 cTextureMat = cBiasMat * cProjProjectionMat * cProjViewMat; // Set up OpenGL texture generation glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_S, GL_EYE_PLANE, cTextureMat[0]); glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_T, GL_EYE_PLANE, cTextureMat[1]); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_R, GL_EYE_PLANE, cTextureMat[2]); glEnable(GL_TEXTURE_GEN_R); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_Q, GL_EYE_PLANE, cTextureMat[3]); glEnable(GL_TEXTURE_GEN_Q); glEnable(GL_TEXTURE_2D); // Set up depth comparison glBindTexture(GL_TEXTURE_2D, gluiDepthMapId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); glAlphaFunc(GL_GEQUAL, 0.99f); glEnable(GL_ALPHA_TEST); glutSolidCube(10.0f); glutSwapBuffers();}