/* 
 * @Description: render scene to FBO texture
 * @param: none
 * @return: none
 */
void Base_ThreeD_ProjectApp::renderSceneToFBO()
{
	mScreenSpace1.bindFramebuffer();
    
	glClearColor( 0.5f, 0.5f, 0.5f, 1 );
	glClearDepth(1.0f);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	if (mLightingOn)
		glDisable(GL_LIGHTING);
	glColor3f( 1.0f, 1.0f, 0.1f );
	gl::drawFrustum( mLightRef->getShadowCamera() );
	glColor3f( 1.0f, 1.0f, 1.0f );
	if (mLightingOn)
		glEnable(GL_LIGHTING);
	
	mEye = mCam->getEyePoint();
	mEye.normalize();
	mEye = mEye * abs(mCameraDistance);
	mCam->lookAt( mEye, mCenter, mUp );
	gl::setMatrices( *mCam );
	mLight->update( *mCam );
	
	drawTestObjects();
	
	mScreenSpace1.unbindFramebuffer();
	
	glDisable(GL_LIGHTING);
}
Example #2
0
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 ) );
	}
}