This example shows how to add a 2D Overlay to a channel.
We will add a logo to the bottom left hand corner of the channel.
It is important to understand the concept of overlay's in VR-Vantage. An overlay is a 2D scene that is drawn on top of a 3D scene. The 2D scene can contain any number of the 2D primitives which include: DtLineSegment, DtQuad, DtFilledPolygon and DtOutlinedPolygon. To draw an overlay we need to add something to the scene. In this case we add a DtOverlayDrawable to the scene. The DtOverlayDrawable is responsible for telling overlays to render themselves at the appropriate time. The class that implements the overlay concept is the DtOverlayRenderer. The DtOverlayRenderer does the actual drawing of the graphical primitives. The DtOverlayDrawable is told which DtOverlayRenderer it should draw. During the render phase, the DtOverlayDrawable tells the DtOverlayRenderer to render itself and the graphics primitives are then rendered.
So to draw our logo we create a DtOverlayDrawable, give it a DtOverlayRenderer to render, then add a DtQuad to the DtOverlayRenderer. Here's how that looks in code...
- Create the DtOverlayDrawable. Creating the DtOverlayDrawable requires a DtOsgOverlayManager and a DtChannel. Additionally, drawables need to be added to osg::Geodes and somehow added to the scene. Here we add the geode to the scene as a child of the channel's overlay camera. The overlay camera uses an orthographic projection matrix. This has the effect of drawing the graphical primitives in 2D on channel.
DtChannel* channel = 0;
if ( windows.size() > 0 )
{
DtWindow* window = windows.front();
if ( window )
{
const DtChannelManager::ChannelMap& channels = window->channelManager().channels();
DtChannelManager::ChannelMap::const_iterator curIter = channels.begin();
channel = curIter->second;
if ( ! channel )
{
return;
}
}
}
DtOsgChannel* osgChannel = dynamic_cast<DtOsgChannel*>(channel);
if(!osgChannel)
{
return;
}
if(!osgOverlayManager)
{
return;
}
osg::ref_ptr<DtOverlayDrawable> overlayDrawer = new DtOverlayDrawable(*osgOverlayManager, *channel);
osg::ref_ptr<osg::Geode> geod = new osg::Geode;
geod->addDrawable(overlayDrawer);
osgChannel->overlayCamera()->addChild( geod.get() );
overlayDrawer->setProjectionCamera(osgChannel->overlayCamera());
- Create the DtOverlayRenderer (commonly referred to as the "overlay"). DtOverlayRenderers can be "lazily created" by asking for one that doesn't yet exist. Here we also tell the DtOverlayDrawable to render that specific overlay via the setOverlayToRender call.
DtOverlayRenderer& overlay = osgOverlayManager->overlayRenderer(DtOverlayManager::Channel_SpecificStart + 0);
overlayDrawer->setOverlayToRender(&overlay);
- Create the DtQuad on the overlay,assign a texture to it, then position and size it.
Building the Example
VR-Vantage includes pre-built versions of the example application. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
Running the Example
This example is an application. You can run it by running ./bin/exampleLogopage.exe (on Windows) or ./bin/exampleLogopage (on Linux). For more information about running examples, please see Running Applications and Examples.
Example Source Files
exampleLogo.cxx
#include <osg/Geode>
using namespace makVrv;
{
{
return;
}
if ( windows.size() > 0 )
{
if ( window )
{
DtChannelManager::ChannelMap::const_iterator curIter = channels.begin();
channel = curIter->second;
if ( ! channel )
{
return;
}
}
}
if(!osgChannel)
{
return;
}
if(!osgOverlayManager)
{
return;
}
osg::ref_ptr<DtOverlayDrawable> overlayDrawer =
new DtOverlayDrawable(*osgOverlayManager, *channel);
osg::ref_ptr<osg::Geode> geod = new osg::Geode;
geod->addDrawable(overlayDrawer);
overlayDrawer->setOverlayToRender(&overlay);
if(osgFileCache)
{
std::string logoFilename("../data/Overlays/VtMakLogoTransparent.png");
osg::Texture::NEAREST,osg::Texture::LINEAR,osg::Texture::REPEAT,osg::Texture::REPEAT,
}
float lowerLeftX = 50.0;
float lowerLeftY = 50.0;
float imageWidth = 184.0;
float imageHeight = 60.0;
logoQuad->
setPosition(lowerLeftX, lowerLeftY, 0.0, 0.0);
float points[8];
DtBoundingBox box(lowerLeftX, lowerLeftY, lowerLeftX+imageWidth, lowerLeftY+imageHeight);
box.toPoints(points);
}
int main( int argc, char** argv )
{
}