]> git.mxchange.org Git - flightgear.git/blob - Main/GLUTmain.cxx
Added command line rendering options:
[flightgear.git] / Main / GLUTmain.cxx
1 //
2 // GLUTmain.cxx -- top level sim routines
3 //
4 // Written by Curtis Olson for OpenGL, started May 1997.
5 //
6 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23 // (Log is kept at end of this file)
24
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #ifdef HAVE_WINDOWS_H
31 #  include <windows.h>                     
32 #endif
33
34 #include <GL/glut.h>
35 #include <XGL/xgl.h>
36 #include <stdio.h>
37
38 #ifdef HAVE_STDLIB_H
39 #   include <stdlib.h>
40 #endif
41
42 #include <Include/fg_constants.h>  // for VERSION
43 #include <Include/general.h>
44
45 #include <Aircraft/aircraft.h>
46 #include <Astro/moon.hxx>
47 #include <Astro/planets.hxx>
48 #include <Astro/sky.hxx>
49 #include <Astro/stars.hxx>
50 #include <Astro/sun.hxx>
51 #include <Cockpit/cockpit.hxx>
52 #include <Debug/fg_debug.h>
53 #include <Joystick/joystick.h>
54 #include <Math/fg_geodesy.h>
55 #include <Math/mat3.h>
56 #include <Math/polar.h>
57 #include <Scenery/scenery.hxx>
58 #include <Scenery/tilemgr.hxx>
59 #include <Time/event.hxx>
60 #include <Time/fg_time.hxx>
61 #include <Time/fg_timer.hxx>
62 #include <Time/sunpos.hxx>
63 #include <Weather/weather.h>
64
65 #include "GLUTkey.hxx"
66 #include "fg_init.hxx"
67 #include "options.hxx"
68 #include "views.hxx"
69
70
71 // This is a record containing global housekeeping information
72 fgGENERAL general;
73
74 // view parameters
75 static GLfloat win_ratio = 1.0;
76 static GLint winWidth, winHeight;
77
78 // Another hack
79 int use_signals = 0;
80
81 // Yet another other hack. Used for my prototype instrument code. (Durk)
82 int displayInstruments; 
83
84 /*
85 // The following defines flight gear options. Because glutlib will also
86 // want to parse its own options, those options must not be included here
87 // or they will get parsed by the main program option parser. Hence case
88 // is significant for any option added that might be in conflict with
89 // glutlib's parser.
90 //
91 // glutlib parses for:
92 //    -display
93 //    -direct   (invalid in Win32)
94 //    -geometry
95 //    -gldebug
96 //    -iconized
97 //    -indirect (invalid in Win32)
98 //    -synce
99 //
100 // Note that glutlib depends upon strings while this program's
101 // option parser wants only initial characters followed by numbers
102 // or pathnames.
103 //
104 const char *fg_cmdargopts = "a:c:Hhp:r:v:x:?";
105 //
106 // Where
107 //   -a aircraftfilename    aircraft start over ride
108 //   -c0x0000 - 0xffffffff  debug class setting
109 //    H,h.? help on command line use (does not need Option struct)
110 //   -p  priority
111 //   -r flightgear          root path to program support files
112 //   -v0 -v1                initial view mode (hud/no_hud currently)
113 //   -xlogpathname          debug logfile name
114 //
115 // Defaults in arguments to indicate not set on command line.
116 // Program defaults set variables from constants if neither command
117 // options or environmental variables effect values.
118 //
119
120 char  acArgbuf          [ MAXPATH + 1] = "\0";
121 int   debugArgValue                    = -2;
122 int   priorityArgValue                 = -1;
123 char  rootArgbuf        [ MAXPATH + 1] = "\0";
124 int   viewArg                          = -1;
125 char  logArgbuf         [ MAXPATH + 1] = "\0";
126
127 // There is a reason for defining the option structs by name and then
128 // creating an array of pointers to options. C++ is unfriendly to
129 // initializing arrays of objects that are not built in types. Always
130 // look forward. (Besides, you can follow what is going on better and
131 // add or modify with greater security. -ch
132 //
133 Option aircraftOption = { 'a',
134                           OPT_STRING,
135                           acArgbuf,
136                           "Startup aircraft pathname override"
137                         };
138 Option debugOption    = { 'c',
139                           OPT_LHEX,       // Long int (32 bits)
140                           &debugArgValue,
141                           "Debug trace level"
142                         };
143 Option priorityOption = { 'p',
144                           OPT_INTEGER,
145                           &priorityArgValue,
146                           "Debug priority Threshold"
147                         };
148 Option rootOption     = { 'r',
149                           OPT_STRING,
150                           rootArgbuf,
151                           "Root directory for execution"
152                         };
153 Option hudOption      = { 'v',
154                           OPT_INTEGER,
155                           &viewArg,
156                           "View mode start" // Naked,HUD,Panel,Chase,Tower...
157                         };
158
159 // Only naked view and HUD are implemented at this time
160 Option logfileOption  = { 'x',
161                           OPT_STRING,
162                           logArgbuf,
163                           "Debug log file name"
164                         };
165
166 #define OptsDefined 6
167 Option *CmdLineOptions[ OptsDefined ] = {
168   &aircraftOption,
169   &debugOption,
170   &hudOption,
171   &priorityOption,
172   &rootOption,
173   &logfileOption
174   };
175
176 const char *DefaultRootDir  = "\\Flightgear";
177 const char *DefaultAircraft = "Navion.acf";
178 const char *DefaultDebuglog = "fgdebug.log";
179 const int   DefaultViewMode = HUD_VIEW;
180 */
181
182 // Debug defaults handled in fg_debug.c
183
184 // fgInitVisuals() -- Initialize various GL/view parameters
185 static void fgInitVisuals( void ) {
186     fgLIGHT *l;
187     fgOPTIONS *o;
188     struct fgWEATHER *w;
189
190     l = &cur_light_params;
191     o = &current_options;
192     w = &current_weather;
193
194     // xglDisable( GL_DITHER );
195
196     // If enabled, normal vectors specified with glNormal are scaled
197     // to unit length after transformation.  See glNormal.
198     xglEnable( GL_NORMALIZE );
199
200     xglEnable( GL_LIGHTING );
201     xglEnable( GL_LIGHT0 );
202     xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
203
204     xglFogi (GL_FOG_MODE, GL_LINEAR);
205     xglFogf (GL_FOG_START, w->visibility / 1000000.0 );
206     xglFogf (GL_FOG_END, w->visibility);
207     // xglFogf (GL_FOG_DENSITY, w->visibility);
208     xglHint (GL_FOG_HINT, GL_NICEST /* GL_FASTEST */ );
209
210     if ( o->wireframe ) {
211         // draw wire frame
212         xglPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
213     }
214 }
215
216
217 // Update the view volume, position, and orientation
218 static void fgUpdateViewParams( void ) {
219     fgFLIGHT *f;
220     fgLIGHT *l;
221     fgVIEW *v;
222
223     f = current_aircraft.flight;
224     l = &cur_light_params;
225     v = &current_view;
226
227     fgViewUpdate(f, v, l);
228
229     if (displayInstruments) {
230         xglViewport( 0, (GLint)(winHeight / 2 ) , 
231                      (GLint)winWidth, (GLint)winHeight / 2 );
232         // Tell GL we are about to modify the projection parameters
233         xglMatrixMode(GL_PROJECTION);
234         xglLoadIdentity();
235         gluPerspective(65.0, 2.0/win_ratio, 1.0, 100000.0);
236     } else {
237         xglViewport(0, 0 , (GLint)winWidth, (GLint) winHeight);
238         // Tell GL we are about to modify the projection parameters
239         xglMatrixMode(GL_PROJECTION);
240         xglLoadIdentity();
241         gluPerspective(65.0, 1.0/win_ratio, 10.0, 100000.0);
242     }
243
244     xglMatrixMode(GL_MODELVIEW);
245     xglLoadIdentity();
246     
247     // set up our view volume (default)
248     gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
249                v->view_pos.x + v->view_forward[0], 
250                v->view_pos.y + v->view_forward[1], 
251                v->view_pos.z + v->view_forward[2],
252                v->view_up[0], v->view_up[1], v->view_up[2]);
253
254     // look almost straight up (testing and eclipse watching)
255     /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
256                v->view_pos.x + v->view_up[0] + .001, 
257                v->view_pos.y + v->view_up[1] + .001, 
258                v->view_pos.z + v->view_up[2] + .001,
259                v->view_up[0], v->view_up[1], v->view_up[2]); */
260
261     // lock view horizontally towards sun (testing)
262     /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
263                v->view_pos.x + v->surface_to_sun[0], 
264                v->view_pos.y + v->surface_to_sun[1], 
265                v->view_pos.z + v->surface_to_sun[2],
266                v->view_up[0], v->view_up[1], v->view_up[2]); */
267
268     // lock view horizontally towards south (testing)
269     /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
270                v->view_pos.x + v->surface_south[0], 
271                v->view_pos.y + v->surface_south[1], 
272                v->view_pos.z + v->surface_south[2],
273                v->view_up[0], v->view_up[1], v->view_up[2]); */
274
275     // set the sun position
276     xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
277 }
278
279
280 // Draw a basic instrument panel
281 static void fgUpdateInstrViewParams( void ) {
282     xglViewport(0, 0 , (GLint)winWidth, (GLint)winHeight / 2);
283   
284     xglMatrixMode(GL_PROJECTION);
285     xglPushMatrix();
286   
287     xglLoadIdentity();
288     gluOrtho2D(0, 640, 0, 480);
289     xglMatrixMode(GL_MODELVIEW);
290     xglPushMatrix();
291     xglLoadIdentity();
292
293     xglColor3f(1.0, 1.0, 1.0);
294     xglIndexi(7);
295   
296     xglDisable(GL_DEPTH_TEST);
297     xglDisable(GL_LIGHTING);
298   
299     xglLineWidth(1);
300     xglColor3f (0.5, 0.5, 0.5);
301
302     xglBegin(GL_QUADS);
303     xglVertex2f(0.0, 0.00);
304     xglVertex2f(0.0, 480.0);
305     xglVertex2f(640.0,480.0);
306     xglVertex2f(640.0, 0.0);
307     xglEnd();
308
309     xglRectf(0.0,0.0, 640, 480);
310     xglEnable(GL_DEPTH_TEST);
311     xglEnable(GL_LIGHTING);
312     xglMatrixMode(GL_PROJECTION);
313     xglPopMatrix();
314     xglMatrixMode(GL_MODELVIEW);
315     xglPopMatrix();
316 }
317
318
319 // Update all Visuals (redraws anything graphics related)
320 static void fgRenderFrame( void ) {
321     fgLIGHT *l;
322     fgOPTIONS *o;
323     fgTIME *t;
324     fgVIEW *v;
325     double angle;
326     GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
327     GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
328     GLfloat color[4] = { 0.54, 0.44, 0.29, 1.0 };
329
330     l = &cur_light_params;
331     o = &current_options;
332     t = &cur_time_params;
333     v = &current_view;
334
335     // update view volume parameters
336     fgUpdateViewParams();
337
338     if ( o->skyblend ) {
339         glClearColor(black[0], black[1], black[2], black[3]);
340     } else {
341         glClearColor(l->sky_color[0], l->sky_color[1], 
342                      l->sky_color[2], l->sky_color[3]);
343     }
344     xglClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
345
346     // Tell GL we are switching to model view parameters
347     xglMatrixMode(GL_MODELVIEW);
348     // xglLoadIdentity();
349
350     // draw sky
351     xglDisable( GL_DEPTH_TEST );
352     xglDisable( GL_LIGHTING );
353     xglDisable( GL_CULL_FACE );
354     xglDisable( GL_FOG );
355     xglShadeModel( GL_SMOOTH );
356     if ( o->skyblend ) {
357         fgSkyRender();
358     }
359
360     // setup transformation for drawing astronomical objects
361     xglPushMatrix();
362     // Translate to view position
363     xglTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z );
364     // Rotate based on gst (sidereal time)
365     angle = t->gst * 15.041085; /* should be 15.041085, Curt thought it was 15*/
366     // printf("Rotating astro objects by %.2f degrees\n",angle);
367     xglRotatef( angle, 0.0, 0.0, -1.0 );
368
369     // draw stars and planets
370     fgStarsRender();
371     fgPlanetsRender();
372
373     // draw the sun
374     fgSunRender();
375
376     // render the moon
377     xglEnable( GL_LIGHTING );
378     // set lighting parameters
379     xglLightfv(GL_LIGHT0, GL_AMBIENT, white );
380     xglLightfv(GL_LIGHT0, GL_DIFFUSE, white );
381     xglEnable( GL_CULL_FACE );
382     
383     // Let's try some blending technique's (Durk)
384     glEnable(GL_BLEND);
385     glBlendFunc(GL_ONE, GL_ONE);
386     fgMoonRender();
387     glDisable(GL_BLEND);
388
389     xglPopMatrix();
390
391     // draw scenery
392     if ( o->shading ) {
393         xglShadeModel( GL_SMOOTH ); 
394     } else {
395         xglShadeModel( GL_FLAT ); 
396     }
397     xglEnable( GL_DEPTH_TEST );
398     if ( o->fog ) {
399         xglEnable( GL_FOG );
400         xglFogfv (GL_FOG_COLOR, l->fog_color);
401     }
402     // set lighting parameters
403     xglLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_ambient );
404     xglLightfv(GL_LIGHT0, GL_DIFFUSE, l->scene_diffuse );
405
406     if ( o->textures ) {
407         // texture parameters
408         xglEnable( GL_TEXTURE_2D );
409         xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ) ;
410         xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ) ;
411         xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) ;
412         xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
413                           GL_LINEAR /* GL_LINEAR_MIPMAP_LINEAR */ ) ;
414         xglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
415         xglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
416         // set base color (I don't think this is doing anything here)
417         xglMaterialfv (GL_FRONT, GL_AMBIENT, white);
418         xglMaterialfv (GL_FRONT, GL_DIFFUSE, white);
419     } else {
420         xglDisable( GL_TEXTURE_2D );
421         xglMaterialfv (GL_FRONT, GL_AMBIENT, color);
422         xglMaterialfv (GL_FRONT, GL_DIFFUSE, color);
423     }
424
425     fgTileMgrRender();
426
427     xglDisable( GL_TEXTURE_2D );
428
429     // display HUD
430     if( o->hud_status ) {
431         fgCockpitUpdate();
432     }
433
434     // display instruments
435     if (displayInstruments) {
436         fgUpdateInstrViewParams();
437     }
438
439     xglutSwapBuffers();
440 }
441
442
443 // Update internal time dependent calculations (i.e. flight model)
444 void fgUpdateTimeDepCalcs(int multi_loop) {
445     fgFLIGHT *f;
446     fgTIME *t;
447     fgVIEW *v;
448     int i;
449
450     f = current_aircraft.flight;
451     t = &cur_time_params;
452     v = &current_view;
453
454     // update the flight model
455     if ( multi_loop < 0 ) {
456         multi_loop = DEFAULT_MULTILOOP;
457     }
458
459     // printf("updating flight model x %d\n", multi_loop);
460     fgFlightModelUpdate(FG_LARCSIM, f, multi_loop);
461
462     // update the view angle
463     for ( i = 0; i < multi_loop; i++ ) {
464         if ( fabs(v->goal_view_offset - v->view_offset) < 0.05 ) {
465             v->view_offset = v->goal_view_offset;
466             break;
467         } else {
468             // move v->view_offset towards v->goal_view_offset
469             if ( v->goal_view_offset > v->view_offset ) {
470                 if ( v->goal_view_offset - v->view_offset < FG_PI ) {
471                     v->view_offset += 0.01;
472                 } else {
473                     v->view_offset -= 0.01;
474                 }
475             } else {
476                 if ( v->view_offset - v->goal_view_offset < FG_PI ) {
477                     v->view_offset -= 0.01;
478                 } else {
479                     v->view_offset += 0.01;
480                 }
481             }
482             if ( v->view_offset > FG_2PI ) {
483                 v->view_offset -= FG_2PI;
484             } else if ( v->view_offset < 0 ) {
485                 v->view_offset += FG_2PI;
486             }
487         }
488     }
489 }
490
491
492 void fgInitTimeDepCalcs( void ) {
493     // initialize timer
494
495 #ifdef HAVE_SETITIMER
496     fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs );
497 #endif HAVE_SETITIMER
498
499 }
500
501
502 // What should we do when we have nothing else to do?  Let's get ready
503 // for the next move and update the display?
504 static void fgMainLoop( void ) {
505     static int remainder = 0;
506     int elapsed, multi_loop;
507     double cur_elev;
508     // double joy_x, joy_y;
509     // int joy_b1, joy_b2;
510     fgAIRCRAFT *a;
511     fgFLIGHT *f;
512     fgTIME *t;
513
514     fgPrintf( FG_ALL, FG_DEBUG, "Running Main Loop\n");
515     fgPrintf( FG_ALL, FG_DEBUG, "======= ==== ====\n");
516
517     a = &current_aircraft;
518     f = a->flight;
519     t = &cur_time_params;
520
521     // update "time"
522     fgTimeUpdate(f, t);
523
524     // Read joystick
525     /* fgJoystickRead( &joy_x, &joy_y, &joy_b1, &joy_b2 );
526     printf( "Joystick X %f  Y %f  B1 %d  B2 %d\n",  
527             joy_x, joy_y, joy_b1, joy_b2 );
528     fgElevSet( -joy_y );
529     fgAileronSet( joy_x ); */
530
531     // Calculate model iterations needed
532     elapsed = fgGetTimeInterval();
533     fgPrintf( FG_ALL, FG_BULK, 
534               "Time interval is = %d, previous remainder is = %d\n", 
535               elapsed, remainder);
536     fgPrintf( FG_ALL, FG_BULK, 
537               "--> Frame rate is = %.2f\n", 1000.0 / (float)elapsed);
538     elapsed += remainder;
539
540     multi_loop = (int)(((float)elapsed * 0.001) * DEFAULT_MODEL_HZ);
541     remainder = elapsed - ((multi_loop*1000) / DEFAULT_MODEL_HZ);
542     fgPrintf( FG_ALL, FG_BULK, 
543               "Model iterations needed = %d, new remainder = %d\n", 
544               multi_loop, remainder);
545         
546     // Run flight model
547     if ( ! use_signals ) {
548         // flight model
549         fgUpdateTimeDepCalcs(multi_loop);
550     }
551
552     // I'm just sticking this here for now, it should probably move
553     // eventually
554     /* cur_elev = mesh_altitude(FG_Longitude * RAD_TO_ARCSEC, 
555                                FG_Latitude  * RAD_TO_ARCSEC); */
556     // there is no ground collision detection really, so for now I
557     // just hard code the ground elevation to be 0 */
558     cur_elev = 0;
559
560     // printf("Ground elevation is %.2f meters here.\n", cur_elev);
561     // FG_Runway_altitude = cur_elev * METER_TO_FEET;
562
563     if ( FG_Altitude * FEET_TO_METER < cur_elev + 3.758099) {
564         // set this here, otherwise if we set runway height above our
565         // current height we get a really nasty bounce.
566         FG_Runway_altitude = FG_Altitude - 3.758099;
567
568         // now set aircraft altitude above ground
569         FG_Altitude = cur_elev * METER_TO_FEET + 3.758099;
570         fgPrintf( FG_ALL, FG_BULK, "<*> resetting altitude to %.0f meters\n", 
571                FG_Altitude * FEET_TO_METER);
572     }
573
574     fgAircraftOutputCurrent(a);
575
576     // see if we need to load any new scenery tiles
577     fgTileMgrUpdate();
578
579     // Process/manage pending events
580     fgEventProcess();
581
582     // redraw display
583     fgRenderFrame();
584
585     fgPrintf( FG_ALL, FG_DEBUG, "\n");
586 }
587
588
589 // Handle new window size or exposure
590 static void fgReshape( int width, int height ) {
591     // Do this so we can call fgReshape(0,0) ourselves without having
592     // to know what the values of width & height are.
593     if ( (height > 0) && (width > 0) ) {
594         win_ratio = (GLfloat) height / (GLfloat) width;
595     }
596
597     winWidth = width;
598     winHeight = height;
599
600     // Inform gl of our view window size (now handled elsewhere)
601     // xglViewport(0, 0, (GLint)width, (GLint)height);
602     fgUpdateViewParams();
603     
604     // xglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
605 }
606
607
608 // Initialize GLUT and define a main window
609 int fgGlutInit( int argc, char **argv ) {
610     // GLUT will extract all glut specific options so later on we only
611     // need wory about our own.
612     xglutInit(&argc, argv);
613
614     // Define Display Parameters
615     xglutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
616
617     // Define initial window size
618     xglutInitWindowSize(640, 480);
619
620     // Initialize windows
621     xglutCreateWindow("Flight Gear");
622
623     return(1);
624 }
625
626
627 // Initialize GLUT event handlers
628 int fgGlutInitEvents( void ) {
629     // call fgReshape() on window resizes
630     xglutReshapeFunc( fgReshape );
631
632     // call GLUTkey() on keyboard event
633     xglutKeyboardFunc( GLUTkey );
634     glutSpecialFunc( GLUTspecialkey );
635
636     // call fgMainLoop() whenever there is
637     // nothing else to do
638     xglutIdleFunc( fgMainLoop );
639
640     // draw the scene
641     xglutDisplayFunc( fgRenderFrame );
642
643     return(1);
644 }
645
646
647 // Main ...
648 int main( int argc, char **argv ) {
649     fgFLIGHT *f;
650     int result;  // Used in command line argument.
651
652     f = current_aircraft.flight;
653
654     // Initialize the debugging output system
655     fgInitDebug();
656
657     fgPrintf(FG_GENERAL, FG_INFO, "Flight Gear:  Version %s\n\n", VERSION);
658
659     // Initialize the Window/Graphics environment.
660     if( !fgGlutInit(argc, argv) ) {
661         fgPrintf( FG_GENERAL, FG_EXIT, "GLUT initialization failed ...\n" );
662     }
663
664     // Parse remaining command line options
665     result = current_options.parse(argc, argv);
666
667     if ( result != FG_OPTIONS_OK ) {
668         // Something must have gone horribly wrong with the command
669         // line parsing or maybe the user just requested help ... :-)
670         current_options.usage();
671         fgPrintf( FG_GENERAL, FG_EXIT, "\nShutting down ...\n");
672     }
673
674     // These are a few miscellaneous things that aren't really
675     // "subsystems" but still need to be initialized.
676     if( !fgInitGeneral()) {
677         fgPrintf( FG_GENERAL, FG_EXIT, "General initializations failed ...\n" );
678     }
679
680     // This is the top level init routine which calls all the other
681     // subsystem initialization routines.  If you are adding a
682     // subsystem to flight gear, its initialization call should
683     // located in this routine.
684     if( !fgInitSubsystems()) {
685         fgPrintf( FG_GENERAL, FG_EXIT,
686                   "Subsystem initializations failed ...\n" );
687     }
688
689     // setup OpenGL view parameters
690     fgInitVisuals();
691
692     if ( use_signals ) {
693         // init timer routines, signals, etc.  Arrange for an alarm
694         // signal to be generated, etc.
695         fgInitTimeDepCalcs();
696     }
697
698     // Initialize the various GLUT Event Handlers.
699     if( !fgGlutInitEvents() ) {
700         fgPrintf( FG_GENERAL, FG_EXIT, 
701                   "GLUT event handler initialization failed ...\n" );
702     }
703
704     // pass control off to the master GLUT event handler
705     glutMainLoop();
706
707     // we never actually get here ... but just in case ... :-)
708     return(0);
709 }
710
711
712 #ifdef __SUNPRO_CC
713 extern "C" {
714     void __eprintf( void ) {
715     }
716 }
717 #endif
718
719
720 // $Log$
721 // Revision 1.9  1998/04/30 12:34:17  curt
722 // Added command line rendering options:
723 //   enable/disable fog/haze
724 //   specify smooth/flat shading
725 //   disable sky blending and just use a solid color
726 //   enable wireframe drawing mode
727 //
728 // Revision 1.8  1998/04/28 01:20:21  curt
729 // Type-ified fgTIME and fgVIEW.
730 // Added a command line option to disable textures.
731 //
732 // Revision 1.7  1998/04/26 05:10:02  curt
733 // "struct fgLIGHT" -> "fgLIGHT" because fgLIGHT is typedef'd.
734 //
735 // Revision 1.6  1998/04/25 22:06:30  curt
736 // Edited cvs log messages in source files ... bad bad bad!
737 //
738 // Revision 1.5  1998/04/25 20:24:01  curt
739 // Cleaned up initialization sequence to eliminate interdependencies
740 // between sun position, lighting, and view position.  This creates a
741 // valid single pass initialization path.
742 //
743 // Revision 1.4  1998/04/24 14:19:30  curt
744 // Fog tweaks.
745 //
746 // Revision 1.3  1998/04/24 00:49:18  curt
747 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
748 // Trying out some different option parsing code.
749 // Some code reorganization.
750 //
751 // Revision 1.2  1998/04/22 13:25:41  curt
752 // C++ - ifing the code.
753 // Starting a bit of reorganization of lighting code.
754 //
755 // Revision 1.1  1998/04/21 17:02:39  curt
756 // Prepairing for C++ integration.
757 //
758 // Revision 1.71  1998/04/18 04:11:26  curt
759 // Moved fg_debug to it's own library, added zlib support.
760 //
761 // Revision 1.70  1998/04/14 02:21:02  curt
762 // Incorporated autopilot heading hold contributed by:  Jeff Goeke-Smith
763 // <jgoeke@voyager.net>
764 //
765 // Revision 1.69  1998/04/08 23:35:34  curt
766 // Tweaks to Gnu automake/autoconf system.
767 //
768 // Revision 1.68  1998/04/03 22:09:03  curt
769 // Converting to Gnu autoconf system.
770 //
771 // Revision 1.67  1998/03/23 21:24:37  curt
772 // Source code formating tweaks.
773 //
774 // Revision 1.66  1998/03/14 00:31:20  curt
775 // Beginning initial terrain texturing experiments.
776 //
777 // Revision 1.65  1998/03/09 22:45:57  curt
778 // Minor tweaks for building on sparc platform.
779 //
780 // Revision 1.64  1998/02/20 00:16:23  curt
781 // Thursday's tweaks.
782 //
783 // Revision 1.63  1998/02/16 16:17:39  curt
784 // Minor tweaks.
785 //
786 // Revision 1.62  1998/02/16 13:39:42  curt
787 // Miscellaneous weekend tweaks.  Fixed? a cache problem that caused whole
788 // tiles to occasionally be missing.
789 //
790 // Revision 1.61  1998/02/12 21:59:46  curt
791 // Incorporated code changes contributed by Charlie Hotchkiss
792 // <chotchkiss@namg.us.anritsu.com>
793 //
794 // Revision 1.60  1998/02/11 02:50:40  curt
795 // Minor changes.
796 //
797 // Revision 1.59  1998/02/09 22:56:54  curt
798 // Removed "depend" files from cvs control.  Other minor make tweaks.
799 //
800 // Revision 1.58  1998/02/09 15:07:49  curt
801 // Minor tweaks.
802 //
803 // Revision 1.57  1998/02/07 15:29:40  curt
804 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
805 // <chotchkiss@namg.us.anritsu.com>
806 //
807 // Revision 1.56  1998/02/03 23:20:23  curt
808 // Lots of little tweaks to fix various consistency problems discovered by
809 // Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
810 // passed arguments along to the real printf().  Also incorporated HUD changes
811 // by Michele America.
812 //
813 // Revision 1.55  1998/02/02 20:53:58  curt
814 // Incorporated Durk's changes.
815 //
816 // Revision 1.54  1998/01/31 00:43:10  curt
817 // Added MetroWorks patches from Carmen Volpe.
818 //
819 // Revision 1.53  1998/01/27 18:35:54  curt
820 // Minor tweaks.
821 //
822 // Revision 1.52  1998/01/27 00:47:56  curt
823 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
824 // system and commandline/config file processing code.
825 //
826 // Revision 1.51  1998/01/26 15:57:05  curt
827 // Tweaks for dynamic scenery development.
828 //
829 // Revision 1.50  1998/01/19 19:27:07  curt
830 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
831 // This should simplify things tremendously.
832 //
833 // Revision 1.49  1998/01/19 18:40:31  curt
834 // Tons of little changes to clean up the code and to remove fatal errors
835 // when building with the c++ compiler.
836 //
837 // Revision 1.48  1998/01/19 18:35:46  curt
838 // Minor tweaks and fixes for cygwin32.
839 //
840 // Revision 1.47  1998/01/13 00:23:08  curt
841 // Initial changes to support loading and management of scenery tiles.  Note,
842 // there's still a fair amount of work left to be done.
843 //
844 // Revision 1.46  1998/01/08 02:22:06  curt
845 // Beginning to integrate Tile management subsystem.
846 //
847 // Revision 1.45  1998/01/07 03:18:55  curt
848 // Moved astronomical stuff from .../Src/Scenery to .../Src/Astro/
849 //
850 // Revision 1.44  1997/12/30 22:22:31  curt
851 // Further integration of event manager.
852 //
853 // Revision 1.43  1997/12/30 20:47:43  curt
854 // Integrated new event manager with subsystem initializations.
855 //
856 // Revision 1.42  1997/12/30 16:36:47  curt
857 // Merged in Durk's changes ...
858 //
859 // Revision 1.41  1997/12/30 13:06:56  curt
860 // A couple lighting tweaks ...
861 //
862 // Revision 1.40  1997/12/30 01:38:37  curt
863 // Switched back to per vertex normals and smooth shading for terrain.
864 //
865 // Revision 1.39  1997/12/22 23:45:45  curt
866 // First stab at sunset/sunrise sky glow effects.
867 //
868 // Revision 1.38  1997/12/22 04:14:28  curt
869 // Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
870 //
871 // Revision 1.37  1997/12/19 23:34:03  curt
872 // Lot's of tweaking with sky rendering and lighting.
873 //
874 // Revision 1.36  1997/12/19 16:44:57  curt
875 // Working on scene rendering order and options.
876 //
877 // Revision 1.35  1997/12/18 23:32:32  curt
878 // First stab at sky dome actually starting to look reasonable. :-)
879 //
880 // Revision 1.34  1997/12/17 23:13:34  curt
881 // Began working on rendering a sky.
882 //
883 // Revision 1.33  1997/12/15 23:54:45  curt
884 // Add xgl wrappers for debugging.
885 // Generate terrain normals on the fly.
886 //
887 // Revision 1.32  1997/12/15 20:59:08  curt
888 // Misc. tweaks.
889 //
890 // Revision 1.31  1997/12/12 21:41:25  curt
891 // More light/material property tweaking ... still a ways off.
892 //
893 // Revision 1.30  1997/12/12 19:52:47  curt
894 // Working on lightling and material properties.
895 //
896 // Revision 1.29  1997/12/11 04:43:54  curt
897 // Fixed sun vector and lighting problems.  I thing the moon is now lit
898 // correctly.
899 //
900 // Revision 1.28  1997/12/10 22:37:45  curt
901 // Prepended "fg" on the name of all global structures that didn't have it yet.
902 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
903 //
904 // Revision 1.27  1997/12/09 05:11:54  curt
905 // Working on tweaking lighting.
906 //
907 // Revision 1.26  1997/12/09 04:25:29  curt
908 // Working on adding a global lighting params structure.
909 //
910 // Revision 1.25  1997/12/08 22:54:09  curt
911 // Enabled GL_CULL_FACE.
912 //
913 // Revision 1.24  1997/11/25 19:25:32  curt
914 // Changes to integrate Durk's moon/sun code updates + clean up.
915 //
916 // Revision 1.23  1997/11/15 18:16:34  curt
917 // minor tweaks.
918 //
919 // Revision 1.22  1997/10/30 12:38:41  curt
920 // Working on new scenery subsystem.
921 //
922 // Revision 1.21  1997/09/23 00:29:38  curt
923 // Tweaks to get things to compile with gcc-win32.
924 //
925 // Revision 1.20  1997/09/22 14:44:19  curt
926 // Continuing to try to align stars correctly.
927 //
928 // Revision 1.19  1997/09/18 16:20:08  curt
929 // At dusk/dawn add/remove stars in stages.
930 //
931 // Revision 1.18  1997/09/16 22:14:51  curt
932 // Tweaked time of day lighting equations.  Don't draw stars during the day.
933 //
934 // Revision 1.17  1997/09/16 15:50:29  curt
935 // Working on star alignment and time issues.
936 //
937 // Revision 1.16  1997/09/13 02:00:06  curt
938 // Mostly working on stars and generating sidereal time for accurate star
939 // placement.
940 //
941 // Revision 1.15  1997/09/05 14:17:27  curt
942 // More tweaking with stars.
943 //
944 // Revision 1.14  1997/09/05 01:35:53  curt
945 // Working on getting stars right.
946 //
947 // Revision 1.13  1997/09/04 02:17:34  curt
948 // Shufflin' stuff.
949 //
950 // Revision 1.12  1997/08/27 21:32:24  curt
951 // Restructured view calculation code.  Added stars.
952 //
953 // Revision 1.11  1997/08/27 03:30:16  curt
954 // Changed naming scheme of basic shared structures.
955 //
956 // Revision 1.10  1997/08/25 20:27:22  curt
957 // Merged in initial HUD and Joystick code.
958 //
959 // Revision 1.9  1997/08/22 21:34:39  curt
960 // Doing a bit of reorganizing and house cleaning.
961 //
962 // Revision 1.8  1997/08/19 23:55:03  curt
963 // Worked on better simulating real lighting.
964 //
965 // Revision 1.7  1997/08/16 12:22:38  curt
966 // Working on improving the lighting/shading.
967 //
968 // Revision 1.6  1997/08/13 20:24:56  curt
969 // Changes due to changing sunpos interface.
970 //
971 // Revision 1.5  1997/08/06 21:08:32  curt
972 // Sun position now really* works (I think) ... I still have sun time warping
973 // code in place, probably should remove it soon.
974 //
975 // Revision 1.4  1997/08/06 15:41:26  curt
976 // Working on correct sun position.
977 //
978 // Revision 1.3  1997/08/06 00:24:22  curt
979 // Working on correct real time sun lighting.
980 //
981 // Revision 1.2  1997/08/04 20:25:15  curt
982 // Organizational tweaking.
983 //
984 // Revision 1.1  1997/08/02 18:45:00  curt
985 // Renamed GLmain.c GLUTmain.c
986 //
987 // Revision 1.43  1997/08/02 16:23:47  curt
988 // Misc. tweaks.
989 //
990 // Revision 1.42  1997/08/01 19:43:33  curt
991 // Making progress with coordinate system overhaul.
992 //
993 // Revision 1.41  1997/07/31 22:52:37  curt
994 // Working on redoing internal coordinate systems & scenery transformations.
995 //
996 // Revision 1.40  1997/07/30 16:12:42  curt
997 // Moved fg_random routines from Util/ to Math/
998 //
999 // Revision 1.39  1997/07/21 14:45:01  curt
1000 // Minor tweaks.
1001 //
1002 // Revision 1.38  1997/07/19 23:04:47  curt
1003 // Added an initial weather section.
1004 //
1005 // Revision 1.37  1997/07/19 22:34:02  curt
1006 // Moved PI definitions to ../constants.h
1007 // Moved random() stuff to ../Utils/ and renamed fg_random()
1008 //
1009 // Revision 1.36  1997/07/18 23:41:25  curt
1010 // Tweaks for building with Cygnus Win32 compiler.
1011 //
1012 // Revision 1.35  1997/07/18 14:28:34  curt
1013 // Hacked in some support for wind/turbulence.
1014 //
1015 // Revision 1.34  1997/07/16 20:04:48  curt
1016 // Minor tweaks to aid Win32 port.
1017 //
1018 // Revision 1.33  1997/07/12 03:50:20  curt
1019 // Added an #include <Windows32/Base.h> to help compiling for Win32
1020 //
1021 // Revision 1.32  1997/07/11 03:23:18  curt
1022 // Solved some scenery display/orientation problems.  Still have a positioning
1023 // (or transformation?) problem.
1024 //
1025 // Revision 1.31  1997/07/11 01:29:58  curt
1026 // More tweaking of terrian floor.
1027 //
1028 // Revision 1.30  1997/07/10 04:26:37  curt
1029 // We now can interpolated ground elevation for any position in the grid.  We
1030 // can use this to enforce a "hard" ground.  We still need to enforce some
1031 // bounds checking so that we don't try to lookup data points outside the
1032 // grid data set.
1033 //
1034 // Revision 1.29  1997/07/09 21:31:12  curt
1035 // Working on making the ground "hard."
1036 //
1037 // Revision 1.28  1997/07/08 18:20:12  curt
1038 // Working on establishing a hard ground.
1039 //
1040 // Revision 1.27  1997/07/07 20:59:49  curt
1041 // Working on scenery transformations to enable us to fly fluidly over the
1042 // poles with no discontinuity/distortion in scenery.
1043 //
1044 // Revision 1.26  1997/07/05 20:43:34  curt
1045 // renamed mat3 directory to Math so we could add other math related routines.
1046 //
1047 // Revision 1.25  1997/06/29 21:19:17  curt
1048 // Working on scenery management system.
1049 //
1050 // Revision 1.24  1997/06/26 22:14:53  curt
1051 // Beginning work on a scenery management system.
1052 //
1053 // Revision 1.23  1997/06/26 19:08:33  curt
1054 // Restructuring make, adding automatic "make dep" support.
1055 //
1056 // Revision 1.22  1997/06/25 15:39:47  curt
1057 // Minor changes to compile with rsxnt/win32.
1058 //
1059 // Revision 1.21  1997/06/22 21:44:41  curt
1060 // Working on intergrating the VRML (subset) parser.
1061 //
1062 // Revision 1.20  1997/06/21 17:12:53  curt
1063 // Capitalized subdirectory names.
1064 //
1065 // Revision 1.19  1997/06/18 04:10:31  curt
1066 // A couple more runway tweaks ...
1067 //
1068 // Revision 1.18  1997/06/18 02:21:24  curt
1069 // Hacked in a runway
1070 //
1071 // Revision 1.17  1997/06/17 16:51:58  curt
1072 // Timer interval stuff now uses gettimeofday() instead of ftime()
1073 //
1074 // Revision 1.16  1997/06/17 04:19:16  curt
1075 // More timer related tweaks with respect to view direction changes.
1076 //
1077 // Revision 1.15  1997/06/17 03:41:10  curt
1078 // Nonsignal based interval timing is now working.
1079 // This would be a good time to look at cleaning up the code structure a bit.
1080 //
1081 // Revision 1.14  1997/06/16 19:32:51  curt
1082 // Starting to add general timer support.
1083 //
1084 // Revision 1.13  1997/06/02 03:40:06  curt
1085 // A tiny bit more view tweaking.
1086 //
1087 // Revision 1.12  1997/06/02 03:01:38  curt
1088 // Working on views (side, front, back, transitions, etc.)
1089 //
1090 // Revision 1.11  1997/05/31 19:16:25  curt
1091 // Elevator trim added.
1092 //
1093 // Revision 1.10  1997/05/31 04:13:52  curt
1094 // WE CAN NOW FLY!!!
1095 //
1096 // Continuing work on the LaRCsim flight model integration.
1097 // Added some MSFS-like keyboard input handling.
1098 //
1099 // Revision 1.9  1997/05/30 19:27:01  curt
1100 // The LaRCsim flight model is starting to look like it is working.
1101 //
1102 // Revision 1.8  1997/05/30 03:54:10  curt
1103 // Made a bit more progress towards integrating the LaRCsim flight model.
1104 //
1105 // Revision 1.7  1997/05/29 22:39:49  curt
1106 // Working on incorporating the LaRCsim flight model.
1107 //
1108 // Revision 1.6  1997/05/29 12:31:39  curt
1109 // Minor tweaks, moving towards general flight model integration.
1110 //
1111 // Revision 1.5  1997/05/29 02:33:23  curt
1112 // Updated to reflect changing interfaces in other "modules."
1113 //
1114 // Revision 1.4  1997/05/27 17:44:31  curt
1115 // Renamed & rearranged variables and routines.   Added some initial simple
1116 // timer/alarm routines so the flight model can be updated on a regular 
1117 // interval.
1118 //
1119 // Revision 1.3  1997/05/23 15:40:25  curt
1120 // Added GNU copyright headers.
1121 // Fog now works!
1122 //
1123 // Revision 1.2  1997/05/23 00:35:12  curt
1124 // Trying to get fog to work ...
1125 //
1126 // Revision 1.1  1997/05/21 15:57:51  curt
1127 // Renamed due to added GLUT support.
1128 //
1129 // Revision 1.3  1997/05/19 18:22:42  curt
1130 // Parameter tweaking ... starting to stub in fog support.
1131 //
1132 // Revision 1.2  1997/05/17 00:17:34  curt
1133 // Trying to stub in support for standard OpenGL.
1134 //
1135 // Revision 1.1  1997/05/16 16:05:52  curt
1136 // Initial revision.
1137 //