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 overlays 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 graph. In this case we add a DtOverlayDrawable to the scene graph. 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. However, since we would like to add a texture to the DtQuad, we will create a new class MyTexturedQuad, which has an osg::ref_ptr that will hold our texture reference.
Create a New Class (MyTexturedQuad)
class MyTexturedQuad : public DtQuad
{
public:
MyTexturedQuad( DtOverlayRenderer& overlay )
: DtQuad( overlay )
{
}
void setTexture( DtDe& de,
const std::string& texFilename )
{
DtOsgFileCache* osgFileCache = dynamic_cast<DtOsgFileCache*>(de.fileCache());
if(osgFileCache)
{
myTexture = osgFileCache->getTextureInstance(texFilename,
osg::Texture::NEAREST,osg::Texture::LINEAR,osg::Texture::REPEAT,
osg::Texture::REPEAT,
de.fileCache()->defaultOptions());
setTextureParameter(myTexture.get());
}
}
private:
osg::ref_ptr<osg::Texture> myTexture;
};
Overlays can be created that are drawn on a specific channel, on all channels currently rendering a specific model set, or on all channels with the keyword "RemoteGraphics". For our example we will create a channel-specific overlay, in the function createUserOverlay.
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.
DtOsgOverlayManager* osgOverlayManager =
(DtOsgOverlayManager*)&de.renderer().overlayManager();
osg::ref_ptr<DtOverlayDrawable> overlayDrawable = new DtOverlayDrawable(
*osgOverlayManager, *osgChannel);
osg::ref_ptr<osg::Geode> geod = new osg::Geode;
geod->addDrawable(overlayDrawable);
overlayDrawable->setProjectionCamera(osgChannel->
overlayCamera());
Create the DtOverlayRenderer
DtOverlayRenderers (commonly referred to as the overlay) 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& overlayRenderer = osgOverlayManager->overlayRenderer(DtOverlayManager::UserStart);
overlayDrawable->setOverlayToRender(&overlayRenderer);
The Main Routine
Our main routine, addQuad, will look up the first channel, create our user overlay (calling createUserOverlay), create the textured quad on the overlay, assign a texture to it, then position and size it.
float lowerLeftX = 50.0;
float lowerLeftY = 50.0;
float imageWidth = 184.0;
float imageHeight = 60.0;
float points[8];
DtBoundingBox
box(0., 0., imageWidth, imageHeight);
MyTexturedQuad* logoQuad = new MyTexturedQuad(overlay);
logoQuad->setFillType(DtQuad::Fill_Texture);
logoQuad->setPoints(points);
logoQuad->setPosition(lowerLeftX, lowerLeftY, 0.0, 0.0);
logoQuad->setTexture( de, "../data/Overlays/VtMakLogo.png" );
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 ./bin64/exampleLogopage.exe (on Windows) or ./bin64/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;
class MyTexturedQuad :
public DtQuad
{
public:
{
}
{
if(osgFileCache)
{
osg::Texture::NEAREST,osg::Texture::LINEAR,osg::Texture::REPEAT,
osg::Texture::REPEAT,
setTextureParameter(myTexture.get());
}
}
private:
osg::ref_ptr<osg::Texture> myTexture;
};
{
*osgOverlayManager, *osgChannel);
osg::ref_ptr<osg::Geode> geod = new osg::Geode;
geod->addDrawable(overlayDrawable);
overlayDrawable->setProjectionCamera(osgChannel->
overlayCamera());
overlayDrawable->setOverlayToRender(&overlayRenderer);
return overlayRenderer;
}
MyTexturedQuad* addQuad(
DtDe& de )
{
{
return 0;
}
if ( windows.size() > 0 )
{
if ( window )
{
DtChannelManager::ChannelMap::const_iterator curIter = channels.begin();
channel = curIter->second;
if ( ! channel )
{
return 0;
}
}
}
if(!osgChannel)
{
return 0;
}
float lowerLeftX = 50.0;
float lowerLeftY = 50.0;
float imageWidth = 184.0;
float imageHeight = 60.0;
float points[8];
MyTexturedQuad* logoQuad = new MyTexturedQuad(overlay);
logoQuad->setPoints(points);
logoQuad->setPosition(lowerLeftX, lowerLeftY, 0.0, 0.0);
logoQuad->setTexture( de, "../data/Overlays/VtMakLogo.png" );
return logoQuad;
}
int main( int argc, char** argv )
{
MyTexturedQuad* quad = addQuad( igApp.
de() );
delete quad;
return 0;
}