2 // Written and (c) Torsten Dreyer - Torsten(at)t3r_dot_de
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License as
6 // published by the Free Software Foundation; either version 2 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "FGGLApplication.hxx"
24 #include <simgear/compiler.h>
28 #define snprintf sprintf_s
31 #include <OpenGL/gl.h>
32 #include <GLUT/glut.h>
42 FGGLApplication * FGGLApplication::application = NULL;
44 FGGLApplication::FGGLApplication( const char * aName, int argc, char ** argv ) :
48 if( application != NULL ) {
49 std::cerr << "Only one instance of FGGLApplication allowed!" << std::endl;
50 throw std::exception();
54 glutInit( &argc, argv );
57 FGGLApplication::~FGGLApplication()
61 void FGGLApplication::DisplayCallback()
63 if( application ) application->Display();
66 void FGGLApplication::IdleCallback()
68 if( application ) application->Idle();
71 void FGGLApplication::KeyCallback( unsigned char key, int x, int y )
73 if( application ) application->Key( key, x, y );
76 void FGGLApplication::ReshapeCallback( int width, int height )
78 if( application ) application->Reshape( width, height );
81 void FGGLApplication::Run( int glutMode, bool gameMode, int width, int height, int bpp )
83 glutInitDisplayMode(glutMode);
85 width = glutGet(GLUT_SCREEN_WIDTH);
86 height = glutGet(GLUT_SCREEN_HEIGHT);
87 char game_mode_str[20];
88 snprintf(game_mode_str, 20, "%dx%d:%d", width, height, bpp );
89 glutGameModeString( game_mode_str );
91 this->gameMode = gameMode;
94 width = glutGet(GLUT_SCREEN_WIDTH);
97 height = glutGet(GLUT_SCREEN_HEIGHT);
99 glutInitDisplayMode(glutMode);
100 // glutInitWindowSize(width, height);
101 windowId = glutCreateWindow(name);
105 glutKeyboardFunc(FGGLApplication::KeyCallback);
106 glutIdleFunc(FGGLApplication::IdleCallback);
107 glutDisplayFunc(FGGLApplication::DisplayCallback);
108 glutReshapeFunc(FGGLApplication::ReshapeCallback);