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()
63 void FGGLApplication::DisplayCallback()
65 if( application ) application->Display();
68 void FGGLApplication::IdleCallback()
70 if( application ) application->Idle();
73 void FGGLApplication::KeyCallback( unsigned char key, int x, int y )
75 if( application ) application->Key( key, x, y );
78 void FGGLApplication::ReshapeCallback( int width, int height )
80 if( application ) application->Reshape( width, height );
83 void FGGLApplication::Run( int glutMode, bool gameMode, int width, int height, int bpp )
85 glutInitDisplayMode(glutMode);
87 width = glutGet(GLUT_SCREEN_WIDTH);
88 height = glutGet(GLUT_SCREEN_HEIGHT);
89 char game_mode_str[20];
90 snprintf(game_mode_str, 20, "%dx%d:%d", width, height, bpp );
91 glutGameModeString( game_mode_str );
93 this->gameMode = gameMode;
96 width = glutGet(GLUT_SCREEN_WIDTH);
99 height = glutGet(GLUT_SCREEN_HEIGHT);
101 glutInitDisplayMode(glutMode);
102 // glutInitWindowSize(width, height);
103 windowId = glutCreateWindow(name);
107 glutKeyboardFunc(FGGLApplication::KeyCallback);
108 glutIdleFunc(FGGLApplication::IdleCallback);
109 glutDisplayFunc(FGGLApplication::DisplayCallback);
110 glutReshapeFunc(FGGLApplication::ReshapeCallback);