This example plugin creates a new driver that demonstrates how to use OpenGL draw calls from a subclass of osg::Drawable that gets added to the normalized 2D camera of all DtOsgChannels.
Instantiate a DtReticleDrawable when the driver starts up and put it into an osg::Geode so it can be added to cameras:
To get the reticle geode added to any new channels, hook up signal_channelCreated from the drivers constructor:
This example is a plug-in. You can run it by running ./bin64/exampleGLDrawingPlugin_stealth.bat (on Windows) or ./bin64/exampleGLDrawingPlugin_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.
#ifdef _WIN32
#ifdef EXAMPLEGLDRAWINGPLUGIN_EXPORTS
#define DT_DLL_EXAMPLEGLDRAWINGPLUGIN __declspec ( dllexport )
#else
#define DT_DLL_EXAMPLEGLDRAWINGPLUGIN __declspec ( dllimport )
#endif
#else
#define DT_DLL_EXAMPLEGLDRAWINGPLUGIN
#endif
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEGLDRAWINGPLUGIN
#include <matrix/vlMath.h>
#include <osg/Drawable>
#include <osg/Geode>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <boost/bind/bind.hpp>
static vrvSignalsLib::connection postInitializeConnection;
class DtCustomDrawable : public osg::Drawable
{
public:
DtCustomDrawable()
{
myIsReticleEnabled = false;
myIsCubeEnabled = false;
setSupportsDisplayList(false);
setUseDisplayList(false);
};
DtCustomDrawable(const DtCustomDrawable& drawable,
const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) :
osg::Drawable(drawable,copyop)
{
myIsReticleEnabled = drawable.myIsReticleEnabled;
myIsCubeEnabled = drawable.myIsCubeEnabled;
setSupportsDisplayList(false);
setUseDisplayList(false);
}
virtual ~DtCustomDrawable()
{
};
META_Object(test, DtCustomDrawable)
virtual void drawImplementation(osg::RenderInfo& state) const
{
if (myIsReticleEnabled)
renderReticle(state);
if (myIsCubeEnabled)
renderCube(state);
}
virtual void renderReticle(osg::RenderInfo& state) const
{
osg::Viewport* viewport = state.getCurrentCamera()->getViewport();
if (!viewport)
{
return;
}
int width = viewport->width();
int height = viewport->height();
float aspect = viewport->width() / viewport->height();
glPushMatrix();
glPushAttrib(GL_LINE_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (width >= height)
{
gluOrtho2D(-1.0 * aspect, 1.0 * aspect, -1.0, 1.0);
}
else
{
gluOrtho2D(-1.0, 1.0, -1.0 / aspect, 1.0 / aspect);
}
int lineWidth = 10;
if ((width * .01) < lineWidth)
{
lineWidth = width * .01;
}
glLineWidth(lineWidth);
glBegin(GL_LINE_LOOP);
glColor3f(0.0f, 1.0f, 0.0f);
float radius = 0.5;
float centerX = 0.0;
float centerY = 0.0;
for (int i=0; i < 360; i++)
{
float radians = i * M_DEG2RAD;
glVertex2f(centerX + cos(radians)*radius,
centerY + sin(radians)*radius);
}
glEnd();
glBegin(GL_LINES);
glColor3f(0.0f, 1.0f, 0.0f);
float extra = 0.06;
glVertex2f(centerX - (radius + extra), centerY);
glVertex2f(centerX - radius/2, centerY);
glVertex2f(centerX + (radius + extra), centerY);
glVertex2f(centerX + radius/2, centerY);
glVertex2f(centerX, centerY - (radius + extra));
glVertex2f(centerX, centerY - radius/2);
glVertex2f(centerX, centerY + (radius + extra));
glVertex2f(centerX, centerY + radius/2);
glEnd();
glLineWidth(2.0);
glBegin(GL_LINES);
glVertex2f(centerX - radius/2, centerY);
glVertex2f(centerX + radius/2, centerY);
glVertex2f(centerX, centerY - radius/2);
glVertex2f(centerX, centerY + radius/2);
glEnd();
glPopAttrib();
glPopMatrix();
}
virtual void renderCube(osg::RenderInfo& renderInfo) const
{
glPushAttrib(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_GREATER);
glPushAttrib(GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
osg::Matrixd projMat = renderInfo.getState()->getProjectionMatrix();
glLoadMatrixd( projMat.ptr() );
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(0.0, 0.0, -distance);
static int frame = 0;
++frame;
float rotDeg = (float)frame / 10.0f;
glRotatef(rotDeg, 0.0f, 1.0f, 0.0f);
glRotatef(rotDeg, 1.0f, 0.0f, 0.0f);
float size = 100.0f;
glScalef(size, size, size);
glColor3f(0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glEnd();
glColor3f(0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glEnd();
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
glVertex3f( -0.5f, 0.5f, 0.5f);
glVertex3f( -0.5f, 0.5f, -0.5f);
glVertex3f( -0.5f, -0.5f, -0.5f);
glVertex3f( -0.5f, -0.5f, 0.5f);
glEnd();
glColor3f(0.0f, 1.0f, 0.0f);
glBegin(GL_QUADS);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( -0.5f, 0.5f, -0.5f);
glVertex3f( -0.5f, 0.5f, 0.5f);
glEnd();
glColor3f(0.0f, 1.0f, 0.0f);
glBegin(GL_QUADS);
glVertex3f( 0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( -0.5f, -0.5f, -0.5f);
glVertex3f( -0.5f, -0.5f, 0.5f);
glEnd();
glPopAttrib();
glPopAttrib();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
bool myIsReticleEnabled;
bool myIsCubeEnabled;
};
{
public:
DtExampleGLDrawingDriver( DtAgentManager& am )
: makVrv::DtDriver( am, "DtExampleGLDrawingDriver" )
{
boost::bind(&DtExampleGLDrawingDriver::slot_channelCreated, this,
boost::placeholders::_1, boost::placeholders::_2));
}
virtual ~DtExampleGLDrawingDriver()
{
}
{
static std::string name = "DtExampleGLDrawingDriver";
return name;
}
void slot_channelCreated(DtChannelManager* mgr, DtChannel* channel)
{
DtOsgChannel* osgChannel = dynamic_cast<DtOsgChannel*>(channel);
if (!osgChannel || !myReticleGeode || !myCubeGeode)
{
return;
}
}
{
myReticle = new DtCustomDrawable();
myReticle->myIsReticleEnabled = true;
myReticle->myIsCubeEnabled = false;
myReticleGeode = new osg::Geode();
myReticleGeode->setName("Reticle Geode");
myReticleGeode->addDrawable(myReticle);
myCube = new DtCustomDrawable();
myCube->myIsReticleEnabled = false;
myCube->myIsCubeEnabled = true;
myCubeGeode = new osg::Geode();
myCubeGeode->setName("Cube Geode");
myCubeGeode->addDrawable(myCube);
osg::StateSet* ss = myReticleGeode->getOrCreateStateSet();
ss->setAttributeAndModes(new osg::Program(), osg::StateAttribute::OFF);
ss->setTextureMode(0, GL_TEXTURE_1D, osg::StateAttribute::OFF);
ss->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF);
ss->setTextureMode(0, GL_TEXTURE_3D, osg::StateAttribute::OFF);
ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
ss->setMode(GL_BLEND, osg::StateAttribute::OFF);
ss->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
ss->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED);
myCubeGeode->setStateSet(ss);
DtWindowManager::WindowList wins = myAgentManager.de().display()->windowManager().windows();
DtWindowManager::WindowList::iterator winIter = wins.begin();
for(winIter; winIter != wins.end(); ++winIter)
{
DtChannelManager::ChannelMap channels = (*winIter)->channelManager().channels();
DtChannelManager::ChannelMap::iterator chanIter=channels.begin();
for(chanIter; chanIter!=channels.end(); ++chanIter)
{
DtOsgChannel* osgChannel = dynamic_cast<DtOsgChannel*>(chanIter->second);
if (osgChannel)
{
}
}
}
return true;
}
{
return true;
}
{
return true;
}
protected:
osg::ref_ptr<DtCustomDrawable> myReticle;
osg::ref_ptr<osg::Geode> myReticleGeode;
osg::ref_ptr<DtCustomDrawable> myCube;
osg::ref_ptr<osg::Geode> myCubeGeode;
makVrv::DtSignalConnectionManager mySignalConnections;
};
{
DtExampleGLDrawingDriver* driver =
new DtExampleGLDrawingDriver(de.
agentManager());
}
{
{
}
}
{
return true;
}
Contains makVrv:DtAgentManager 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:DtDisplay class.
Contains makVrv:DtDriver class.
Contains makVrv:DtMasterScene class.
Contains makVrv::DtOsgChannel class.
Contains makVrv::DtOsgEmptySceneLogo class.
Base class to provide boost signal/slot management.
Contains makVrv::DtIgView class.
Contains makVrv::DtWindowManager class.
boost::signalslib::signal< void(DtChannelManager *, DtChannel *)> signal_channelCreated
Signals when a new channel is created.
Definition DtChannelManager.h:110
static DtChannelManagerSignaler & instance(DtDe &anIG)
Get an instance of the signaler.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
DtAgentManager & agentManager()
Get the scene manager.
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
virtual DtDriverManager & driverManager()
The DtMasterScene accessor. The function will throw before the initialize function is called.
boost::signalslib::signal< void()> signal_postInitialize
Definition DtDe.h:535
The DtDriver is an abstract class. Developers derive from this to create logic that "directs" things ...
Definition DtDriver.h:32
virtual const std::string & className() const =0
Get this driver's class name.
virtual bool onStart()=0
Start the host output. Create all objects for an existing host connection.
virtual bool onTick()=0
Tick.
virtual bool onStop()=0
Stop the host output. All scene object created by the host should be destroyed.
void addDriver(DtDriver *driver)
Add a host driver to the master scene. The host is now owned by the Master Scene.
void startDriver(DtDriver *driver)
Start a driver driver modifying the scene.
virtual DtCameraNode * sceneCamera()
Accessor for the 3D camera.
virtual DtCameraNode * normalizedOverlayCamera()
Accessor for the normalized 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...
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
DT_DLL_EXAMPLEPROJECTILE void installDriver(makVrv::DtDe &de)
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
DT_DLL_VRVCORE double distance(const makVrv::DtCoordinateSystem &, const DtVector &from, const DtVector &to)
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
Definition DtOverlayPolygonModelInstance.h:28