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.
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.
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.
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.
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.
This example is a plug-in. You can run it by running ./bin64/exampleLogo_stealth.bat (on Windows from cmd.exe) or ./bin64/exampleLogo_stealth.sh (on Linux). The MAK logo is displayed on top of the scene. For more information about running examples, please see Running Applications and Examples.
#include <osg/Geode>
#include <osg/BlendFunc>
#include <boost/bind/bind.hpp>
static vrvSignalsLib::connection myPostTickConnection;
static vrvSignalsLib::connection myShutDownConnection;
class MyTexturedQuad;
static MyTexturedQuad* quadPointer;
class MyTexturedQuad
{
public:
{
float lowerLeftX = 50.0;
float lowerLeftY = 50.0;
float imageWidth = 184.0;
float imageHeight = 60.0;
float points[8];
box.toPoints( points );
myQuad->setPoints( points );
myQuad->set3DPosition( lowerLeftX, lowerLeftY, 0.0, 0.0 );
myTexture->loadTextureFromFile( file, myDe.fileCache()->defaultOptions() );
myQuad->setTextureParameters( myTexture );
}
~MyTexturedQuad()
{
DtDELETE( myQuad );
DtDELETE( myTexture );
}
protected:
};
{
osg::ref_ptr<DtOverlayDrawable> overlayDrawable =
new DtOverlayDrawable(de, *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;
}
MyTexturedQuad* logoQuad = new MyTexturedQuad(de,overlay);
return logoQuad;
}
void addQuadCallback(
DtDe* de)
{
myPostTickConnection.disconnect();
quadPointer = addQuad(*de);
}
void removeQuadCallback(
DtDe* de )
{
myShutDownConnection.disconnect();
delete quadPointer;
}
{
{
myPostTickConnection = de.
signal_postTick.connect(boost::bind(&addQuadCallback, &de));
myShutDownConnection = de.
signal_quit.connect(boost::bind(&removeQuadCallback, &de));
}
}
{
return true;
}
Contains the makVrv::DtBoundingBox class declaration.
Contains makVrv::DtChannel class.
Contains makVrv::DtChannelManager class.
Contains makVrv::DtDe class.
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30
Contains makVrv::DtDeSharedState class.
Contains makVrv:DtDisplay class.
Contains makVrv::DtOsgChannel class.
Contains makVrv::DtOsgEmptySceneLogo class.
Contains makVrv::DtOsgFileCache class.
Contains makVrv::DtOsgOverlayManager class.
Contains makVrv::DtOsgTextureWrapper class.
Contains makVrv::DtOverlayDrawable class.
Contains the makVrv::DtOverlayRenderer class declaration.
Contains the makVrv::DtQuadProxy class declaration.
Contains makVrv::DtRenderer class.
Contains makVrv::DtTextureInterface class.
Contains makVrv::DtIgView class.
Contains makVrv::DtWindowManager class.
Definition DtBoundingBox.h:102
The abstract Channel Class.
Definition DtChannel.h:36
std::map< std::string, DtChannel * > ChannelMap
Definition DtChannelManager.h:42
virtual const ChannelMap & channels() const
Get the channel list.
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
virtual const DtDePathConfiguration & dePathConfiguration() const
Return the DtDePathConfiguration.
virtual DtDisplay * display()
DtDisplay accessor. The returned pointer will be NULL before initialize is called,...
boost::signalslib::signal< void()> signal_quit
Definition DtDe.h:619
boost::signalslib::signal< void()> signal_postTick
Definition DtDe.h:549
virtual DtRenderer & renderer() const
Get the renderer.
virtual std::string resolvePath(const std::string &directory) const
virtual DtWindowManager & windowManager()
DtWindowManager accessor.
This class provides the OSG-specific implementation of a DtChannel.
Definition DtOsgChannel.h:59
virtual DtCameraNode * overlayCamera()
Accessor for the 2D overlay camera.
static void setEnabled(bool enabled)
This global method will enable or disable the use of an empty scene overlay for all uses of this clas...
The OSG overlay manager managers 2D graphical overlays.
Definition DtOsgOverlayManager.h:41
virtual DtOverlayRendererInterface & overlayRenderer(unsigned int layerId)
Get the renderer for any layer.
Definition DtOverlayDrawable.h:33
@ UserStart
Definition DtOverlayManager.h:53
Definition DtOverlayRenderer.h:68
Definition DtQuadProxyInterface.h:22
Definition DtTextureInterface.h:110
Interface for a texture. Used to pass in a texture to vrvGraphics.
Definition DtTextureInterface.h:27
Abstract Base class.
Definition DtWindow.h:26
virtual DtChannelManager & channelManager()
Get the window's channel manager.
std::list< DtWindow * > WindowList
Definition DtWindowManager.h:36
virtual WindowList & windows()
Get the window list.
Contains declarations for plugin initialization functions.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)