From a6d329b812a0904c1e660698b8b33c0412a1d906 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 24 Dec 2001 19:06:49 +0000 Subject: [PATCH] Updated the osgGLUT::Viewer to subclass from osgGLUT::Window as has been intended since the development of osgGLUT::Window. --- include/osgGLUT/Viewer | 33 +------ include/osgGLUT/Window | 13 +-- src/Demos/hangglide/hangglide.cpp | 2 - src/Demos/sgv/Makefile | 2 +- src/osgGLUT/Viewer.cpp | 149 +++++------------------------- src/osgGLUT/Window.cpp | 64 ++++++------- 6 files changed, 65 insertions(+), 198 deletions(-) diff --git a/include/osgGLUT/Viewer b/include/osgGLUT/Viewer index cb241a6f3..0b97b932f 100644 --- a/include/osgGLUT/Viewer +++ b/include/osgGLUT/Viewer @@ -15,15 +15,12 @@ #include #include -#include - -#ifdef SGV_USE_RTFS -#include -#endif +#include #include -namespace osgGLUT{ +namespace osgGLUT +{ /** A basic viewer base class which provides a window, simple keyboard and mouse interaction. * Please note, this viewer class has been developed via a rather haphazard @@ -31,17 +28,13 @@ namespace osgGLUT{ * but shouldn't be viewed as the be all and end of osg viewer classes. * Someone please rewrite it :-) */ -class OSGGLUT_EXPORT Viewer : public osgUtil::GUIActionAdapter +class OSGGLUT_EXPORT Viewer : public Window, osgUtil::GUIActionAdapter { public: Viewer(); virtual ~Viewer(); - void setWindowOrigin(int x, int y) { wx = x, wy = y; }; - void setWindowSize(int width, int height) { ww = width, wh = height; }; - void setWindowTitle(const std::string& title) { _title = title; } - /** init is deprecated, you should use addViewport instead. init is * only available for backwards compatibility.*/ virtual void init(osg::Node* rootnode); @@ -97,17 +90,8 @@ class OSGGLUT_EXPORT Viewer : public osgUtil::GUIActionAdapter protected: - static void displayCB(); - static void reshapeCB(int w, int h); - static void visibilityCB(int state); - static void mouseMotionCB(int x, int y); - static void mousePassiveMotionCB(int x, int y); - static void mouseCB(int button, int state, int x, int y); - static void keyboardCB(unsigned char key, int x, int y ); - virtual void display(); virtual void reshape(GLint w, GLint h); - virtual void visibility(int state); virtual void mouseMotion(int x, int y); virtual void mousePassiveMotion(int x, int y); virtual void mouse(int button, int state, int x, int y); @@ -136,15 +120,6 @@ class OSGGLUT_EXPORT Viewer : public osgUtil::GUIActionAdapter unsigned int _focusedViewport; std::string _saveFileName; - - std::string _title; - int wx, wy, ww, wh; - int _is_open; - - #ifdef SGV_USE_RTFS - unsigned int frame_rate; - RTfs *fs; - #endif bool _viewFrustumCullingActive; bool _smallFeatureCullingActive; diff --git a/include/osgGLUT/Window b/include/osgGLUT/Window index f4868e226..31363291d 100644 --- a/include/osgGLUT/Window +++ b/include/osgGLUT/Window @@ -9,15 +9,16 @@ #include -namespace osgGLUT{ +namespace osgGLUT +{ /** A basic GLUTWindow base class which provides a just a basic window. */ -class OSGGLUT_EXPORT GLUTWindow +class OSGGLUT_EXPORT Window { public: - GLUTWindow(); - virtual ~GLUTWindow(); + Window(); + virtual ~Window(); void setWindowOrigin(int x, int y) { _wx = x, _wy = y; }; void setWindowSize(int width, int height) { _ww = width, _wh = height; }; @@ -27,7 +28,7 @@ class OSGGLUT_EXPORT GLUTWindow virtual bool open(); virtual bool run(); virtual void display(); - + protected: static void displayCB(); @@ -45,7 +46,7 @@ class OSGGLUT_EXPORT GLUTWindow virtual void mouse(int button, int state, int x, int y); virtual void keyboard(unsigned char key, int x, int y); - static GLUTWindow* s_theGLUTWindow; + static Window* s_theWindow; std::string _title; int _wx, _wy, _ww, _wh; diff --git a/src/Demos/hangglide/hangglide.cpp b/src/Demos/hangglide/hangglide.cpp index c21395ac5..c35d18b3f 100644 --- a/src/Demos/hangglide/hangglide.cpp +++ b/src/Demos/hangglide/hangglide.cpp @@ -81,8 +81,6 @@ int main( int argc, char **argv ) viewer.selectCameraManipulator(pos); - osgUtil::SceneView* sv = viewer.getViewportSceneView(0); - viewer.run(); return 0; diff --git a/src/Demos/sgv/Makefile b/src/Demos/sgv/Makefile index 1cbd5b37f..561ab27f7 100644 --- a/src/Demos/sgv/Makefile +++ b/src/Demos/sgv/Makefile @@ -11,7 +11,7 @@ TARGET_BIN_FILES = sgv #note, standard library list. LIBS = -losgGLUT -losgUtil -losgDB -losg $(GLUTLIB) -lGLU -lGL -lm -lXmu -lX11 -lXi -C++FLAGS += -I../../../include -g +C++FLAGS += -I../../../include LDFLAGS += -L../../../lib include ../../../Make/makerules diff --git a/src/osgGLUT/Viewer.cpp b/src/osgGLUT/Viewer.cpp index ce2e2735a..0d652a5d2 100644 --- a/src/osgGLUT/Viewer.cpp +++ b/src/osgGLUT/Viewer.cpp @@ -79,18 +79,6 @@ Viewer::Viewer() { s_theViewer = this; - fullscreen = false; - _is_open = 0; - _saved_wx = wx = _saved_wy = wy = 0; - _saved_ww = ww = 800, - _saved_wh = wh = 600; - - _title = "OSG Viewer"; - - mx = ww/2, - my = wh/2; - mbutton = 0; - polymode = 0; texture = 1; backface = 1; @@ -148,10 +136,6 @@ void Viewer::readCommandLine(std::vector& commandLine) */ bool Viewer::open() { - if ( _is_open ) { - osg::notify(osg::NOTICE)<<"osgGLUT::Viewer::open() called with window already open."<< std::endl; - return false; - } if ( getNumViewports() <= 0 ) { osg::notify(osg::FATAL)<<"osgGLUT::Viewer::open() called with no Viewports registered."<< std::endl; return false; @@ -177,7 +161,7 @@ bool Viewer::open() selectCameraManipulator(0,index); } - GLUTEventAdapter::setWindowSize( wx, wy, ww, wh ); + GLUTEventAdapter::setWindowSize( _wx, _wy, _ww, _wh ); GLUTEventAdapter::setButtonMask(0); @@ -192,8 +176,8 @@ bool Viewer::open() ++itr) { osgUtil::SceneView* sceneView = itr->sceneView.get(); - int view[4] = { int(itr->viewport[0]*ww), int(itr->viewport[1]*wh), - int(itr->viewport[2]*ww), int(itr->viewport[3]*wh) }; + int view[4] = { int(itr->viewport[0]*_ww), int(itr->viewport[1]*_wh), + int(itr->viewport[2]*_ww), int(itr->viewport[3]*_wh) }; sceneView->setViewport(view[0], view[1], view[2], view[3]); @@ -223,12 +207,6 @@ bool Viewer::open() if (_displaySettings->getStereo() && _displaySettings->getStereoMode()==osg::DisplaySettings::QUAD_BUFFER) needQuadBufferStereo = true; - //glutInit( &argc, argv ); // I moved this into main to avoid passing - // argc and argv to the Viewer - glutInitWindowPosition( wx, wy ); - glutInitWindowSize( ww, wh ); - - // traverse the scene graphs gathering the requirements of the OpenGL buffers. osgUtil::DisplayRequirementsVisitor drv; drv.setDisplaySettings(_displaySettings.get()); @@ -270,7 +248,6 @@ bool Viewer::open() // by other systems I've come across so not need to worry about it. displayMode |= GLUT_MULTISAMPLE; - osg::notify(osg::INFO) <<"osgGLUT::Viewer::open() requesting displayMode = "<= int( itr->viewport[0]*ww ) && - ogl_y >= int( itr->viewport[1]*wh ) && - x <= int( (itr->viewport[0]+itr->viewport[2])*ww ) && - ogl_y <= int( (itr->viewport[1]+itr->viewport[3])*wh ) ) + if ( x >= int( itr->viewport[0]*_ww ) && + ogl_y >= int( itr->viewport[1]*_wh ) && + x <= int( (itr->viewport[0]+itr->viewport[2])*_ww ) && + ogl_y <= int( (itr->viewport[1]+itr->viewport[3])*_wh ) ) return index; } return -1; } - -void Viewer::displayCB() -{ - s_theViewer->display(); -} - - -//void Viewer::reshapeCB(GLint w, GLint h) -void Viewer::reshapeCB(int w, int h) -{ - s_theViewer->reshape(w, h); -} - - -void Viewer::visibilityCB( int state ) -{ - s_theViewer->visibility(state); -} - - -void Viewer::mouseCB(int button, int state, int x, int y) -{ - s_theViewer->mouse(button, state, x, y); -} - - -void Viewer::mouseMotionCB(int x, int y) -{ - s_theViewer->mouseMotion(x,y); -} - - -void Viewer::mousePassiveMotionCB(int x, int y) -{ - s_theViewer->mousePassiveMotion(x,y); -} - - -void Viewer::keyboardCB(unsigned char key, int x, int y) -{ - s_theViewer->keyboard(key,x,y); -} - - - // GWM July 2001 - moved all draw stats to Statistics structure, and related RenderBin // GWM Sept 2001 - all draw stats now calculated by calls to ->getStats(Statistic..) -void Viewer::showStats(const unsigned int viewport) +void Viewer::showStats(const unsigned int /*viewport*/) { // collect stats for viewport static int maxbins=1; // count number of bins static GLfloat tmax=100; - glViewport(0,0,ww,wh); - float vh = wh; + glViewport(0,0,_ww,_wh); + float vh = _wh; glDisable( GL_DEPTH_TEST ); // to see the stats always glDisable( GL_ALPHA_TEST ); @@ -647,7 +559,7 @@ void Viewer::showStats(const unsigned int viewport) delete [] primStats; // free up } if (_printStats==Statistics::STAT_DC) { // yet more stats - read the depth complexity - int wid=ww, ht=wh; // temporary local screen size - must change during this section + int wid=_ww, ht=_wh; // temporary local screen size - must change during this section if (wid>0 && ht>0) { const int blsize=16; char *clin=new char[wid/blsize+2]; // buffer to print dc @@ -756,8 +668,7 @@ void Viewer::display() void Viewer::reshape(GLint w, GLint h) { - ww = w; - wh = h; + Window::reshape(w,h); // Propagate new window size to viewports for(ViewportList::iterator itr=_viewportList.begin(); @@ -765,8 +676,8 @@ void Viewer::reshape(GLint w, GLint h) ++itr) { osgUtil::SceneView* sceneView = itr->sceneView.get(); - int view[4] = { int(itr->viewport[0]*ww), int(itr->viewport[1]*wh), - int(itr->viewport[2]*ww), int(itr->viewport[3]*wh) }; + int view[4] = { int(itr->viewport[0]*_ww), int(itr->viewport[1]*_wh), + int(itr->viewport[2]*_ww), int(itr->viewport[3]*_wh) }; sceneView->setViewport(view[0], view[1], view[2], view[3]); @@ -783,15 +694,6 @@ void Viewer::reshape(GLint w, GLint h) } -void Viewer::visibility(int state) -{ - if (state == GLUT_VISIBLE) - glutIdleFunc( displayCB ); - else - glutIdleFunc(0L); -} - - void Viewer::mouseMotion(int x, int y) { osg::ref_ptr ea = new GLUTEventAdapter; @@ -1043,8 +945,8 @@ void Viewer::keyboard(unsigned char key, int x, int y) fullscreen = !fullscreen; if (fullscreen) { - _saved_ww = ww; - _saved_wh = wh; + _saved_ww = _ww; + _saved_wh = _wh; glutFullScreen(); } else { @@ -1113,7 +1015,7 @@ void Viewer::keyboard(unsigned char key, int x, int y) osg::notify(osg::NOTICE) << "***** Intersecting **************"<< std::endl; osg::Vec3 near_point,far_point; - if (!sceneView->projectWindowXYIntoObject(x,wh-y,near_point,far_point)) + if (!sceneView->projectWindowXYIntoObject(x,_wh-y,near_point,far_point)) { osg::notify(osg::NOTICE) << "Failed to calculate intersection ray."<< std::endl; return; @@ -1275,11 +1177,6 @@ osg::Timer_t Viewer::updateFrameTick() bool Viewer::run() { - if (!_is_open) { - osg::notify(osg::NOTICE)<<"osgGLUT::Viewer::run() called without window open. Opening window."<< std::endl; - if ( !open() ) - return false; - } // Reset the views of all of SceneViews osg::ref_ptr ea = new GLUTEventAdapter; @@ -1292,11 +1189,7 @@ bool Viewer::run() } updateFrameTick(); -#ifdef SGV_USE_RTFS - fs->start(); -#endif - glutMainLoop(); - return true; + return Window::run(); } diff --git a/src/osgGLUT/Window.cpp b/src/osgGLUT/Window.cpp index bb4b8aaf4..b8d2591bd 100644 --- a/src/osgGLUT/Window.cpp +++ b/src/osgGLUT/Window.cpp @@ -14,11 +14,11 @@ using namespace osgGLUT; -GLUTWindow* GLUTWindow::s_theGLUTWindow = 0; +Window* Window::s_theWindow = 0; -GLUTWindow::GLUTWindow() +Window::Window() { - s_theGLUTWindow = this; + s_theWindow = this; _fullscreen = false; _is_open = 0; @@ -36,24 +36,24 @@ GLUTWindow::GLUTWindow() } -GLUTWindow::~GLUTWindow() +Window::~Window() { } /** - * Configure and open the GLUT window for this GLUTWindow + * Configure and open the GLUT window for this Window * */ -bool GLUTWindow::open() +bool Window::open() { if ( _is_open ) { - osg::notify(osg::NOTICE)<<"osgGLUT::GLUTWindow::open() called with window already open."<< std::endl; + osg::notify(osg::NOTICE)<<"osgGLUT::Window::open() called with window already open."<< std::endl; return false; } //glutInit( &argc, argv ); // I moved this into main to avoid passing - // argc and argv to the GLUTWindow + // argc and argv to the Window glutInitWindowPosition( _wx, _wy ); glutInitWindowSize( _ww, _wh ); @@ -74,62 +74,62 @@ bool GLUTWindow::open() return true; } -void GLUTWindow::displayCB() +void Window::displayCB() { - s_theGLUTWindow->display(); + s_theWindow->display(); } -//void GLUTWindow::reshapeCB(GLint w, GLint h) -void GLUTWindow::reshapeCB(int w, int h) +//void Window::reshapeCB(GLint w, GLint h) +void Window::reshapeCB(int w, int h) { - s_theGLUTWindow->reshape(w, h); + s_theWindow->reshape(w, h); } -void GLUTWindow::visibilityCB( int state ) +void Window::visibilityCB( int state ) { - s_theGLUTWindow->visibility(state); + s_theWindow->visibility(state); } -void GLUTWindow::mouseCB(int button, int state, int x, int y) +void Window::mouseCB(int button, int state, int x, int y) { - s_theGLUTWindow->mouse(button, state, x, y); + s_theWindow->mouse(button, state, x, y); } -void GLUTWindow::mouseMotionCB(int x, int y) +void Window::mouseMotionCB(int x, int y) { - s_theGLUTWindow->mouseMotion(x,y); + s_theWindow->mouseMotion(x,y); } -void GLUTWindow::mousePassiveMotionCB(int x, int y) +void Window::mousePassiveMotionCB(int x, int y) { - s_theGLUTWindow->mousePassiveMotion(x,y); + s_theWindow->mousePassiveMotion(x,y); } -void GLUTWindow::keyboardCB(unsigned char key, int x, int y) +void Window::keyboardCB(unsigned char key, int x, int y) { - s_theGLUTWindow->keyboard(key,x,y); + s_theWindow->keyboard(key,x,y); } -void GLUTWindow::display() +void Window::display() { } -void GLUTWindow::reshape(GLint w, GLint h) +void Window::reshape(GLint w, GLint h) { _ww = w; _wh = h; } -void GLUTWindow::visibility(int state) +void Window::visibility(int state) { if (state == GLUT_VISIBLE) glutIdleFunc( displayCB ); @@ -138,22 +138,22 @@ void GLUTWindow::visibility(int state) } -void GLUTWindow::mouseMotion(int x, int y) +void Window::mouseMotion(int , int ) { } -void GLUTWindow::mousePassiveMotion(int x, int y) +void Window::mousePassiveMotion(int , int ) { } -void GLUTWindow::mouse(int button, int state, int x, int y) +void Window::mouse(int , int , int , int ) { } -void GLUTWindow::keyboard(unsigned char key, int x, int y) +void Window::keyboard(unsigned char key, int , int ) { switch( key ) { @@ -173,10 +173,10 @@ void GLUTWindow::keyboard(unsigned char key, int x, int y) } } -bool GLUTWindow::run() +bool Window::run() { if (!_is_open) { - osg::notify(osg::NOTICE)<<"osgGLUT::GLUTWindow::run() called without window open. Opening window."<< std::endl; + osg::notify(osg::NOTICE)<<"osgGLUT::Window::run() called without window open. Opening window."<< std::endl; if ( !open() ) return false; }