To create an OpenGL application that creates shadows using the shadow mapping technique, perform the following steps. We'll start by setting up a framebuffer object (FBO) to contain the shadow map texture, and then move on to the required shader code:
- In the main OpenGL program, set up an FBO with a depth buffer only. Declare a GLuint variable named shadowFBO to store the handle to this framebuffer. The depth buffer storage should be a texture object. You can use something similar to the following code to accomplish this:
GLfloat border[]={1.0f,0.0f,0.0f,0.0f}; //The shadowmap texture GLuint depthTex; glGenTextures(1,&depthTex); glBindTexture(GL_TEXTURE_2D,depthTex); glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT24, ...