| 14 | | #include <osgProducer/Viewer> |
| 15 | | |
| 16 | | #include <Producer/CameraConfig> |
| 17 | | |
| 18 | | static Producer::CameraConfig *BuildConfig(void) |
| 19 | | { |
| 20 | | #define TWO_SEPERATE_WINDOWS |
| 21 | | |
| 22 | | #ifdef TWO_SEPERATE_WINDOWS |
| 23 | | Producer::RenderSurface *rs1 = new Producer::RenderSurface; |
| 24 | | rs1->setScreenNum(0); |
| 25 | | rs1->setWindowName("osgwindows"); |
| 26 | | //rs1->useBorder(false); |
| 27 | | rs1->setWindowRectangle(0,0,640,480); |
| 28 | | Producer::Camera *camera1 = new Producer::Camera; |
| 29 | | camera1->setRenderSurface(rs1); |
| 30 | | camera1->setOffset( 1.0, 0.0 ); |
| 31 | | |
| 32 | | Producer::RenderSurface *rs2 = new Producer::RenderSurface; |
| 33 | | rs2->setScreenNum(0); |
| 34 | | rs2->setWindowName("osgwindows"); |
| 35 | | //rs2->useBorder(false); |
| 36 | | rs2->setWindowRectangle(640,0,640,480); |
| 37 | | Producer::Camera *camera2 = new Producer::Camera; |
| 38 | | camera2->setRenderSurface(rs2); |
| 39 | | camera2->setOffset( -1.0, 0.0 ); |
| 40 | | |
| 41 | | rs1->setInputRectangle( Producer::RenderSurface::InputRectangle(0.0,0.5,0.0,1.0)); |
| 42 | | rs2->setInputRectangle( Producer::RenderSurface::InputRectangle(0.5,1.0,0.0,1.0)); |
| 43 | | |
| 44 | | Producer::InputArea *ia = new Producer::InputArea; |
| 45 | | ia->addRenderSurface(rs1); |
| 46 | | ia->addRenderSurface(rs2); |
| 47 | | |
| 48 | | Producer::CameraConfig *cfg = new Producer::CameraConfig; |
| 49 | | cfg->addCamera("Camera 1",camera1); |
| 50 | | cfg->addCamera("Camera 2", camera2); |
| 51 | | cfg->setInputArea(ia); |
| 52 | | return cfg; |
| 53 | | |
| 54 | | #else |
| 55 | | // one window with four camera's. |
| 56 | | Producer::Camera* pcam1 = new Producer::Camera (); |
| 57 | | pcam1->setProjectionRectangle (0.0f, 0.5f, 0.5f, 1.0f); |
| 58 | | |
| 59 | | Producer::Camera* pcam2 = new Producer::Camera (); |
| 60 | | pcam2->setRenderSurface (pcam1->getRenderSurface ()); |
| 61 | | pcam2->setProjectionRectangle (0.5f, 1.0f, 0.5f, 1.0f); |
| 62 | | |
| 63 | | Producer::Camera* pcam3 = new Producer::Camera (); |
| 64 | | pcam3->setRenderSurface (pcam1->getRenderSurface ()); |
| 65 | | pcam3->setProjectionRectangle (0.0f, 0.5f, 0.0f, 0.5f); |
| 66 | | |
| 67 | | Producer::Camera* pcam4 = new Producer::Camera (); |
| 68 | | pcam4->setRenderSurface (pcam1->getRenderSurface ()); |
| 69 | | pcam4->setProjectionRectangle (0.5f, 1.0f, 0.0f, 0.5f); |
| 70 | | |
| 71 | | Producer::CameraConfig *cfg = new Producer::CameraConfig; |
| 72 | | cfg->addCamera("Camera 1",pcam1); |
| 73 | | cfg->addCamera("Camera 2",pcam2); |
| 74 | | cfg->addCamera("Camera 3",pcam3); |
| 75 | | cfg->addCamera("Camera 4",pcam4); |
| 76 | | |
| 77 | | return cfg; |
| 78 | | #endif |
| 79 | | } |
| | 14 | #include <osgViewer/Viewer> |
| 86 | | |
| 87 | | // set up the usage document, in case we need to print out how to use this program. |
| 88 | | arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); |
| 89 | | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrate hows to set up programitically a Producer::CameraConfig and use it to set up multiple window views."); |
| 90 | | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
| 91 | | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
| 92 | | |
| 93 | | |
| 94 | | // construct the viewer. |
| 95 | | osgProducer::Viewer viewer(BuildConfig()); |
| 96 | | |
| 97 | | // set up the value with sensible default event handlers. |
| 98 | | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
| 99 | | |
| 100 | | // get details on keyboard and mouse bindings used by the viewer. |
| 101 | | viewer.getUsage(*arguments.getApplicationUsage()); |
| 102 | | |
| 103 | | // if user request help write it out to cout. |
| 104 | | if (arguments.read("-h") || arguments.read("--help")) |
| 105 | | { |
| 106 | | arguments.getApplicationUsage()->write(std::cout); |
| 107 | | return 1; |
| 108 | | } |
| 109 | | |
| 110 | | // any option left unread are converted into errors to write out later. |
| 111 | | arguments.reportRemainingOptionsAsUnrecognized(); |
| 112 | | |
| 113 | | // report any errors if they have occured when parsing the program aguments. |
| 114 | | if (arguments.errors()) |
| 115 | | { |
| 116 | | arguments.writeErrorMessages(std::cout); |
| 117 | | return 1; |
| 118 | | } |
| 119 | | |
| 120 | | if (arguments.argc()<=1) |
| 121 | | { |
| 122 | | arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); |
| 123 | | return 1; |
| 124 | | } |
| | 31 | // construct the viewer. |
| | 32 | osgViewer::Viewer viewer; |
| | 33 | |
| | 34 | // left window + left slave camera |
| | 35 | { |
| | 36 | osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; |
| | 37 | traits->x = 0; |
| | 38 | traits->y = 0; |
| | 39 | traits->width = 640; |
| | 40 | traits->height = 480; |
| | 41 | traits->windowDecoration = true; |
| | 42 | traits->doubleBuffer = true; |
| | 43 | traits->sharedContext = 0; |
| | 44 | |
| | 45 | osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); |
| | 46 | |
| | 47 | osg::ref_ptr<osg::Camera> camera = new osg::Camera; |
| | 48 | camera->setGraphicsContext(gc.get()); |
| | 49 | camera->setViewport(new osg::Viewport(0,0, traits->width, traits->height)); |
| | 50 | GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; |
| | 51 | camera->setDrawBuffer(buffer); |
| | 52 | camera->setReadBuffer(buffer); |
| | 53 | |
| | 54 | // add this slave camra to the viewer, with a shift left of the projection matrix |
| | 55 | viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,0.0,0.0), osg::Matrixd()); |
| | 56 | } |
| | 57 | |
| | 58 | // left window + left slave camera |
| | 59 | { |
| | 60 | osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; |
| | 61 | traits->x = 640; |
| | 62 | traits->y = 0; |
| | 63 | traits->width = 640; |
| | 64 | traits->height = 480; |
| | 65 | traits->windowDecoration = true; |
| | 66 | traits->doubleBuffer = true; |
| | 67 | traits->sharedContext = 0; |
| | 68 | |
| | 69 | osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); |
| | 70 | |
| | 71 | osg::ref_ptr<osg::Camera> camera = new osg::Camera; |
| | 72 | camera->setGraphicsContext(gc.get()); |
| | 73 | camera->setViewport(new osg::Viewport(0,0, traits->width, traits->height)); |
| | 74 | GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; |
| | 75 | camera->setDrawBuffer(buffer); |
| | 76 | camera->setReadBuffer(buffer); |
| | 77 | |
| | 78 | // add this slave camra to the viewer, with a shift right of the projection matrix |
| | 79 | viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,0.0,0.0), osg::Matrixd()); |
| | 80 | } |
| | 81 | |