Showing posts with label camera. Show all posts
Showing posts with label camera. Show all posts

Tuesday, August 14, 2007

Ogre: Multiple Viewports

fig.1 - Two viewports, one frontal fullscreen,
the other small left bottom with a sideways camera

To create multiple viewports in ogre3D it is necessary to add another viewport to the Rendering window. Viewports can use the same SceneManager with different cameras, or use completely different scene managers. Here's an example:

void GuiScene::createViewports()
{
// Create one viewport, entire window
Viewport* vp1 = mWindow->addViewport(mCamera);
vp->setBackgroundColour(ColourValue(0,0,0));

// Create one viewport, left bottom corner
Viewport* vp2 = mWindow->addViewport(mCamera,1,0,0.8,0.2,0.2);
vp2->setBackgroundColour(ColourValue(1,1,1));

// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(
Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
}
Note that different viewports must have different Z values ( second argument in the addViewport function).