1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
| #include <osgQOpenGL/osgQOpenGLWidget>
#include <osgDB/ReadFile> #include <osgUtil/Optimizer> #include <osg/CoordinateSystemNode>
#include <osg/Switch> #include <osg/Types> #include <osgViewer/Viewer> #include <osgText/Text>
#include <osgViewer/Viewer> #include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator> #include <osgGA/FlightManipulator> #include <osgGA/DriveManipulator> #include <osgGA/KeySwitchMatrixManipulator> #include <osgGA/StateSetManipulator> #include <osgGA/AnimationPathManipulator> #include <osgGA/TerrainManipulator> #include <osgGA/SphericalManipulator>
#include <osgGA/Device>
#include <QApplication> #include <QSurfaceFormat>
#include <iostream>
int main( int argc, char** argv ) {
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
#ifdef OSG_GL3_AVAILABLE format.setVersion(3, 2); format.setProfile(QSurfaceFormat::CoreProfile); format.setRenderableType(QSurfaceFormat::OpenGL); format.setOption(QSurfaceFormat::DebugContext); #else format.setVersion(2, 0); format.setProfile(QSurfaceFormat::CompatibilityProfile); format.setRenderableType(QSurfaceFormat::OpenGL); format.setOption(QSurfaceFormat::DebugContext); #endif format.setDepthBufferSize(24); format.setSamples(8); format.setStencilBufferSize(8); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); QSurfaceFormat::setDefaultFormat(format);
QApplication app(argc, argv);
osg::ArgumentParser arguments(&argc, argv);
arguments.getApplicationUsage()->setApplicationName( arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName() + " is the standard OpenSceneGraph example which loads and visualises 3d models."); arguments.getApplicationUsage()->setCommandLineUsage( arguments.getApplicationName() + " [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("--image <filename>", "Load an image and render it on a quad"); arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>", "Load an image/DEM and render it on a HeightField"); arguments.getApplicationUsage()->addCommandLineOption("--login <url> <username> <password>", "Provide authentication information for http file access."); arguments.getApplicationUsage()->addCommandLineOption("-p <filename>", "Play specified camera path animation file, previously saved with 'z' key.", "F:/dataSets/OpenSceneGraph-Data-3.4.0/OpenSceneGraph-Data/glider.osg"); arguments.getApplicationUsage()->addCommandLineOption("--speed <factor>", "Speed factor for animation playing (1 == normal speed)."); arguments.getApplicationUsage()->addCommandLineOption("--device <device-name>", "add named device to the viewer");
osgQOpenGLWidget widget(&arguments);
if (true) {
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("F:/dataSets/OpenSceneGraph-Data-3.4.0/OpenSceneGraph-Data/glider.osg");
if (!loadedModel) { std::cout << arguments.getApplicationName() << ": No data loaded" << std::endl; return 1; }
arguments.reportRemainingOptionsAsUnrecognized();
if (arguments.errors()) { arguments.writeErrorMessages(std::cout); return 1; }
widget.show();
osgUtil::Optimizer optimizer; optimizer.optimize(loadedModel);
osg::ref_ptr<osgViewer::Viewer> mViewer = widget.getOsgViewer(); osg::ref_ptr<osg::Camera> camera = mViewer->getCamera();
camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); camera->setClearColor(osg::Vec4f(0.2f, 0.2f, 0.4f, 1.0f));
mViewer->setCamera(camera.get());
osg::ref_ptr<osgGA::TrackballManipulator> trackball = new osgGA::TrackballManipulator(); mViewer->setCameraManipulator(trackball.get());
mViewer->setSceneData(loadedModel);
return app.exec(); } }
|