Tutorial - Stereo rendering

From Horde3D Wiki
Revision as of 12:11, 11 July 2009 by Wakko (talk | contribs) (New page: '''In this tutorial I will describe how to perform quadbuffered stereo rendering with Horde3D. This explicitly requires a graphics card that supports quad-buffering, i.e. rendering to two ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

In this tutorial I will describe how to perform quadbuffered stereo rendering with Horde3D. This explicitly requires a graphics card that supports quad-buffering, i.e. rendering to two different output devices(Nvidia Quadro or ATI/AMD FireGL). This has been tested with a stereo projection system and polarization glasses.

To do this we need to render our scene from two different points of view(left and right eye) and send each frame to the corresponding output device.

Stereoscopic OpenGL Tutorial

Stereoscopic Geometry in OpenGL In this tutorial we will only use an asymmetric frustum.


Enable quadbuffering

First of all we need to tell our graphics card to enable quadbuffering if available. The following code shows how to do this using SDL. We will try to enable stereo rendering by default but it will fall back to non-stereo if the graphics card does not have quadbuffering capabilities. We will only enable stereo rendering in fullscreen mode.

Stereo Setup .
bool setupWindow( int width, int height, bool fullscreen )
{
	const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
	SDL_Surface* surface;

	appWidth = fullscreen ? videoInfo->current_w : width;
	appHeight = fullscreen ? videoInfo->current_h : height;

	const bool fullscreen = true;

	if(fullscreen)
	{
		// enable stereo if possible (only in fullscreen mode)
		if ( SDL_GL_SetAttribute(SDL_GL_STEREO, 1) == 0) {
			std::cout<<"Stereo flag set!"<<std::endl;
		}
		// Try to initialize the SDL_Surface with Stereo enabled
		if (!(surface =  SDL_SetVideoMode(appWidth,appHeight,32,SDL_OPENGL | SDL_FULLSCREEN | SDL_HWSURFACE))) 
		{
			// if initialization with stereo enabled failed disable the stereo flag and retry
			std::cerr << "STEREO initialization failed! Restarting..."<< std::endl;
			SDL_GL_SetAttribute(SDL_GL_STEREO, 0);
			if (!SDL_SetVideoMode(width, height, 32, SDL_OPENGL | SDL_FULLSCREEN | SDL_HWSURFACE)) {
			     std::cerr << "SDL_SetVideoMode failed: " << SDL_GetError() << std::endl;
			     SDL_Quit();
			     return 0;
			}
		}
	}else // windowed
	{	
		if (!(surface = SDL_SetVideoMode(appWidth,appHeight,32,SDL_OPENGL | SDL_HWSURFACE))) 
		{
			std::cerr << "SDL_SetVideoMode failed: " << SDL_GetError() << std::endl;
			SDL_Quit();
			return 0;
		}
		SDL_WM_SetCaption("SDL App",NULL);
	}
	// check if stereo rendering is enabled
	int ga = 0;
	if (SDL_GL_GetAttribute(SDL_GL_STEREO, &ga) == 0) {
		if (ga == 0)
			std::cout<<"No stereo rendering available."<<std::endl;
		else
			std::cout<<"Stereo rendering enabled!."<<std::endl;
	}
	return true;
}

work in progress