OSG 與QT 結合

Sunday發表於2014-03-27
#include <QtGui/QApplication>

#include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator>
#include <osgQt/GraphicsWindowQt>

#include <osg/ShapeDrawable>
#include <osg/MatrixTransform>
#include <osgManipulator/TabBoxDragger>
#include <osgGA/StateSetManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgDB/ReadFile>



int main( int argc, char** argv )
{
	QApplication app(argc, argv);    
	osgQt::initQtWindowingSystem();

	osg::Group* sceneroot = new osg::Group;
 
	 sceneroot->addChild(osgDB::readNodeFile("cow.osg"));
	 osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
	 viewer->addEventHandler( new osgGA::StateSetManipulator(viewer->getCamera()->getOrCreateStateSet()) );
	 viewer->addEventHandler(new osgViewer::StatsHandler);


	viewer->setSceneData( sceneroot );
	viewer->setCameraManipulator( new osgGA::TrackballManipulator );
	osgQt::setViewer( viewer.get() );

	osgQt::GLWidget* glw = new osgQt::GLWidget;
	osgQt::GraphicsWindowQt* graphicswin = new osgQt::GraphicsWindowQt(glw);
	 
	viewer->getCamera()->setViewport( new osg::Viewport(0, 0, glw->width(), glw->height() ) );
	viewer->getCamera()->setGraphicsContext( graphicswin );

	glw->show();

	return app.exec();
}



相關文章