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

vrj::GlWindow Class Reference

Represent cross-platform interface to OpenGL windows. More...

#include <GlWindow.h>

Inheritance diagram for vrj::GlWindow:

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

Collaboration graph
[legend]
List of all members.

Public Methods

 GlWindow ()
virtual ~GlWindow ()
virtual int open ()
 Opens the OpenGL window. More...

virtual int close ()
 Closes the OpenGL window. More...

virtual bool makeCurrent ()
 Sets the current OpenGL context to this window. More...

virtual void configWindow (vrj::Display *displayWindow)
 Configures the window. More...

virtual void swapBuffers ()
 Performs an OpenGL swap buffers command. More...

virtual void checkEvents ()
 Handles any window events that have occured. More...

virtual void finishSetup ()
 Complete any setup that is needed after open. More...

void setProjection (vrj::Projection *proj)
 Sets the projection matrix for this window to proj. More...

void setLeftEyeProjection ()
 Sets the projection matrix for this window to draw the left eye frame. More...

void setRightEyeProjection ()
 Sets the projection matrix for this window to draw the right eye frame. More...

void setViewBuffer (vrj::Viewport::View view)
 Sets the view buffer for the window (issues glDrawBuffer command). More...

void setViewport (float xo, float yo, float xSize, float ySize)
 Sets the viewport in the GL window based on float values. More...

void updateViewport ()
 Updates the viewport and does any viewport cleaning. More...

bool hasDirtyContext () const
 Is the context dirty? More...

void setDirtyContext (bool val=true)
 Sets the dirty bit for the context. More...

bool hasDirtyViewport () const
 Is the viewport dirty? More...

void setDirtyViewport (bool val=true)
 Sets the dirty bit for the viewport. More...

bool isOpen () const
 Queries wether the window is open. More...

bool isStereo () const
 Queries wether the window is in stereo. More...

bool isEventSource () const
vrj::DisplaygetDisplay ()
int getId () const
void updateOriginSize (int o_x, int o_y, int width, int height)
void getOriginSize (unsigned &o_x, unsigned &o_y, unsigned &width, unsigned &height) const
 Return the origin and size of the current window. More...

virtual bool createHardwareSwapGroup (std::vector< GlWindow * > wins)

Protected Attributes

vrj::DisplaymVrjDisplay
bool mDirtyContext
 The context is dirty. More...

bool mDirtyViewport
bool in_stereo
 Whether the display is actually in stereo if we wanted a stereo display but couldn't open it we fall back to mono, and this will be false. More...

bool border
 Do we have a border? More...

bool window_is_open
 Is the window open? More...

int window_width
int window_height
int origin_x
int origin_y
 lower-left corner of window. More...

int mWindowId
 A unique window id to identify us. More...

bool mAreEventSource
 Should we act as an event source too? More...


Friends

std::ostream & operator<< (std::ostream &out, GlWindow &win)

Detailed Description

Represent cross-platform interface to OpenGL windows.

This interface is used by the OpenGL draw manager in order to keep all platform specific code in this one class.

Definition at line 68 of file GlWindow.h.


Constructor & Destructor Documentation

vrj::GlWindow::GlWindow   [inline]
 

Definition at line 71 of file GlWindow.h.

00072       : mVrjDisplay(NULL)
00073       , mDirtyContext(true)
00074       , mDirtyViewport(true)
00075       , in_stereo(false)
00076       , border(false)
00077       , window_is_open(false)
00078       , window_width(0)
00079       , window_height(0)
00080       , origin_x(0)
00081       , origin_y(0)
00082       // XXX: Sync problem on window id value assignment
00083       , mWindowId(getNextWindowId())
00084       , mAreEventSource(false)
00085    {
00086       // The context is always dirty when the window is first created
00087    }

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

Definition at line 90 of file GlWindow.h.

00091    {;}


Member Function Documentation

virtual int vrj::GlWindow::open   [inline, virtual]
 

Opens the OpenGL window.

Precondition:
this has been configured.

Reimplemented in vrj::GlWindowOSX.

Definition at line 99 of file GlWindow.h.

00100    {
00101       return 1;
00102    }

virtual int vrj::GlWindow::close   [inline, virtual]
 

Closes the OpenGL window.

Reimplemented in vrj::GlWindowOSX.

Definition at line 105 of file GlWindow.h.

00106    {
00107       return 1;
00108    }

virtual bool vrj::GlWindow::makeCurrent   [inline, virtual]
 

Sets the current OpenGL context to this window.

Postcondition:
this.context is active context.

Reimplemented in vrj::GlWindowOSX.

Definition at line 114 of file GlWindow.h.

00115    {
00116       return false;
00117    }

void vrj::GlWindow::configWindow vrj::Display   displayWindow [virtual]
 

Configures the window.

Postcondition:
this is configured based on the data in display.

Reimplemented in vrj::GlWindowOSX.

Definition at line 83 of file GlWindow.cpp.

References border, vrj::Display::getOriginAndSize, mVrjDisplay, origin_x, origin_y, vrj::Display::shouldDrawBorder, window_height, and window_width.

Referenced by vrj::GlWindowXWin::configWindow, and vrj::GlWindowWin32::configWindow.

00084 {
00085    vprASSERT(displayWindow != NULL);      // We can't config to a NULL display
00086    mVrjDisplay = displayWindow;
00087    mVrjDisplay->getOriginAndSize(origin_x, origin_y, window_width, window_height);
00088    border = mVrjDisplay->shouldDrawBorder();
00089 
00091 }

virtual void vrj::GlWindow::swapBuffers   [inline, virtual]
 

Performs an OpenGL swap buffers command.

Postcondition:
A glFlush must be called explicitly by the implementation or explicitly by the functions used in the implementation.

Reimplemented in vrj::GlWindowOSX.

Definition at line 130 of file GlWindow.h.

00131    {;}

virtual void vrj::GlWindow::checkEvents   [inline, virtual]
 

Handles any window events that have occured.

Reimplemented in vrj::GlWindowWin32.

Definition at line 136 of file GlWindow.h.

00137    {;}

void vrj::GlWindow::finishSetup   [virtual]
 

Complete any setup that is needed after open.

Precondition:
Window is open

Definition at line 96 of file GlWindow.cpp.

References vrj::Display::getViewport, mAreEventSource, mVrjDisplay, vrjDBG_DRAW_MGR, and window_is_open.

00097 {
00098    vprASSERT(window_is_open && "Pre-condition of being open failed");
00099 
00100    // --- Setup any attached simulator that is needed --- //
00101    Viewport* viewport = NULL;
00102    SimViewport* sim_vp = NULL;
00103    unsigned num_vps = mVrjDisplay->getNumViewports();
00104    for(unsigned vp_num=0; vp_num < num_vps; vp_num++)
00105    {
00106       viewport = mVrjDisplay->getViewport(vp_num);
00107       if(viewport->isSimulator())
00108       {
00109          sim_vp = dynamic_cast<SimViewport*>(viewport);
00110          vprASSERT(NULL != sim_vp && "isSimulator lied");
00111 
00112          DrawSimInterface* draw_sim = sim_vp->getDrawSimInterface();
00113          GlSimInterface* gl_draw_sim = dynamic_cast<GlSimInterface*>(draw_sim);
00114          if(NULL != gl_draw_sim)
00115          {
00116             // Setup the simulator
00117             // - Get the event window device
00118             // - Register a proxy that we will use
00119             // - Make device interface for that proxy
00120             // - Intialize the simulator
00121             vprASSERT(mAreEventSource && "Tried to use simulator with a non-keyboard enabled GL window. Bad programmer.");
00122             gadget::EventWindow* kb_dev = dynamic_cast<gadget::EventWindow*>(this);
00123             gadget::Input* input_dev = dynamic_cast<gadget::Input*>(this);
00124             vprASSERT((kb_dev != NULL) && (input_dev != NULL) && "Failed to cast glWindow impl to a gadget::EventWindow");
00125             std::string kb_dev_name = input_dev->getInstanceName();
00126             vprASSERT( gadget::InputManager::instance()->getDevice(kb_dev_name) != NULL);
00127 
00128             gadget::EventWindowProxy* kb_proxy = new gadget::EventWindowProxy;
00129             kb_proxy->set(kb_dev_name, kb_dev);
00130 
00131             std::string kb_proxy_name("GlWin-Sim-EventWindow-");
00132             kb_proxy_name += kb_dev_name;
00133             kb_proxy_name += std::string("-Proxy");
00134             kb_proxy->setName(kb_proxy_name);
00135             bool add_success = gadget::InputManager::instance()->addProxy(kb_proxy);
00136 
00137             if ( ! add_success )
00138             {
00139                vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL)
00140                   << clrOutBOLD(clrYELLOW, "WARNING")
00141                   << ": [vrj::GlWindow::finishSetup()] Failed to add the "
00142                   << "event window proxy.  Check for a unique name."
00143                   << std::endl << vprDEBUG_FLUSH;
00144                vprASSERT(false && "Failed to add sim wind kb proxy: Check for unique name");
00145             }
00146             else
00147             {
00148                gadget::EventWindowInterface kb_interface;
00149                kb_interface.setProxy(kb_proxy);
00150                gl_draw_sim->setEventWindow(kb_interface); // Initialize the simulator
00151             }
00152          }
00153          else
00154          {
00155             vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CRITICAL_LVL)
00156                << clrOutBOLD(clrRED, "ERROR")
00157                << ": [vrj::GlWindow::finishSetup()] You configured a simulator "
00158                << "viewport, but I cannot find a DrawSimInterface for it.\n"
00159                << vprDEBUG_FLUSH;
00160             vprDEBUG_CONT(vrjDBG_DRAW_MGR, vprDBG_CRITICAL_LVL)
00161                << "Check your configuration for missing information.\n"
00162                << vprDEBUG_FLUSH;
00163             vprASSERT(false && "You configured a simulator viewport, but I cannot find a DrawSimInterface for it");
00164          }
00165       }
00166    }
00167 
00168 }

void vrj::GlWindow::setProjection vrj::Projection   proj
 

Sets the projection matrix for this window to proj.

Definition at line 202 of file GlWindow.cpp.

References vrj::Frustum::frust, vrj::Projection::getFrustum, vrj::Projection::getViewMatrix, vrjDBG_DRAW_MGR, and window_is_open.

00203 {
00204    if (!window_is_open)
00205       return;
00206 
00207    const float* frust = proj->getFrustum().frust;
00208 
00209    vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HEX_LVL)  << "---- Frustum ----\n"
00210                << proj->getFrustum().frust << std::endl
00211                << vprDEBUG_FLUSH;
00212 
00213    // --- Set up the projection --- //
00214    glMatrixMode(GL_PROJECTION);
00215    {
00216       glLoadIdentity();             // Load identity matrix
00217       glFrustum(frust[Frustum::VJ_LEFT],frust[Frustum::VJ_RIGHT],
00218                  frust[Frustum::VJ_BOTTOM],frust[Frustum::VJ_TOP],
00219                  frust[Frustum::VJ_NEAR],frust[Frustum::VJ_FAR]);
00220 #ifdef USE_PROJECTION_MATRIX
00221          // Set camera rotation and position
00222       glMultMatrixf(proj->getViewMatrix().mData);
00223 #endif
00224    }
00225    glMatrixMode(GL_MODELVIEW);
00226 #ifndef USE_PROJECTION_MATRIX
00227       // Set camera rotation and position
00228    glLoadIdentity();
00229    glMultMatrixf(proj->getViewMat().mData);
00230 #endif
00231 }

void vrj::GlWindow::setLeftEyeProjection  
 

Sets the projection matrix for this window to draw the left eye frame.

If the window is in stereo, it changes to the left buffer.

void vrj::GlWindow::setRightEyeProjection  
 

Sets the projection matrix for this window to draw the right eye frame.

If the window is in stereo, it changes to the right buffer.

void vrj::GlWindow::setViewBuffer vrj::Viewport::View    view
 

Sets the view buffer for the window (issues glDrawBuffer command).

Definition at line 192 of file GlWindow.cpp.

References isStereo, and vrj::Viewport::View.

00193 {
00194    if(!isStereo())
00195       glDrawBuffer(GL_BACK);
00196    else if(Viewport::LEFT_EYE == view)
00197       glDrawBuffer(GL_BACK_LEFT);
00198    else if(Viewport::RIGHT_EYE == view)
00199       glDrawBuffer(GL_BACK_RIGHT);
00200 }

void vrj::GlWindow::setViewport float    xo,
float    yo,
float    xSize,
float    ySize
 

Sets the viewport in the GL window based on float values.

Parameters:
xo  X-coordinate for the viewport origin.
yo  Y-coordinate for the viewport origin.
xSize  Width of the viewport.
ySize  Height of the viewport.
Note:
The xo,yo values must be in the range [0.0,1.0] where lowerleft is 0,0 and upper right is 1,1.

Definition at line 178 of file GlWindow.cpp.

References window_height, and window_width.

00179 {
00180    vprASSERT( ((xo+xSize) <= 1.0f) && "X viewport sizes are out of range");
00181    vprASSERT( ((yo+ySize) <= 1.0f) && "Y viewport sizes are out of range");
00182 
00183    unsigned ll_x = unsigned(xo*float(window_width));
00184    unsigned ll_y = unsigned(yo*float(window_height));
00185    unsigned x_size = unsigned(xSize*float(window_width));
00186    unsigned y_size = unsigned(ySize*float(window_height));
00187 
00188    glViewport(ll_x, ll_y, x_size, y_size);
00189 }

void vrj::GlWindow::updateViewport  
 

Updates the viewport and does any viewport cleaning.

Definition at line 172 of file GlWindow.cpp.

References setDirtyViewport, window_height, and window_width.

00173 {
00174    glViewport(0,0, window_width, window_height);
00175    setDirtyViewport(false);
00176 }

bool vrj::GlWindow::hasDirtyContext   const [inline]
 

Is the context dirty?

Definition at line 180 of file GlWindow.h.

00181    {
00182       return mDirtyContext;
00183    }

void vrj::GlWindow::setDirtyContext bool    val = true [inline]
 

Sets the dirty bit for the context.

Definition at line 186 of file GlWindow.h.

00187    {
00188       mDirtyContext = val;
00189    }

bool vrj::GlWindow::hasDirtyViewport   const [inline]
 

Is the viewport dirty?

Definition at line 192 of file GlWindow.h.

00193    {
00194       return mDirtyViewport;
00195    }

void vrj::GlWindow::setDirtyViewport bool    val = true [inline]
 

Sets the dirty bit for the viewport.

Definition at line 198 of file GlWindow.h.

Referenced by vrj::GlWindowXWin::processEvent, and updateViewport.

00199    {
00200       mDirtyViewport = val;
00201    }

bool vrj::GlWindow::isOpen   const [inline]
 

Queries wether the window is open.

Returns:
true if window is open.

Definition at line 207 of file GlWindow.h.

00208    {
00209       return window_is_open;
00210    }

bool vrj::GlWindow::isStereo   const [inline]
 

Queries wether the window is in stereo.

Returns:
true if window is in stereo.

Definition at line 216 of file GlWindow.h.

Referenced by setViewBuffer.

00217    {
00218       return in_stereo;
00219    }

bool vrj::GlWindow::isEventSource   const [inline]
 

Definition at line 221 of file GlWindow.h.

00222    {
00223       return mAreEventSource;
00224    }

vrj::Display* vrj::GlWindow::getDisplay   [inline]
 

Definition at line 226 of file GlWindow.h.

00227    {
00228       return mVrjDisplay;
00229    }

int vrj::GlWindow::getId   const [inline]
 

Returns:
A unique window id.

Definition at line 234 of file GlWindow.h.

00235    {
00236       return mWindowId;
00237    }

void vrj::GlWindow::updateOriginSize int    o_x,
int    o_y,
int    width,
int    height
[inline]
 

Definition at line 241 of file GlWindow.h.

Referenced by vrj::GlWindowXWin::processEvent.

00242    {
00243       origin_x = o_x; origin_y = o_y;
00244       window_width = width; window_height = height;
00245 
00246       // Update the display configuration
00247       mVrjDisplay->setOriginAndSize(o_x, o_y, width, height);
00248    }

void vrj::GlWindow::getOriginSize unsigned &    o_x,
unsigned &    o_y,
unsigned &    width,
unsigned &    height
const [inline]
 

Return the origin and size of the current window.

Definition at line 251 of file GlWindow.h.

00253    {
00254       o_x = origin_x;
00255       o_y = origin_y;
00256       width = window_width;
00257       height = window_height;
00258    }

virtual bool vrj::GlWindow::createHardwareSwapGroup std::vector< GlWindow * >    wins [inline, virtual]
 

Reimplemented in vrj::GlWindowOSX.

Definition at line 263 of file GlWindow.h.

00264    {
00265       boost::ignore_unused_variable_warning(wins);
00266       vprDEBUG(vprDBG_ALL,vprDBG_WARNING_LVL)
00267          << "WARNING: hardware swap not supported.\n" << vprDEBUG_FLUSH;
00268       return false;
00269    }


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &    out,
GlWindow &    win
[friend]
 

Definition at line 240 of file GlWindow.cpp.

00241 {
00242    vprASSERT(win.mVrjDisplay != NULL);
00243 
00244    //out << "-------- GlWindow --------" << endl;
00245    out << "Open: " << (win.window_is_open ? "Yes" : "No") << std::endl;
00246    out << "Stereo: " << (win.in_stereo ? "Yes" : "No") << std::endl;
00247    out << "Display Info:\n" << *(win.mVrjDisplay) << std::endl;
00248    return out;
00249 }


Member Data Documentation

vrj::Display* vrj::GlWindow::mVrjDisplay [protected]
 

Definition at line 275 of file GlWindow.h.

Referenced by configWindow, finishSetup, vrj::GlWindowXWin::getGlxVisInfo, and vrj::GlWindowWin32::setPixelFormat.

bool vrj::GlWindow::mDirtyContext [protected]
 

The context is dirty.

We need to (re)initialize it next draw

Definition at line 277 of file GlWindow.h.

bool vrj::GlWindow::mDirtyViewport [protected]
 

Definition at line 278 of file GlWindow.h.

bool vrj::GlWindow::in_stereo [protected]
 

Whether the display is actually in stereo if we wanted a stereo display but couldn't open it we fall back to mono, and this will be false.

Definition at line 284 of file GlWindow.h.

Referenced by vrj::GlWindowXWin::getGlxVisInfo, and vrj::GlWindowWin32::setPixelFormat.

bool vrj::GlWindow::border [protected]
 

Do we have a border?

Definition at line 286 of file GlWindow.h.

Referenced by configWindow, and vrj::GlWindowXWin::open.

bool vrj::GlWindow::window_is_open [protected]
 

Is the window open?

Definition at line 287 of file GlWindow.h.

Referenced by vrj::GlWindowXWin::close, vrj::GlWindowWin32::close, finishSetup, vrj::GlWindowXWin::GlWindowXWin, vrj::GlWindowXWin::makeCurrent, vrj::GlWindowXWin::open, vrj::GlWindowWin32::open, vrj::GlWindowOSX::open, and setProjection.

int vrj::GlWindow::window_width [protected]
 

Definition at line 288 of file GlWindow.h.

Referenced by configWindow, vrj::GlWindowXWin::GlWindowXWin, vrj::GlWindowXWin::open, vrj::GlWindowWin32::open, vrj::GlWindowOSX::open, setViewport, vrj::GlWindowWin32::sizeChanged, and updateViewport.

int vrj::GlWindow::window_height [protected]
 

Definition at line 288 of file GlWindow.h.

Referenced by configWindow, vrj::GlWindowXWin::GlWindowXWin, vrj::GlWindowXWin::open, vrj::GlWindowWin32::open, vrj::GlWindowOSX::open, setViewport, vrj::GlWindowWin32::sizeChanged, and updateViewport.

int vrj::GlWindow::origin_x [protected]
 

Definition at line 289 of file GlWindow.h.

Referenced by configWindow, vrj::GlWindowXWin::open, vrj::GlWindowWin32::open, vrj::GlWindowOSX::open, and vrj::GlWindowXWin::processEvent.

int vrj::GlWindow::origin_y [protected]
 

lower-left corner of window.

Definition at line 289 of file GlWindow.h.

Referenced by configWindow, vrj::GlWindowXWin::open, vrj::GlWindowWin32::open, vrj::GlWindowOSX::open, and vrj::GlWindowXWin::processEvent.

int vrj::GlWindow::mWindowId [protected]
 

A unique window id to identify us.

Definition at line 290 of file GlWindow.h.

bool vrj::GlWindow::mAreEventSource [protected]
 

Should we act as an event source too?

Definition at line 291 of file GlWindow.h.

Referenced by vrj::GlWindowXWin::checkEvents, vrj::GlWindowWin32::checkEvents, vrj::GlWindowXWin::close, vrj::GlWindowXWin::configWindow, vrj::GlWindowWin32::configWindow, vrj::GlWindowOSX::configWindow, finishSetup, vrj::GlWindowXWin::open, vrj::GlWindowWin32::open, and vrj::GlWindowOSX::open.


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