Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

vrj::OsgApp Class Reference

OsgApp: Encapulates an open scene graph application. More...

#include <OsgApp.h>

Inheritance diagram for vrj::OsgApp:

Inheritance graph
[legend]
Collaboration diagram for vrj::OsgApp:

Collaboration graph
[legend]
List of all members.

Public Methods

 OsgApp (Kernel *kern)
 OsgApp ()
virtual ~OsgApp ()
virtual void initScene ()=0
 Initializes the scene. More...

virtual osg::Group * getScene ()=0
 Gets the root of the scene to render. More...

virtual void configSceneView (osgUtil::SceneView *newSceneViewer)
 Configures newly created scene viewers. More...

virtual void draw ()
 Function to draw the scene. More...

virtual void init ()
 Application initialization function. More...

virtual void contextInit ()
 Function that is called immediately after a new context is created. More...

virtual void contextClose ()
 Function that is called immediately before a context is closed. More...

virtual void contextPreDraw ()
 Function that is called upon entry into the context for a draw. More...

virtual void bufferPreDraw ()
 Function that is called upon entry into a buffer of a GL context. More...

virtual void pipePreDraw ()
 Function that is called at the beginning of the drawing of each pipe. More...


Protected Attributes

vrj::GlContextData< osgUtil::SceneView * > sceneViewer

Detailed Description

OsgApp: Encapulates an open scene graph application.

PURPOSE:

See also:
vrj::GlApp

Definition at line 61 of file OsgApp.h.


Constructor & Destructor Documentation

vrj::OsgApp::OsgApp Kernel   kern [inline]
 

Definition at line 64 of file OsgApp.h.

References vrj::GlApp::GlApp.

00064                         : GlApp(kern)
00065    {
00066       ;
00067    }

vrj::OsgApp::OsgApp   [inline]
 

Definition at line 69 of file OsgApp.h.

References vrj::GlApp::GlApp.

00069             : GlApp()
00070    {
00071       ;
00072    }

virtual vrj::OsgApp::~OsgApp   [inline, virtual]
 

Definition at line 74 of file OsgApp.h.

00075    {
00076       ;
00077    }


Member Function Documentation

virtual void vrj::OsgApp::initScene   [pure virtual]
 

Initializes the scene.

Called by init() to initialize the scene.

Referenced by init.

virtual osg::Group* vrj::OsgApp::getScene   [pure virtual]
 

Gets the root of the scene to render.

Called each frame to get the current scene to render.

Referenced by draw.

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.

Definition at line 97 of file OsgApp.h.

Referenced by contextInit.

00098    {
00099       newSceneViewer->setDefaults();
00100       newSceneViewer->setBackgroundColor(osg::Vec4(0.0f, 0.0f, 0.0f, 0.0f));
00101    }

void vrj::OsgApp::draw   [inline, virtual]
 

Function to draw the scene.

Override this function with the user draw routine.

Precondition:
OpenGL state has correct transformation and buffer selected.
Postcondition:
The current scene has been drawn.

Implements vrj::GlApp.

Definition at line 239 of file OsgApp.h.

References vrj::GlApp::getDrawManager, and getScene.

00240 {
00241    glPushAttrib(GL_ALL_ATTRIB_BITS);
00242    glPushAttrib(GL_TRANSFORM_BIT);
00243    glPushAttrib(GL_VIEWPORT_BIT);
00244 
00245    glMatrixMode(GL_MODELVIEW);
00246    glPushMatrix();
00247 
00248    glMatrixMode(GL_PROJECTION);
00249    glPushMatrix();
00250 
00251    glMatrixMode(GL_TEXTURE);
00252    glPushMatrix();
00253 
00254 
00255    osgUtil::SceneView* sv(NULL);
00256    sv = (*sceneViewer);    // Get context specific scene viewer
00257    vprASSERT( sv != NULL);
00258 
00259    GlDrawManager*    gl_manager;    
00260    gl_manager = GlDrawManager::instance();
00261 
00262    // Set the up the viewport (since OSG clears it out)
00263    float vp_ox, vp_oy, vp_sx, vp_sy;         // The float vrj sizes of the view ports
00264    unsigned w_ox, w_oy, w_width, w_height;   // Origin and size of the window
00265    gl_manager->currentUserData()->getViewport()->getOriginAndSize(vp_ox, vp_oy, vp_sx, vp_sy);
00266    gl_manager->currentUserData()->getGlWindow()->getOriginSize(w_ox, w_oy, w_width, w_height);
00267 
00268    // compute unsigned versions of the viewport info (for passing to glViewport)
00269    unsigned ll_x = unsigned(vp_ox*float(w_width));
00270    unsigned ll_y = unsigned(vp_oy*float(w_height));
00271    unsigned x_size = unsigned(vp_sx*float(w_width));
00272    unsigned y_size = unsigned(vp_sy*float(w_height));
00273 
00274    // Add the tree to the scene viewer and set properties
00275    sv->setSceneData(getScene());
00276    //sv->setCalcNearFar(false);
00277    sv->setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR);
00278    sv->setViewport(ll_x, ll_y, x_size, y_size);
00279 
00280    //Get the view matrix and the frustrum form the draw manager
00281    GlDrawManager* drawMan = dynamic_cast<GlDrawManager*>(this->getDrawManager());
00282    vprASSERT(drawMan != NULL);
00283    GlUserData* userData = drawMan->currentUserData();
00284 
00285    // Copy the matrix
00286    Projection* project = userData->getProjection();
00287    const float* vj_proj_view_mat = project->getViewMatrix().mData;
00288    osg::RefMatrix* osg_proj_xform_mat = new osg::RefMatrix;
00289    osg_proj_xform_mat->set( vj_proj_view_mat );
00290 
00291    //Get the frustrum
00292    Frustum frustum = project->getFrustum();
00293    sv->setProjectionMatrixAsFrustum(frustum[Frustum::VJ_LEFT],
00294                                     frustum[Frustum::VJ_RIGHT],
00295                                     frustum[Frustum::VJ_BOTTOM],
00296                                     frustum[Frustum::VJ_TOP],
00297                                     frustum[Frustum::VJ_NEAR],
00298                                     frustum[Frustum::VJ_FAR]);
00299 
00300    sv->setViewMatrix(*osg_proj_xform_mat);
00301 
00302    //Draw the scene
00303    sv->update();
00304    sv->cull();
00305    sv->draw();
00306 
00307    glMatrixMode(GL_TEXTURE);
00308    glPopMatrix();
00309 
00310    glMatrixMode(GL_PROJECTION);
00311    glPopMatrix();
00312 
00313    glMatrixMode(GL_MODELVIEW);
00314    glPopMatrix();
00315 
00316    glPopAttrib();
00317    glPopAttrib();
00318    glPopAttrib();
00319 }

virtual void vrj::OsgApp::init   [inline, virtual]
 

Application initialization function.

Execute any initialization needed before the API is started.

Note:
Derived classes MUST call base class version of this method.

Reimplemented from vrj::App.

Definition at line 114 of file OsgApp.h.

References initScene.

00115    {
00116       GlApp::init();
00117 
00118       //Create the scene
00119       this->initScene();
00120    }

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. i.e. Display lists, Texture objects, etc.

Precondition:
The ogl context has been set to the new context.
Postcondition:
Application has completed in initialization the user wishes.

Reimplemented from vrj::GlApp.

Definition at line 189 of file OsgApp.h.

References configSceneView.

00190 {
00191    unsigned int unique_context_id = GlDrawManager::instance()->getCurrentContext();
00192 
00193    // --- Create new context specific scene viewer -- //
00194    osgUtil::SceneView* new_sv = new osgUtil::SceneView;
00195    this->configSceneView(new_sv);            // Configure the new viewer
00196    new_sv->getState()->setContextID(unique_context_id);
00197 
00198    // This will eventually be changed to no light and all lighting will be handled
00199    // by the application.  For the time being it fixes the lighting inconsistanies
00200    // over multiple screens
00201    new_sv->setLightingMode(osgUtil::SceneView::SKY_LIGHT);
00202 
00203    (*sceneViewer) = new_sv;
00204 
00205    //Setup OpenGL light
00206    //This should actualy be done in the simulator code
00207    GLfloat light0_ambient[] = { 0.1f,  0.1f,  0.1f,  1.0f};
00208    GLfloat light0_diffuse[] = { 0.8f,  0.8f,  0.8f,  1.0f};
00209    GLfloat light0_specular[] = { 1.0f,  1.0f,  1.0f,  1.0f};
00210    GLfloat light0_position[] = {0.0f, 0.75f, 0.75f, 0.0f};
00211 
00212    GLfloat mat_ambient[] = { 0.7f, 0.7f,  0.7f,  1.0f};
00213    GLfloat mat_diffuse[] = { 1.0f,  0.5f,  0.8f,  1.0f};
00214    GLfloat mat_specular[] = { 1.0f,  1.0f,  1.0f,  1.0f};
00215    GLfloat mat_shininess[] = { 50.0f};
00216    //GLfloat mat_emission[] = { 1.0f,  1.0f,  1.0f,  1.0f};
00217    GLfloat no_mat[] = { 0.0f,  0.0f,  0.0f,  1.0f};
00218 
00219    glLightfv(GL_LIGHT0, GL_AMBIENT,  light0_ambient);
00220    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light0_diffuse);
00221    glLightfv(GL_LIGHT0, GL_SPECULAR,  light0_specular);
00222    glLightfv(GL_LIGHT0, GL_POSITION,  light0_position);
00223 
00224    glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient );
00225    glMaterialfv( GL_FRONT,  GL_DIFFUSE, mat_diffuse );
00226    glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular );
00227    glMaterialfv( GL_FRONT,  GL_SHININESS, mat_shininess );
00228    glMaterialfv( GL_FRONT,  GL_EMISSION, no_mat);
00229 
00230    glEnable(GL_DEPTH_TEST);
00231    glEnable(GL_NORMALIZE);
00232    glEnable(GL_LIGHTING);
00233    glEnable(GL_LIGHT0);
00234    glEnable(GL_COLOR_MATERIAL);
00235    glShadeModel(GL_SMOOTH);
00236 }

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 data structures.

Reimplemented from vrj::GlApp.

Definition at line 136 of file OsgApp.h.

00137    {
00138       ;
00139    }

virtual void vrj::OsgApp::contextPreDraw   [inline, virtual]
 

Function that is called upon entry into the context for a draw.

Precondition:
The ogl context has been set to the context for drawing.
Postcondition:
User application has executed any commands that need to only be executed once per context, per frame.
Note:
This function can be used for things that need to happen every frame, but only once per context.
Ex: Dynamically Create display lists

Reimplemented from vrj::GlApp.

Definition at line 151 of file OsgApp.h.

00152    {
00153       ;
00154    }

virtual void vrj::OsgApp::bufferPreDraw   [inline, virtual]
 

Function that is called upon entry into a buffer of a GL context.

Precondition:
The ogl context has been set to the context for drawing.
Postcondition:
User application has executed any commands that need to only be executed once per context, per buffer, per frame.
Note:
This function is designed to be used when you want to do something only once per buffer (ie.once for left buffer, once for right buffer).
Ex: glClear's need to be done in this method

Reimplemented from vrj::GlApp.

Definition at line 167 of file OsgApp.h.

00168    {
00169       ;
00170    }

virtual void vrj::OsgApp::pipePreDraw   [inline, virtual]
 

Function that is called at the beginning of the drawing of each pipe.

Precondition:
The library is preparing to render all windows on a given pipe.
Postcondition:
Any pre-pipe user calls have been done.
Note:
Currently the OGL context is not set when this function is called. This is a TEST function. USE AT YOUR OWN RISK!!!

Reimplemented from vrj::GlApp.

Definition at line 180 of file OsgApp.h.

00181    {
00182       ;
00183    }


Member Data Documentation

vrj::GlContextData< osgUtil::SceneView* > vrj::OsgApp::sceneViewer [protected]
 

Definition at line 186 of file OsgApp.h.


The documentation for this class was generated from the following file:
Generated on Sun May 2 15:11:13 2004 for VR Juggler by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002