diff --git a/VisualStudio/osgGLUT/osgGLUT.dsp b/VisualStudio/osgGLUT/osgGLUT.dsp index 8a6d1140f..e801366dd 100755 --- a/VisualStudio/osgGLUT/osgGLUT.dsp +++ b/VisualStudio/osgGLUT/osgGLUT.dsp @@ -101,6 +101,10 @@ SOURCE=..\..\src\osgGLUT\Version.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osgGLUT\Window.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osgGLUT\Viewer.cpp # End Source File # End Group @@ -121,6 +125,10 @@ SOURCE=..\..\Include\osgGLUT\GLUTEventAdapter # End Source File # Begin Source File +SOURCE=..\..\Include\osgGLUT\Window +# End Source File +# Begin Source File + SOURCE=..\..\Include\osgGLUT\Version # End Source File # Begin Source File diff --git a/include/osgGLUT/Window b/include/osgGLUT/Window new file mode 100644 index 000000000..f4868e226 --- /dev/null +++ b/include/osgGLUT/Window @@ -0,0 +1,64 @@ +//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield +//Distributed under the terms of the GNU Library General Public License (LGPL) +//as published by the Free Software Foundation. + +#ifndef OSGGLUT_GLUTWINDOW +#define OSGGLUT_GLUTWINDOW 1 + +#include + +#include + +namespace osgGLUT{ + +/** A basic GLUTWindow base class which provides a just a basic window. */ +class OSGGLUT_EXPORT GLUTWindow +{ + public: + + GLUTWindow(); + virtual ~GLUTWindow(); + + 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; } + void setDisplayMode(unsigned int displayMode) { _displayMode = displayMode; } + + virtual bool open(); + virtual bool run(); + virtual void display(); + + 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 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); + virtual void keyboard(unsigned char key, int x, int y); + + static GLUTWindow* s_theGLUTWindow; + + std::string _title; + int _wx, _wy, _ww, _wh; + unsigned int _displayMode; + int _is_open; + + int _mx, _my, _mbutton; + bool _fullscreen; + int _saved_wx, _saved_wy, _saved_ww,_saved_wh; + + +}; + +}; + +#endif // SG_VIEWIER_H diff --git a/src/osgGLUT/Makefile b/src/osgGLUT/Makefile index 20fb492a0..13ee5a95c 100644 --- a/src/osgGLUT/Makefile +++ b/src/osgGLUT/Makefile @@ -4,6 +4,7 @@ include ../../Make/makedefs C++FILES = \ GLUTEventAdapter.cpp\ Version.cpp\ + Window.cpp\ Viewer.cpp\ TARGET_BASENAME = osgGLUT @@ -19,6 +20,7 @@ TARGET_INCLUDE_FILES = \ osgGLUT/Export\ osgGLUT/GLUTEventAdapter\ osgGLUT/Version\ + osgGLUT/Window\ osgGLUT/Viewer\ C++FLAGS += -I ../../include diff --git a/src/osgGLUT/Window.cpp b/src/osgGLUT/Window.cpp new file mode 100644 index 000000000..aa7a22f4c --- /dev/null +++ b/src/osgGLUT/Window.cpp @@ -0,0 +1,187 @@ +#if defined(_MSC_VER) + #pragma warning( disable : 4786 ) +#endif + +#include +#include + +#include + +#include +#include + +#include + +using namespace osgGLUT; + +GLUTWindow* GLUTWindow::s_theGLUTWindow = 0; + +GLUTWindow::GLUTWindow() +{ + s_theGLUTWindow = this; + + _fullscreen = false; + _is_open = 0; + _saved_wx = _wx = _saved_wy = _wy = 0; + _saved_ww = _ww = 800, + _saved_wh = _wh = 600; + + _title = "OSG Window"; + + _displayMode = GLUT_DOUBLE| GLUT_RGB | GLUT_DEPTH; + + _mx = _ww/2, + _my = _wh/2; + _mbutton = 0; +} + + +GLUTWindow::~GLUTWindow() +{ +} + + +/** + * Configure and open the GLUT window for this GLUTWindow + * + */ +bool GLUTWindow::open() +{ + if ( _is_open ) { + osg::notify(osg::NOTICE)<<"osgGLUT::GLUTWindow::open() called with window already open."<display(); +} + + +//void GLUTWindow::reshapeCB(GLint w, GLint h) +void GLUTWindow::reshapeCB(int w, int h) +{ + s_theGLUTWindow->reshape(w, h); +} + + +void GLUTWindow::visibilityCB( int state ) +{ + s_theGLUTWindow->visibility(state); +} + + +void GLUTWindow::mouseCB(int button, int state, int x, int y) +{ + s_theGLUTWindow->mouse(button, state, x, y); +} + + +void GLUTWindow::mouseMotionCB(int x, int y) +{ + s_theGLUTWindow->mouseMotion(x,y); +} + + +void GLUTWindow::mousePassiveMotionCB(int x, int y) +{ + s_theGLUTWindow->mousePassiveMotion(x,y); +} + + +void GLUTWindow::keyboardCB(unsigned char key, int x, int y) +{ + s_theGLUTWindow->keyboard(key,x,y); +} + + +void GLUTWindow::display() +{ +} + + +void GLUTWindow::reshape(GLint w, GLint h) +{ + _ww = w; + _wh = h; +} + + +void GLUTWindow::visibility(int state) +{ + if (state == GLUT_VISIBLE) + glutIdleFunc( displayCB ); + else + glutIdleFunc(0L); +} + + +void GLUTWindow::mouseMotion(int x, int y) +{ +} + + +void GLUTWindow::mousePassiveMotion(int x, int y) +{ +} + + +void GLUTWindow::mouse(int button, int state, int x, int y) +{ +} + + +void GLUTWindow::keyboard(unsigned char key, int x, int y) +{ + switch( key ) + { + case 'f' : + _fullscreen = !_fullscreen; + if (_fullscreen) + { + _saved_ww = _ww; + _saved_wh = _wh; + glutFullScreen(); + } else + { + //glutPositionWindow(wx,wy); + glutReshapeWindow(_saved_ww,_saved_wh); + } + break; + } +} + +bool GLUTWindow::run() +{ + if (!_is_open) { + osg::notify(osg::NOTICE)<<"osgGLUT::GLUTWindow::run() called without window open. Opening window."<