]> git.mxchange.org Git - flightgear.git/blob - utils/fgpanel/FGGLApplication.cxx
Replace the NOAA METAR URL with the new, updated one
[flightgear.git] / utils / fgpanel / FGGLApplication.cxx
1 //
2 //  Written and (c) Torsten Dreyer - Torsten(at)t3r_dot_de
3 //
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.
8 // 
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.
13 //
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.
17 //
18
19 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "FGGLApplication.hxx"
24 #include <simgear/compiler.h>
25
26 #ifdef HAVE_WINDOWS_H
27 #include <windows.h>
28 #endif
29
30 #if defined (SG_MAC)
31 #include <OpenGL/gl.h>
32 #include <GLUT/glut.h>
33 #else
34 #include <GL/gl.h>
35 #include <GL/glut.h>
36 #endif
37
38 #include <iostream>
39 #include <exception>
40 #include <stdio.h>
41
42 FGGLApplication * FGGLApplication::application = NULL;
43
44 FGGLApplication::FGGLApplication( const char * aName, int argc, char ** argv ) :
45   gameMode(false),
46   name( aName )
47 {
48   if( application != NULL ) {
49     std::cerr << "Only one instance of FGGLApplication allowed!" << std::endl;
50     throw std::exception();
51   }
52   application = this;  
53
54   glutInit( &argc, argv );
55 }
56
57 FGGLApplication::~FGGLApplication()
58 {
59     if (gameMode)
60         glutLeaveGameMode();
61 }
62
63 void FGGLApplication::DisplayCallback()
64 {
65   if( application ) application->Display();
66 }
67
68 void FGGLApplication::IdleCallback()
69 {
70   if( application ) application->Idle();
71 }
72
73 void FGGLApplication::KeyCallback( unsigned char key, int x, int y )
74 {
75   if( application ) application->Key( key, x, y );
76 }
77
78 void FGGLApplication::ReshapeCallback( int width, int height )
79 {
80   if( application ) application->Reshape( width, height );
81 }
82
83 void FGGLApplication::Run( int glutMode, bool gameMode, int width, int height, int bpp )
84 {
85   glutInitDisplayMode(glutMode);
86   if( gameMode ) {
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 );
92     glutEnterGameMode();
93     this->gameMode = gameMode;
94   } else {
95     if( width == -1 ) 
96       width = glutGet(GLUT_SCREEN_WIDTH);
97
98     if( height == -1 )
99       height = glutGet(GLUT_SCREEN_HEIGHT);
100
101     glutInitDisplayMode(glutMode);
102 //    glutInitWindowSize(width, height);
103     windowId = glutCreateWindow(name);
104   }
105   Init();
106
107   glutKeyboardFunc(FGGLApplication::KeyCallback);
108   glutIdleFunc(FGGLApplication::IdleCallback);
109   glutDisplayFunc(FGGLApplication::DisplayCallback);
110   glutReshapeFunc(FGGLApplication::ReshapeCallback);
111   glutMainLoop();
112 }