Added new osgGLUT::Window base class which is very basic right now, all it does

is bring up a GLUT window and provide virtual functions from which users should
subclass to add functionality.
This commit is contained in:
Robert Osfield
2001-10-23 15:55:01 +00:00
parent 25c8b05914
commit 63bb05e6fd
4 changed files with 261 additions and 0 deletions

View File

@@ -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

64
include/osgGLUT/Window Normal file
View File

@@ -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 <osgGLUT/Export>
#include <string>
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

View File

@@ -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

187
src/osgGLUT/Window.cpp Normal file
View File

@@ -0,0 +1,187 @@
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#endif
#include <stdio.h>
#include <string>
#include <osg/Notify>
#include <osgGLUT/glut>
#include <osgGLUT/Window>
#include <osg/Timer>
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."<<endl;
return false;
}
//glutInit( &argc, argv ); // I moved this into main to avoid passing
// argc and argv to the GLUTWindow
glutInitWindowPosition( _wx, _wy );
glutInitWindowSize( _ww, _wh );
glutInitDisplayMode( _displayMode);
glutCreateWindow( _title.c_str() );
glutReshapeFunc( reshapeCB );
glutVisibilityFunc( visibilityCB );
glutDisplayFunc( displayCB );
glutKeyboardFunc( keyboardCB );
glutMouseFunc( mouseCB );
glutMotionFunc( mouseMotionCB );
glutPassiveMotionFunc( mousePassiveMotionCB );
_is_open = 1;
return true;
}
void GLUTWindow::displayCB()
{
s_theGLUTWindow->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."<<endl;
if ( !open() )
return false;
}
glutMainLoop();
return true;
}