#include <vrj/Draw/OSG/OsgApp.h>
Inheritance diagram for vrj::OsgApp:


Public Member Functions | |
| OsgApp (Kernel *kern=NULL) | |
| virtual | ~OsgApp () |
| virtual void | initScene ()=0 |
| Initializes the scene. | |
| virtual osg::Group * | getScene ()=0 |
| Gets the root of the scene to render. | |
| virtual void | configSceneView (osgUtil::SceneView *newSceneViewer) |
| Configures newly created scene viewers. | |
| virtual void | latePreFrame () |
| Function called after preFrame() and application-specific data synchronization (in a cluster configuration) but before the start of a new frame. | |
| virtual void | draw () |
| Function to set up and render the scene using OSG. | |
| virtual void | init () |
| Application initialization function. | |
| void | contextInit () |
| Function that is called immediately after a new context is created. | |
| virtual void | contextClose () |
| Function that is called immediately before a context is closed. | |
| virtual void | contextPreDraw () |
| Function that is called upon entry into the context before rendering. | |
| virtual void | bufferPreDraw () |
| Function that is called once for each frame buffer of an OpenGL context. | |
| virtual void | pipePreDraw () |
| Function that is called at the beginning of the drawing of each pipe. | |
Protected Member Functions | |
| void | update () |
| Performs the update stage on the scene graph. | |
Protected Attributes | |
| vrj::GlContextData< osg::ref_ptr< osgUtil::SceneView > > | sceneViewer |
This defines the base class from which OSG-based application classes should be derived. It makes use of the OpenGL Draw Manager.
Definition at line 68 of file OsgApp.h.
| vrj::OsgApp::OsgApp | ( | Kernel * | kern = NULL |
) | [inline] |
| virtual vrj::OsgApp::~OsgApp | ( | ) | [inline, virtual] |
| virtual void vrj::OsgApp::initScene | ( | ) | [pure virtual] |
| virtual osg::Group* vrj::OsgApp::getScene | ( | ) | [pure virtual] |
| virtual void vrj::OsgApp::configSceneView | ( | osgUtil::SceneView * | newSceneViewer | ) | [inline, virtual] |
Configures newly created scene viewers.
This is called immediately after a new scene viewer is created for a context. This is the place to configure application background colors and other viewer-specific information.
newSceneViewer is initialized. Definition at line 103 of file OsgApp.h.
Referenced by contextInit().
00104 { 00105 newSceneViewer->setDefaults(); 00106 newSceneViewer->init(); 00107 newSceneViewer->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f, 0.0f)); 00108 00109 // Needed for stereo to work. 00110 newSceneViewer->setDrawBufferValue(GL_NONE); 00111 }
| virtual void vrj::OsgApp::latePreFrame | ( | ) | [inline, virtual] |
Function called after preFrame() and application-specific data synchronization (in a cluster configuration) but before the start of a new frame.
If this method is overridden, it must be called as the last thing done by the overriding version. This calls update(), which is used to update this application object's scene graph.
Reimplemented from vrj::App.
Definition at line 127 of file OsgApp.h.
References update().
00128 { 00129 update(); 00130 }
| void vrj::OsgApp::draw | ( | ) | [inline, virtual] |
Function to set up and render the scene using OSG.
Override this method with great care. All the logic to handle multi-pipe rendering and other VR Juggler features happens here.
< The openGL manager that we are rendering for.
Implements vrj::GlApp.
Definition at line 333 of file OsgApp.h.
References vrj::GlDrawManager::currentUserData(), vrj::GlApp::getDrawManager(), vrj::Projection::getFrustum(), vrj::GlUserData::getGlWindow(), vrj::Viewport::getOriginAndSize(), vrj::GlWindow::getOriginSize(), vrj::GlUserData::getProjection(), getScene(), vrj::Projection::getViewMatrix(), vrj::GlUserData::getViewport(), vrj::Frustum::VJ_BOTTOM, vrj::Frustum::VJ_FAR, vrj::Frustum::VJ_LEFT, vrj::Frustum::VJ_NEAR, vrj::Frustum::VJ_RIGHT, and vrj::Frustum::VJ_TOP.
00334 { 00335 glClear(GL_DEPTH_BUFFER_BIT); 00336 00337 // Users have reported problems with OpenGL reporting stack underflow 00338 // problems when the texture attribute bit is pushed here, so we push all 00339 // attributes *except* GL_TEXTURE_BIT. 00340 glPushAttrib(GL_ALL_ATTRIB_BITS & ~GL_TEXTURE_BIT); 00341 glPushAttrib(GL_TRANSFORM_BIT); 00342 glPushAttrib(GL_VIEWPORT_BIT); 00343 00344 glMatrixMode(GL_MODELVIEW); 00345 glPushMatrix(); 00346 00347 glMatrixMode(GL_PROJECTION); 00348 glPushMatrix(); 00349 00350 glMatrixMode(GL_TEXTURE); 00351 glPushMatrix(); 00352 00353 00354 osg::ref_ptr<osgUtil::SceneView> sv; 00355 sv = (*sceneViewer); // Get context specific scene viewer 00356 vprASSERT(sv.get() != NULL); 00357 00358 // Set the timing information in the scene view. 00359 sv->setFrameStamp(mFrameStamp.get()); 00360 00361 GlDrawManager* gl_manager; 00362 gl_manager = GlDrawManager::instance(); 00363 00364 // Set the up the viewport (since OSG clears it out) 00365 float vp_ox, vp_oy, vp_sx, vp_sy; // The float vrj sizes of the view ports 00366 int w_ox, w_oy, w_width, w_height; // Origin and size of the window 00367 gl_manager->currentUserData()->getViewport()->getOriginAndSize(vp_ox, vp_oy, vp_sx, vp_sy); 00368 gl_manager->currentUserData()->getGlWindow()->getOriginSize(w_ox, w_oy, w_width, w_height); 00369 00370 // compute unsigned versions of the viewport info (for passing to glViewport) 00371 unsigned ll_x = unsigned(vp_ox*float(w_width)); 00372 unsigned ll_y = unsigned(vp_oy*float(w_height)); 00373 unsigned x_size = unsigned(vp_sx*float(w_width)); 00374 unsigned y_size = unsigned(vp_sy*float(w_height)); 00375 00376 // Add the tree to the scene viewer and set properties 00377 sv->setSceneData(getScene()); 00378 //sv->setCalcNearFar(false); 00379 sv->setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR); 00380 sv->setViewport(ll_x, ll_y, x_size, y_size); 00381 00382 //Get the view matrix and the frustrum form the draw manager 00383 GlDrawManager* drawMan = dynamic_cast<GlDrawManager*>(this->getDrawManager()); 00384 vprASSERT(drawMan != NULL); 00385 GlUserData* userData = drawMan->currentUserData(); 00386 00387 //Get the frustrum 00388 Projection* project = userData->getProjection(); 00389 Frustum frustum = project->getFrustum(); 00390 sv->setProjectionMatrixAsFrustum(frustum[Frustum::VJ_LEFT], 00391 frustum[Frustum::VJ_RIGHT], 00392 frustum[Frustum::VJ_BOTTOM], 00393 frustum[Frustum::VJ_TOP], 00394 frustum[Frustum::VJ_NEAR], 00395 frustum[Frustum::VJ_FAR]); 00396 00397 // Copy the view matrix 00398 sv->setViewMatrix(osg::Matrix(project->getViewMatrix().mData)); 00399 00400 //Draw the scene 00401 // NOTE: It is not safe to call osgUtil::SceneView::update() here; it 00402 // should only be called by a single thread. The equivalent of calling 00403 // osgUtil::SceneView::update() is in vrj::OsgApp::update(). 00404 sv->cull(); 00405 sv->draw(); 00406 00407 glMatrixMode(GL_TEXTURE); 00408 glPopMatrix(); 00409 00410 glMatrixMode(GL_PROJECTION); 00411 glPopMatrix(); 00412 00413 glMatrixMode(GL_MODELVIEW); 00414 glPopMatrix(); 00415 00416 glPopAttrib(); 00417 glPopAttrib(); 00418 glPopAttrib(); 00419 }
| virtual void vrj::OsgApp::init | ( | ) | [inline, virtual] |
Application initialization function.
Execute any initialization needed before the graphics API is started. If this method is overridden, it must be called by the overriding version. This calls initScene(), which is used to set up this application object's scene graph.
Reimplemented from vrj::App.
Definition at line 151 of file OsgApp.h.
References vrj::App::init(), and initScene().
00152 { 00153 mUpdateVisitor = new osgUtil::UpdateVisitor(); 00154 mFrameStamp = new osg::FrameStamp(); 00155 mUpdateVisitor->setFrameStamp(mFrameStamp.get()); 00156 00157 GlApp::init(); 00158 00159 mHead.init("VJHead"); 00160 00161 //Create the scene 00162 this->initScene(); 00163 }
| void vrj::OsgApp::contextInit | ( | ) | [inline, virtual] |
Function that is called immediately after a new context is created.
Use this function to create context-specific data structures such as display lists and texture objects that are known to be required when the context is created.
Reimplemented from vrj::GlApp.
Definition at line 283 of file OsgApp.h.
References configSceneView().
00284 { 00285 unsigned int unique_context_id = GlDrawManager::instance()->getCurrentContext(); 00286 00287 // --- Create new context specific scene viewer -- // 00288 osg::ref_ptr<osgUtil::SceneView> new_sv(new osgUtil::SceneView); 00289 this->configSceneView(new_sv.get()); // Configure the new viewer 00290 new_sv->getState()->setContextID(unique_context_id); 00291 00292 // This will eventually be changed to no light and all lighting will be handled 00293 // by the application. For the time being it fixes the lighting inconsistanies 00294 // over multiple screens 00295 new_sv->setLightingMode(osgUtil::SceneView::SKY_LIGHT); 00296 00297 (*sceneViewer) = new_sv; 00298 00299 //Setup OpenGL light 00300 //This should actualy be done in the simulator code 00301 GLfloat light0_ambient[] = { 0.1f, 0.1f, 0.1f, 1.0f}; 00302 GLfloat light0_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f}; 00303 GLfloat light0_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f}; 00304 GLfloat light0_position[] = {0.0f, 0.75f, 0.75f, 0.0f}; 00305 00306 GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f}; 00307 GLfloat mat_diffuse[] = { 1.0f, 0.5f, 0.8f, 1.0f}; 00308 GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f}; 00309 GLfloat mat_shininess[] = { 50.0f}; 00310 //GLfloat mat_emission[] = { 1.0f, 1.0f, 1.0f, 1.0f}; 00311 GLfloat no_mat[] = { 0.0f, 0.0f, 0.0f, 1.0f}; 00312 00313 glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); 00314 glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); 00315 glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular); 00316 glLightfv(GL_LIGHT0, GL_POSITION, light0_position); 00317 00318 glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient ); 00319 glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse ); 00320 glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular ); 00321 glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess ); 00322 glMaterialfv( GL_FRONT, GL_EMISSION, no_mat); 00323 00324 glEnable(GL_DEPTH_TEST); 00325 glEnable(GL_NORMALIZE); 00326 glEnable(GL_LIGHTING); 00327 glEnable(GL_LIGHT0); 00328 glEnable(GL_COLOR_MATERIAL); 00329 glShadeModel(GL_SMOOTH); 00330 }
| virtual void vrj::OsgApp::contextClose | ( | ) | [inline, virtual] |
Function that is called immediately before a context is closed.
Use the function to clean up any context-specific data structures.
Reimplemented from vrj::GlApp.
Definition at line 180 of file OsgApp.h.
| virtual void vrj::OsgApp::contextPreDraw | ( | ) | [inline, virtual] |
Function that is called upon entry into the context before rendering.
This can be used to allocate context-specific data dynamically.
Reimplemented from vrj::GlApp.
Definition at line 196 of file OsgApp.h.
| virtual void vrj::OsgApp::bufferPreDraw | ( | ) | [inline, virtual] |
Function that is called once for each frame buffer of an OpenGL context.
This function is executed after contextInit() (if needed) but before contextPreDraw(). It is called once per frame buffer (see note).
Reimplemented from vrj::GlApp.
Definition at line 216 of file OsgApp.h.
| virtual void vrj::OsgApp::pipePreDraw | ( | ) | [inline, virtual] |
Function that is called at the beginning of the drawing of each pipe.
Reimplemented from vrj::GlApp.
Definition at line 230 of file OsgApp.h.
| void vrj::OsgApp::update | ( | ) | [inline, protected] |
Performs the update stage on the scene graph.
This function should be called as the last thing that happens in latePreFrame(). If latePreFrame() is not overridden, then this happens automatically. Otherwise be sure to call vrj::OsgApp::latePreFrame() as the last thing in application object's override of latePreFrame().
Definition at line 253 of file OsgApp.h.
References getScene().
Referenced by latePreFrame().
00254 { 00255 ++mFrameNumber; 00256 00257 // Update the frame stamp with information from this frame. 00258 mFrameStamp->setFrameNumber(mFrameNumber); 00259 mFrameStamp->setReferenceTime(mHead->getTimeStamp().secd()); 00260 00261 // Set up the time and frame number so time-dependent things (animations, 00262 // particle system) function correctly. 00263 // XXX: This may not be necessary. 00264 mUpdateVisitor->setTraversalNumber(mFrameNumber); 00265 00266 // Update the scene by traversing it with the the update visitor which 00267 // will call all node update callbacks and animations. This is 00268 // equivalent to calling osgUtil::SceneView::update() but does not 00269 // require access to the context-specific osgUtil::SceneView instance. 00270 getScene()->accept(*mUpdateVisitor); 00271 }
vrj::GlContextData< osg::ref_ptr<osgUtil::SceneView> > vrj::OsgApp::sceneViewer [protected] |
1.5.1