[osg-users] osgQt + OSG 3.6.2 Status
James Davis
davisjamesf at gmail.com
Wed Jul 18 13:00:27 PDT 2018
I'm no code guru (more like a hacker), but I'll post what I do if it makes sense and helps. Had to hand-type this as my code is on a different PC and I couldnt copy. You'll probably see some typos and short cuts.
My setup is in a class called OSGDataViewer which double inherits a view base class (pretty much a QMainWindow) and a CompositeViewer.
I define a osgQt::GraphisWindowQt* m_gw member along with all my manipulators, rootnode hud etc in this OSGDataViewer class.
In my constructor, I call a method initializeOSG() which does the following:
setThreadModel(osgViewer::Viewer::SingleThreaded);
osg::ref_ptr<osg::Camera> cam0 = this->createCamera(x(), y(), height(), "Main Camera", false); //more on createCamera in a bit. x,y,width,height comes from qmainwindow
QWidget* GLWidget = m_gw->getGLWidget();
//finally set my central widget
this->setCentralWidget(GLWidget);
I then setup a cam1 which is my hud camera. I'll post if you want to see it.
Next I set up my root node, depthPartitionNode, and others.
finally, I'll call another local method:
addNewView(cam0.get(), rootnode.get(), "MainView") //i'd call this with cam1 also. This method is described below also
finally, my difference scene manipulators are created and i'd do something like the following:
this->getView(0)->setCameraManipulator(m_keyswitchManipulator.get())
I'd also setup callbacks as example:
this->getView(1)->getCamera()->setFinalDrawCallbac(w_WinCapCallback.get())
------------
here is my createCamera method:
osg::Camera* OSGDataViewer::createCamera(int x, y, w, h, name...)
osg::ref_ptr<osg::DisplaySettings> ds = osg::DisplaySettings::instance();
ds->setMaxNumberOfGraphicContext(20)
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->readDISPLAY
if (traits->displayNum<0) traigs->displayNum=0;
traits->windowName = name
traits->.....
x=x
y=y
width=w
alpha = ds->getMinimumNumberAlphaBits
stencil = ds->getMinimumNumStencilBits()
windowDecoration = false
doubleBuffer = true;
sampleBuffers = ds->getMultiSamples
samples = ds->getNumMultiSamples
traits->inheritedWindowData = new osgViewer::GraphicsWindowWin32::WindowData((HWND)QWidget::winID());
osgQt::GraphicsWindowQt *GWQ;
if (!m_gw)
traits->sharedContext = 0;
GWQ = new osgQt::GraphicsWindowQt(traits.get())
GWQ->createNewContextID
else
traits->sharedContext = m_gw
GWQ = new osgQt::GraphicsWindowQt(traits.get())
GWQ->createNewContextID();
GWQ->setName(name)
osg::ref_ptr<osg::Camera> camera = new osg::Camera()
camera->setGraphicsContext(GWQ);
QWidget* GLWidget = GWQ->getGLWidget();
GLWidget->setAttribute(Qt::WA_PaintOnScreen)
..... WA_NoSystemBackground
WA_OpaquePaintEvent
WA_DeleteOnClose
GLWidget->setAttribute(Qt::ClickFocus)
camera->setClearColor(...
camera->setViewPort(new osg::Viewport(0, 0, traits->width, traits->height))
camera ->setLODScale(3.0)
camera->setProjectionMatrixAsPerspective(......
osg::StateSet* stateset = camera->getOrCreateStateSet()
stateset->setGlobalDefaults()
return camera.release()
------------
here is my addNewView method:
void OSGDataViewer::addNewView(osg::Camera* camera, osg::Node* scene, string viewname)
osgVIewer::View* view = new osgVIewer::View;
view->setCamera(camera)
view->adddEventHandler(new osgGA::StateSetManipulator(view->getCamera()->getOrCreateStateSet()))
view->addEventHandler(new osgVIewer::ThreadingHandler)
.... ::WindowSizeHandler)
::StatsHandler)
view->setLightingMode(osg::View::SKY_LIGHT)
view->getDatabasePaer()->setUnrefImageDataAfterApplyPolicy(true, valse)
this->addView(view)
view->setSceneData(scene);
Hope this is as clear as mud!
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74359#74359
More information about the osg-users
mailing list