void ShadowMapSample::draw() { gl::clear(); gl::enableDepthWrite(); glEnable( GL_LIGHTING ); updateShadowMap(); gl::enableDepthRead(); glEnable( GL_TEXTURE_2D ); mDepthFbo.bindDepthTexture(); mShader.bind(); mShader.uniform( "shadowTransMatrix", mLight->getShadowTransformationMatrix( *mCamera ) ); if( mLookThroughCamera ) gl::setMatrices( *mCamera ); else gl::setMatrices( mLight->getShadowCamera() ); mLight->update( *mCamera ); glPushMatrix(); mBackboard.draw(); mTorus.draw(); gl::drawCube( vec3::zero(), vec3( 1, 1, 1 ) ); glPopMatrix(); mShader.unbind(); mDepthFbo.unbindTexture(); // Draw the lighting frustum unless we're looking through it if( mLookThroughCamera ) { glDisable( GL_LIGHTING ); glColor3f( 1.0f, 1.0f, 0.1f ); gl::drawFrustum( mLight->getShadowCamera() ); } if( mDrawDepthMap ) { // there are faster ways to achieve this, but this is a handy way to see the depth map gl::setMatricesWindow( getWindowSize() ); Surface32f shadowMapSurface( mDepthFbo.getDepthTexture() ); ip::hdrNormalize( &shadowMapSurface ); gl::color( Color::white() ); gl::draw( gl::Texture( shadowMapSurface ), Rectf( 0, 0, 128, 128 ) ); } }
void PopGameApp::draw() { if(getElapsedFrames()>200)return; gl::pushMatrices(); gl::setMatrices( *mCamera ); gl::enable(GL_DEPTH_TEST); gl::clear(ColorA(0.5,0.5,0.5,1)); gl::enableDepthWrite(); glEnable( GL_LIGHTING ); updateShadowMap(); gl::enableDepthRead(); // clear out the window with black glEnable( GL_TEXTURE_2D ); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5); mShader.bind(); mDepthFbo.bindDepthTexture(1); mShader.uniform( "shadowTransMatrix", mLight->getShadowTransformationMatrix( *mCamera ) ); //gl::enable(GL_BLEND); mLight->update( *mCamera ); gl::pushMatrices(); stage.int_draw(); gl::popMatrices(); gl::popMatrices(); // gl::setMatrices( *mCamera ); mShader.unbind(); gl::disable (GL_DEPTH_TEST); glDisable( GL_LIGHTING ); glDisable (GL_ALPHA_TEST); glEnable(GL_BLEND); gl::enableAlphaBlending(); stage2D.int_draw(); glDisable(GL_BLEND); gl::disableAlphaBlending(); /* glDisable( GL_LIGHTING ); gl::setMatricesWindow( getWindowSize() ); Surface32f shadowMapSurface( mDepthFbo.getDepthTexture() ); ip::hdrNormalize( &shadowMapSurface ); gl::color( Color::white() ); gl::draw( gl::Texture( shadowMapSurface ), Rectf( 0, 0, 128*2, 128*2 ) ); */ }