| 28 | | rs = new Producer::RenderSurface; |
| 29 | | rs->setWindowRectangle(0,0,1,1); |
| 30 | | rs->useBorder(false); |
| 31 | | rs->useConfigEventThread(false); |
| 32 | | rs->realize(); |
| | 30 | osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; |
| | 31 | traits->x = 0; |
| | 32 | traits->y = 0; |
| | 33 | traits->width = 1; |
| | 34 | traits->height = 1; |
| | 35 | traits->windowDecoration = false; |
| | 36 | traits->doubleBuffer = false; |
| | 37 | traits->sharedContext = 0; |
| | 38 | traits->pbuffer = true; |
| | 39 | |
| | 40 | _gc = osg::GraphicsContext::createGraphicsContext(traits.get()); |
| | 41 | |
| | 42 | if (!_gc) |
| | 43 | { |
| | 44 | osg::notify(osg::NOTICE)<<"Failed to create pbuffer, failing back to normal graphics window."<<std::endl; |
| | 45 | |
| | 46 | traits->pbuffer = false; |
| | 47 | _gc = osg::GraphicsContext::createGraphicsContext(traits.get()); |
| | 48 | } |
| | 49 | |
| | 50 | if (_gc.valid()) |
| | 51 | |
| | 52 | |
| | 53 | { |
| | 54 | _gc->realize(); |
| | 55 | _gc->makeCurrent(); |
| | 56 | std::cout<<"Realized window"<<std::endl; |
| | 57 | } |
| 155 | | int main(int argc, char **argv) |
| 156 | | { |
| 157 | | // use an ArgumentParser object to manage the program arguments. |
| 158 | | osg::ArgumentParser arguments(&argc,argv); |
| 159 | | |
| 160 | | // set up the usage document, in case we need to print out how to use this program. |
| 161 | | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of node tracker."); |
| 162 | | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()); |
| 163 | | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
| 164 | | |
| 165 | | |
| | 178 | int main(int, char**) |
| | 179 | { |
| 167 | | osgProducer::Viewer viewer(arguments); |
| 168 | | |
| 169 | | // set up the value with sensible default event handlers. |
| 170 | | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
| 171 | | |
| 172 | | viewer.getCullSettings().setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); |
| 173 | | viewer.getCullSettings().setNearFarRatio(0.00001f); |
| 174 | | |
| 175 | | // get details on keyboard and mouse bindings used by the viewer. |
| 176 | | viewer.getUsage(*arguments.getApplicationUsage()); |
| 177 | | |
| 178 | | |
| 179 | | // if user request help write it out to cout. |
| 180 | | if (arguments.read("-h") || arguments.read("--help")) |
| 181 | | { |
| 182 | | arguments.getApplicationUsage()->write(std::cout); |
| 183 | | return 1; |
| 184 | | } |
| 185 | | |
| 186 | | // any option left unread are converted into errors to write out later. |
| 187 | | arguments.reportRemainingOptionsAsUnrecognized(); |
| 188 | | |
| 189 | | // report any errors if they have occured when parsing the program aguments. |
| 190 | | if (arguments.errors()) |
| 191 | | { |
| 192 | | arguments.writeErrorMessages(std::cout); |
| 193 | | return 1; |
| 194 | | } |
| | 181 | osgViewer::Viewer viewer; |
| | 182 | |
| | 183 | viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); |
| | 184 | viewer.getCamera()->setNearFarRatio(0.00001f); |
| 210 | | |
| 211 | | |
| 212 | | // create the windows and run the threads. |
| 213 | | viewer.realize(); |
| 214 | | |
| 215 | | while( !viewer.done() ) |
| 216 | | { |
| 217 | | // wait for all cull and draw threads to complete. |
| 218 | | viewer.sync(); |
| 219 | | |
| 220 | | // update the scene by traversing it with the the update visitor which will |
| 221 | | // call all node update callbacks and animations. |
| 222 | | viewer.update(); |
| 223 | | |
| 224 | | // fire off the cull and draw traversals of the scene. |
| 225 | | viewer.frame(); |
| 226 | | |
| 227 | | } |
| 228 | | |
| 229 | | // wait for all cull and draw threads to complete. |
| 230 | | viewer.sync(); |
| 231 | | |
| 232 | | // run a clean up frame to delete all OpenGL objects. |
| 233 | | viewer.cleanup_frame(); |
| 234 | | |
| 235 | | // wait for all the clean up frame to complete. |
| 236 | | viewer.sync(); |
| 237 | | |
| 238 | | return 0; |
| | 200 | |
| | 201 | viewer.setCameraManipulator(new osgGA::TerrainManipulator); |
| | 202 | |
| | 203 | return viewer.run(); |