Create the Shadow map FBO and texture
| 334 | |
| 335 | // Create the Shadow map FBO and texture |
| 336 | void SceneDemo::createShadowMapFBOAndTexture() { |
| 337 | |
| 338 | // For each shadow map |
| 339 | for (int i = 0; i < NB_SHADOW_MAPS; i++) { |
| 340 | |
| 341 | // Create the texture for the depth values |
| 342 | mShadowMapTexture[i].create(SHADOWMAP_WIDTH, SHADOWMAP_HEIGHT, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, |
| 343 | GL_UNSIGNED_BYTE, GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER, NULL); |
| 344 | |
| 345 | mShadowMapTexture[i].setUnit(i); |
| 346 | |
| 347 | // Make sure that texture lookups outside the texture coords range will not |
| 348 | // treated as beeing in shadow |
| 349 | glBindTexture(GL_TEXTURE_2D, mShadowMapTexture[i].getID()); |
| 350 | GLfloat border[] = { 1.0f, 0.0f, 0.0f, 0.0f }; |
| 351 | glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border); |
| 352 | glBindTexture(GL_TEXTURE_2D, 0); |
| 353 | |
| 354 | // Create the FBO for the shadow map |
| 355 | mFBOShadowMap[i].create(0, 0, false); |
| 356 | mFBOShadowMap[i].bind(); |
| 357 | |
| 358 | // Tell OpenGL that we won't bind a color texture with the currently binded FBO |
| 359 | glDrawBuffer(GL_NONE); |
| 360 | glReadBuffer(GL_NONE); |
| 361 | |
| 362 | mFBOShadowMap[i].attachTexture(GL_DEPTH_ATTACHMENT, mShadowMapTexture[i].getID()); |
| 363 | mFBOShadowMap[i].unbind(); |
| 364 | } |
| 365 | |
| 366 | mIsShadowMappingInitialized = true; |
| 367 | } |
| 368 | |
| 369 | // Used for debugging shadow maps |
| 370 | void SceneDemo::createQuadVBO() { |