Overview
This example shows how to create your own QT application and embed a VR-Vantage slave display engine in it. Use any master VR-Vantage application (VR-Vantage XR, VR-Vantage Stealth or VR-Vantage IG for example) to control the visuals embedded in this application.
Expected Result
Embedded Slave Result
Example details
Create and show the main application:
mainWindow.showMaximized();
Run the application:
The example application has a GUI derived from QMainWindow. This is a very common way of building QT applications.
The main window class owns some key VR-Vantage objects. It owns a DtDe (display engine), which is the core component for adding visualization to any application. It also owns a DtPluginManager, which is responsible for loading all the VR-Vantage plug-ins.
The OpenGL graphics context needs to be owned and managed by the QT main window. We connect it the VR-Vantage display engine (and consequently OSG) via the DtOsgAdapterQtWidget.
In addition, main window owns some QT widgets for menus and toolbars.
The real work begins in the constructor of the main window.
First, create the display engine, prepare it to be put into slave mode, create a plug-in manager, and then initialize load the plug-ins.
{
init.setDeMode(DtDeInitializer::SlaveMode);
myDe = new DtDe();
myPluginManager = new DtPluginManager(*myDe);
}
Now we create the GUI. The interesting thing here is the DtQtIgTickerProvider. This provides us with a "ticker" that ticks the display engine as fast as the QT GUI will go. The rest of the function just sets up menus, toolbars, and the other things that would be part of this application.
{
DtQtDeTickerProvider& tickerProvider = DtQtDeTickerProvider::instance(*myDe);
tickerProvider.ticker(this);
setWindowTitle(tr("Embedded Slave Example"));
setWindowIcon(QIcon(":/images/Mak-de.png"));
}
During the call to preDisplayEngineInitialize(), we override the functionality set up by plug-ins. We want to create to use a DtOsgAdapterQtWidget to own the DtEmbeddedOsgWindow and we do that by installing a new creator with the DtWindowFactory.
DtWindowFactory::instance(*myDe).setCreator(
DtWindowConfiguration::EmbeddedWindow,
We have to tell our application framework not to try and create a QApplication, which already exists. We also have to tell it not to create a main window, since that already exists too.
DtQApplicationProvider::instance(*myDe).setQAppInstance(qApp);
DtDeMainWindowProvider::registerInstance(*myDe, NULL);
Finally, everything is all set up and we can initialize the display engine:
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/exampleEmbeddedSlave.exe (on Windows) or ./bin64/exampleEmbeddedSlave (on Linux). Start Vantage separatly, load MakLand terrain, connect the remote display engine by first enabling from the menu "view->Display Engine Configuration Editor Panel". In the "Display Engine Configuration Editor Panel" click on "Connect To Display Engine", set the host name (leave it to localhost if you are running both on the same PC), click connect. For more information about running examples, please see Running Applications and Examples.
Example Source Files
exampleEmbeddedSlaveMain.cxx
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
mainWindow.showMaximized();
return app.exec();
}
exampleEmbeddedSlaveMainWindow.h
#ifndef exampleEmbeddedSlaveMainWindow_H
#define exampleEmbeddedSlaveMainWindow_H
#include <QtWidgets/QMainWindow>
#include <osg/Group>
#include <osg/Node>
{
Q_OBJECT
public:
public slots:
protected:
protected:
};
{
public:
{
}
protected:
};
#endif
exampleEmbeddedSlaveMainWindow.cxx
#include <QtWidgets/QApplication>
#include <QtWidgets/QtWidgets>
#include <osg/Group>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
using namespace makVrv;
, myPluginManager(0)
, myDe(0)
, myMainOSGWidget(0)
{
createDisplayEngine();
buildGui();
preDisplayEngineInitialize();
initializeDisplayEngine();
postDisplayEngineInitialize();
}
{
if (myMainOSGWidget)
{
myMainOSGWidget = 0;
}
myDe = 0;
myPluginManager = 0;
}
{
#ifndef _WIN32
std::list<std::string> excludePlugins;
excludePlugins.push_back("../plugins/release/libvrvDiGuyPlugin.so");
#endif
}
{
setWindowTitle(tr("Embedded Slave Example"));
setWindowIcon(QIcon(":/images/Mak-de.png"));
}
{
DtWindowFactory::instance(*myDe).setCreator(
DtWindowConfiguration::EmbeddedWindow,
DtQApplicationProvider::instance(*myDe).setQAppInstance(qApp);
DtDeMainWindowProvider::registerInstance(*myDe, NULL);
}
{
}
{
}
{
event->accept();
}
{
osg::GraphicsContext* sharedContext = 0;
{
if(windows.size() > 0)
{
if(osgView)
{
}
}
}
traits->sharedContext = sharedContext;
traits->vsync = deInit.
vsync();
if (level == 2 || level == 4 || level == 8 || level == 16 || level == 32)
{
traits->sampleBuffers = 1;
}
else
{
traits->sampleBuffers = 0;
traits->samples = 0;
}
if(wc.
name() ==
"Window 1")
{
DtOsgAdapterQtWidgetCreator::instance( de ).create( de, traits.get(),
DtOsgAdapterQtWidget::createFormatFromTraits(traits.get()),
myWindow );
}
if(pAdapter)
{
if(pWindow)
{
}
}
return pWindow;
}
{
myExitAction =
new QAction(QIcon(
":/images/exit.png"),tr(
"E&xit"),
this);
myExitAction->setStatusTip(tr("Exit the application"));
connect(myExitAction, SIGNAL(triggered()), this, SLOT(close()));
}
{
myFileMenu = this->menuBar()->addMenu(tr("&File"));
myFileMenu->addAction(myExitAction);
}
{
myFileToolBar = this->addToolBar(tr("File"));
}
{
this->statusBar()->showMessage(tr("Ready"));
}
[<< Examples] [Home] [Top of Page]