| [6941] | 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| [5608] | 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| [9655] | 23 | #include <osg/Config> |
|---|
| 24 | |
|---|
| [9640] | 25 | #if defined(_MSC_VER) && defined(OSG_DISABLE_MSVC_WARNINGS) |
|---|
| 26 | |
|---|
| 27 | #pragma warning( disable : 4505 ) |
|---|
| 28 | #endif |
|---|
| 29 | |
|---|
| [5608] | 30 | #include <iostream> |
|---|
| 31 | #ifdef WIN32 |
|---|
| 32 | #include <windows.h> |
|---|
| 33 | #endif |
|---|
| [9655] | 34 | |
|---|
| [5608] | 35 | #ifdef __APPLE__ |
|---|
| 36 | # include <GLUT/glut.h> |
|---|
| 37 | #else |
|---|
| 38 | # include <GL/glut.h> |
|---|
| 39 | #endif |
|---|
| 40 | |
|---|
| [6814] | 41 | #include <osgViewer/Viewer> |
|---|
| [6864] | 42 | #include <osgViewer/ViewerEventHandlers> |
|---|
| [5608] | 43 | #include <osgGA/TrackballManipulator> |
|---|
| 44 | #include <osgDB/ReadFile> |
|---|
| 45 | |
|---|
| [6814] | 46 | osg::ref_ptr<osgViewer::Viewer> viewer; |
|---|
| [6899] | 47 | osg::observer_ptr<osgViewer::GraphicsWindow> window; |
|---|
| [5608] | 48 | |
|---|
| 49 | void display(void) |
|---|
| 50 | { |
|---|
| 51 | |
|---|
| [6899] | 52 | if (viewer.valid()) viewer->frame(); |
|---|
| [5608] | 53 | |
|---|
| 54 | |
|---|
| 55 | glutSwapBuffers(); |
|---|
| 56 | glutPostRedisplay(); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | void reshape( int w, int h ) |
|---|
| 60 | { |
|---|
| 61 | |
|---|
| [6899] | 62 | if (window.valid()) |
|---|
| 63 | { |
|---|
| 64 | window->resized(window->getTraits()->x, window->getTraits()->y, w, h); |
|---|
| 65 | window->getEventQueue()->windowResize(window->getTraits()->x, window->getTraits()->y, w, h ); |
|---|
| 66 | } |
|---|
| [5608] | 67 | } |
|---|
| 68 | |
|---|
| 69 | void mousebutton( int button, int state, int x, int y ) |
|---|
| 70 | { |
|---|
| [6899] | 71 | if (window.valid()) |
|---|
| 72 | { |
|---|
| 73 | if (state==0) window->getEventQueue()->mouseButtonPress( x, y, button+1 ); |
|---|
| 74 | else window->getEventQueue()->mouseButtonRelease( x, y, button+1 ); |
|---|
| 75 | } |
|---|
| [5608] | 76 | } |
|---|
| 77 | |
|---|
| 78 | void mousemove( int x, int y ) |
|---|
| 79 | { |
|---|
| [6899] | 80 | if (window.valid()) |
|---|
| 81 | { |
|---|
| 82 | window->getEventQueue()->mouseMotion( x, y ); |
|---|
| 83 | } |
|---|
| [5608] | 84 | } |
|---|
| 85 | |
|---|
| 86 | void keyboard( unsigned char key, int , int ) |
|---|
| 87 | { |
|---|
| 88 | switch( key ) |
|---|
| 89 | { |
|---|
| 90 | case 27: |
|---|
| [6899] | 91 | |
|---|
| 92 | if (viewer.valid()) viewer = 0; |
|---|
| [5608] | 93 | glutDestroyWindow(glutGetWindow()); |
|---|
| 94 | break; |
|---|
| 95 | default: |
|---|
| [6899] | 96 | if (window.valid()) |
|---|
| 97 | { |
|---|
| 98 | window->getEventQueue()->keyPress( (osgGA::GUIEventAdapter::KeySymbol) key ); |
|---|
| 99 | window->getEventQueue()->keyRelease( (osgGA::GUIEventAdapter::KeySymbol) key ); |
|---|
| 100 | } |
|---|
| [5608] | 101 | break; |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | int main( int argc, char **argv ) |
|---|
| 106 | { |
|---|
| 107 | glutInit(&argc, argv); |
|---|
| 108 | |
|---|
| 109 | if (argc<2) |
|---|
| 110 | { |
|---|
| 111 | std::cout << argv[0] <<": requires filename argument." << std::endl; |
|---|
| 112 | return 1; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(argv[1]); |
|---|
| 117 | if (!loadedModel) |
|---|
| 118 | { |
|---|
| 119 | std::cout << argv[0] <<": No data loaded." << std::endl; |
|---|
| 120 | return 1; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_ALPHA ); |
|---|
| 124 | glutInitWindowPosition( 100, 100 ); |
|---|
| 125 | glutInitWindowSize( 800, 600 ); |
|---|
| 126 | glutCreateWindow( argv[0] ); |
|---|
| 127 | glutDisplayFunc( display ); |
|---|
| 128 | glutReshapeFunc( reshape ); |
|---|
| 129 | glutMouseFunc( mousebutton ); |
|---|
| 130 | glutMotionFunc( mousemove ); |
|---|
| 131 | glutKeyboardFunc( keyboard ); |
|---|
| 132 | |
|---|
| 133 | |
|---|
| [6814] | 134 | viewer = new osgViewer::Viewer; |
|---|
| [6821] | 135 | window = viewer->setUpViewerAsEmbeddedInWindow(100,100,800,600); |
|---|
| [5608] | 136 | viewer->setSceneData(loadedModel.get()); |
|---|
| 137 | viewer->setCameraManipulator(new osgGA::TrackballManipulator); |
|---|
| [6814] | 138 | viewer->addEventHandler(new osgViewer::StatsHandler); |
|---|
| 139 | viewer->realize(); |
|---|
| [5608] | 140 | |
|---|
| 141 | glutMainLoop(); |
|---|
| [6814] | 142 | |
|---|
| [5608] | 143 | return 0; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|