Ejemplo n.º 1
0
void StereoscopicRenderingApp::draw()
{
	// clear color and depth buffers
	gl::clear( mColorBackground ); 
	
	// stereoscopic rendering
	switch( mRenderMethod ) 
	{
	case MONO:
		// render mono camera
		mCamera.disableStereo();
		render();
		break;
	case ANAGLYPH_RED_CYAN:
		renderAnaglyph( getWindowSize(), Color(1, 0, 0), Color(0, 1, 1) );
		break;
	case SIDE_BY_SIDE:
		renderSideBySide( getWindowSize() );
		break;
	case OVER_UNDER:
		renderOverUnder( getWindowSize() );
		break;
	case INTERLACED_HORIZONTAL:
		renderInterlacedHorizontal( getWindowSize() );
		break;
	}

	// draw auto focus visualizer
	if( mDrawAutoFocus ) mAF.draw();
}
Ejemplo n.º 2
0
void StereoscopicRenderingApp::draw()
{
	// find dimensions of each viewport 
	int w = getWindowWidth();
	int h = getWindowHeight();

	// clear color and depth buffers
	gl::clear( mBackgroundColor ); 
	
	// stereoscopic rendering
	switch( mRenderMethod ) 
	{
	case MONO:
		// render mono camera
		mCamera.disableStereo();
		render();
		break;
	case SIDE_BY_SIDE:
		// store current viewport
		glPushAttrib( GL_VIEWPORT_BIT );

		// draw to left half of window only
		gl::setViewport( Area(0, 0, w / 2, h) );

		// render left camera
		mCamera.enableStereoLeft();
		render();

		// draw to right half of window only
		gl::setViewport( Area(w / 2, 0, w, h) );

		// render right camera
		mCamera.enableStereoRight();
		render();

		// restore viewport
		glPopAttrib();
		break;
	case OVER_UNDER:
		// store current viewport
		glPushAttrib( GL_VIEWPORT_BIT );

		// draw to top half of window only
		gl::setViewport( Area(0, 0, w, h / 2) );

		// render left camera
		mCamera.enableStereoLeft();
		render();

		// draw to bottom half of window only
		gl::setViewport( Area(0, h / 2, w, h) );

		// render right camera
		mCamera.enableStereoRight();
		render();

		// restore viewport
		glPopAttrib();
		break;
	case ANAGLYPH_RED_CYAN:
		// store current viewport
		glPushAttrib( GL_VIEWPORT_BIT );

		// bind the left FBO and adjust the viewport to its bounds
		mAnaglyphLeft.bindFramebuffer();
		gl::setViewport( mAnaglyphLeft.getBounds() );

		// because glClear() does not respect the color mask, 
		// clear the color (and depth) buffers using a red filtered background color
		gl::clear( mBackgroundColor * Color( 1, 0, 0 ) );

		// set up color mask to only draw red and render left camera
		glColorMask( true, false, false, true );
		mCamera.enableStereoLeft();
		render();
		glColorMask( true, true, true, true );

		mAnaglyphLeft.unbindFramebuffer();
		
		// bind the right FBO and adjust the viewport to its bounds
		mAnaglyphRight.bindFramebuffer();
		gl::setViewport( mAnaglyphRight.getBounds() );
		
		// because glClear() does not respect the color mask, 
		// clear the color (and depth) buffers using a cyan filtered background color
		gl::clear( mBackgroundColor * Color( 0, 1, 1 ) );
		
		// set up color mask to only draw cyan and render right camera
		glColorMask( false, true, true, true );
		mCamera.enableStereoRight();
		render();
		glColorMask( true, true, true, true );

		mAnaglyphRight.unbindFramebuffer();

		// restore viewport
		glPopAttrib();

		// draw the FBO's on top of each other using a special additive blending operation
		gl::color( Color::white() );
		
		gl::draw( mAnaglyphLeft.getTexture(), Rectf( 0, (float) h, (float) w, 0 ) );	

		glEnable( GL_BLEND );
		glBlendFunc( GL_ONE, GL_ONE );
		gl::draw( mAnaglyphRight.getTexture(), Rectf( 0, (float) h, (float) w, 0) ); 
		glDisable( GL_BLEND );
		break;
	}

	// draw auto focus visualizer
	if( mDrawAutoFocus ) mAF.draw();
}