]> git.mxchange.org Git - flightgear.git/blobdiff - Main/GLUTmain.cxx
Attempting to iron out seg faults and crashes.
[flightgear.git] / Main / GLUTmain.cxx
index b073fd5b13431ab5caeb981ad0df77832c89b2d9..a3a1761244715e52fe1d08fae3a6af29a585b4ea 100644 (file)
@@ -45,7 +45,7 @@
 #include <sys/stat.h> /* for stat() */
 
 #ifdef HAVE_UNISTD_H
-#  include <unistd.h>    /* for fork() && stat() */
+#  include <unistd.h>    /* for stat() */
 #endif
 
 #include <Include/fg_constants.h>  // for VERSION
@@ -174,76 +174,7 @@ static void fgInitVisuals( void ) {
 }
 
 
-// Update the view volume, position, and orientation
-static void fgUpdateViewParams( void ) {
-    fgFLIGHT *f;
-    fgLIGHT *l;
-    fgVIEW *v;
-
-    f = current_aircraft.flight;
-    l = &cur_light_params;
-    v = &current_view;
-
-    v->Update(f);
-    v->UpdateWorldToEye(f);
-
-    // if (!o->panel_status) {
-    // xglViewport( 0, (GLint)((v->winHeight) / 2 ) , 
-    // (GLint)(v->winWidth), (GLint)(v->winHeight) / 2 );
-    // Tell GL we are about to modify the projection parameters
-    // xglMatrixMode(GL_PROJECTION);
-    // xglLoadIdentity();
-    // gluPerspective(o->fov, v->win_ratio / 2.0, 1.0, 100000.0);
-    // } else {
-    xglViewport(0, 0 , (GLint)(v->winWidth), (GLint)(v->winHeight) );
-    // Tell GL we are about to modify the projection parameters
-    xglMatrixMode(GL_PROJECTION);
-    xglLoadIdentity();
-    if ( FG_Altitude * FEET_TO_METER - scenery.cur_elev > 10.0 ) {
-       gluPerspective(current_options.get_fov(), v->win_ratio, 10.0, 100000.0);
-    } else {
-       gluPerspective(current_options.get_fov(), v->win_ratio, 1.0, 100000.0);
-       // printf("Near ground, minimizing near clip plane\n");
-    }
-    // }
-
-    xglMatrixMode(GL_MODELVIEW);
-    xglLoadIdentity();
-    
-    // set up our view volume (default)
-    fg_gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
-              v->view_pos.x + v->view_forward[0], 
-              v->view_pos.y + v->view_forward[1], 
-              v->view_pos.z + v->view_forward[2],
-              v->view_up[0], v->view_up[1], v->view_up[2]);
-
-    // look almost straight up (testing and eclipse watching)
-    /* fg_gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
-              v->view_pos.x + v->view_up[0] + .001, 
-              v->view_pos.y + v->view_up[1] + .001, 
-              v->view_pos.z + v->view_up[2] + .001,
-              v->view_up[0], v->view_up[1], v->view_up[2]); */
-
-    // lock view horizontally towards sun (testing)
-    /* fg_gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
-              v->view_pos.x + v->surface_to_sun[0], 
-              v->view_pos.y + v->surface_to_sun[1], 
-              v->view_pos.z + v->surface_to_sun[2],
-              v->view_up[0], v->view_up[1], v->view_up[2]); */
-
-    // lock view horizontally towards south (testing)
-    /* fg_gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
-              v->view_pos.x + v->surface_south[0], 
-              v->view_pos.y + v->surface_south[1], 
-              v->view_pos.z + v->surface_south[2],
-              v->view_up[0], v->view_up[1], v->view_up[2]); */
-
-    // set the sun position
-    xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
-}
-
-
-#ifdef 0
+#ifdef IS_THIS_BETTER_THAN_A_ZERO_CHARLIE
 // Draw a basic instrument panel
 static void fgUpdateInstrViewParams( void ) {
 
@@ -298,7 +229,7 @@ static void fgRenderFrame( void ) {
     fgTIME *t;
     fgVIEW *v;
     double angle;
-    GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
+    // GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
     GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
     GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
     GLbitfield clear_mask;
@@ -322,11 +253,11 @@ static void fgRenderFrame( void ) {
        //        FG_Altitude * FEET_TO_METER);
     
        // this is just a temporary hack, to make me understand Pui
-       timerText -> setLabel (ctime (&t->cur_time));
+       // timerText -> setLabel (ctime (&t->cur_time));
        // end of hack
 
        // update view volume parameters
-       fgUpdateViewParams();
+       v->UpdateViewParams();
 
        clear_mask = GL_DEPTH_BUFFER_BIT;
        if ( current_options.get_wireframe() ) {
@@ -335,8 +266,8 @@ static void fgRenderFrame( void ) {
        if ( current_options.get_skyblend() ) {
            if ( current_options.get_textures() ) {
                // glClearColor(black[0], black[1], black[2], black[3]);
-               glClearColor(l->fog_color[0], l->fog_color[1], 
-                            l->fog_color[2], l->fog_color[3]);
+               glClearColor(l->adj_fog_color[0], l->adj_fog_color[1], 
+                            l->adj_fog_color[2], l->adj_fog_color[3]);
                clear_mask |= GL_COLOR_BUFFER_BIT;              
            }
        } else {
@@ -379,6 +310,7 @@ static void fgRenderFrame( void ) {
 
        // render the moon
        xglEnable( GL_LIGHTING );
+       xglEnable( GL_LIGHT0 );
        // set lighting parameters
        xglLightfv(GL_LIGHT0, GL_AMBIENT, white );
        xglLightfv(GL_LIGHT0, GL_DIFFUSE, white );
@@ -401,7 +333,7 @@ static void fgRenderFrame( void ) {
        xglEnable( GL_DEPTH_TEST );
        if ( current_options.get_fog() > 0 ) {
            xglEnable( GL_FOG );
-           xglFogfv (GL_FOG_COLOR, l->fog_color);
+           xglFogfv (GL_FOG_COLOR, l->adj_fog_color);
        }
        // set lighting parameters
        xglLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_ambient );
@@ -449,11 +381,13 @@ static void fgRenderFrame( void ) {
 // Update internal time dependent calculations (i.e. flight model)
 void fgUpdateTimeDepCalcs(int multi_loop) {
     fgFLIGHT *f;
+    fgLIGHT *l;
     fgTIME *t;
     fgVIEW *v;
     int i;
 
     f = current_aircraft.flight;
+    l = &cur_light_params;
     t = &cur_time_params;
     v = &current_view;
 
@@ -462,8 +396,12 @@ void fgUpdateTimeDepCalcs(int multi_loop) {
        multi_loop = DEFAULT_MULTILOOP;
     }
 
-    // printf("updating flight model x %d\n", multi_loop);
-    fgFlightModelUpdate(FG_LARCSIM, f, multi_loop);
+    if ( !t->pause ) {
+       // printf("updating flight model x %d\n", multi_loop);
+       fgFlightModelUpdate(current_options.get_flight_model(), f, multi_loop);
+    } else {
+       fgFlightModelUpdate(current_options.get_flight_model(), f, 0);
+    }
 
     // update the view angle
     for ( i = 0; i < multi_loop; i++ ) {
@@ -492,6 +430,18 @@ void fgUpdateTimeDepCalcs(int multi_loop) {
            }
        }
     }
+
+    double tmp = -(l->sun_rotation + FG_PI) - (FG_Psi - v->view_offset);
+    while ( tmp < 0.0 ) {
+       tmp += FG_2PI;
+    }
+    while ( tmp > FG_2PI ) {
+       tmp -= FG_2PI;
+    }
+    /* printf("Psi = %.2f, viewoffset = %.2f sunrot = %.2f rottosun = %.2f\n",
+          FG_Psi * RAD_TO_DEG, v->view_offset * RAD_TO_DEG, 
+          -(l->sun_rotation+FG_PI) * RAD_TO_DEG, tmp * RAD_TO_DEG); */
+    l->UpdateAdjFog();
 }
 
 
@@ -541,7 +491,7 @@ static void fgMainLoop( void ) {
                   FG_Altitude * FEET_TO_METER,
                   scenery.cur_elev + 3.758099 * FEET_TO_METER - 3.0,
                   scenery.cur_elev + 3.758099 * FEET_TO_METER);
-           fgFlightModelSetAltitude( FG_LARCSIM, f, 
+           fgFlightModelSetAltitude( current_options.get_flight_model(), f, 
                                      scenery.cur_elev + 
                                      3.758099 * FEET_TO_METER);
 
@@ -625,7 +575,9 @@ static void fgMainLoop( void ) {
 
     // Run audio scheduler
 #ifdef ENABLE_AUDIO_SUPPORT
-    audio_sched -> update();
+    if ( current_options.get_sound() ) {
+       audio_sched -> update();
+    }
 #endif
 
     // redraw display
@@ -672,7 +624,7 @@ static void fgIdleFunction ( void ) {
                    lockfile, mp3file, lockfile );
            fgPrintf( FG_GENERAL, FG_INFO, 
                      "Starting intro music: %s\n", mp3file);
-           system(command);
+           system ( command );
        }
 #endif
 
@@ -680,10 +632,7 @@ static void fgIdleFunction ( void ) {
     } else if ( idle_state == 2 ) {
        // These are a few miscellaneous things that aren't really
        // "subsystems" but still need to be initialized.
-       if( !fgInitGeneral()) {
-           fgPrintf( FG_GENERAL, FG_EXIT, 
-                     "General initializations failed ...\n" );
-       }
+
 #ifdef USE_GLIDE
        if ( strstr ( g->glRenderer, "Glide" ) ) {
            grTexLodBiasValue ( GR_TMU0, 1.0 ) ;
@@ -714,8 +663,6 @@ static void fgIdleFunction ( void ) {
 
        idle_state++;
     } else if ( idle_state == 5 ) {
-       //Init the user interface
-       guiInit();
 
        idle_state++;
     } else if ( idle_state == 6 ) {
@@ -740,7 +687,7 @@ static void fgIdleFunction ( void ) {
 
        audio_sched = new slScheduler ( 8000 );
        audio_mixer = new smMixer;
-       audio_mixer -> setMasterVolume ( 30 ) ;  /* 50% of max volume. */
+       audio_mixer -> setMasterVolume ( 80 ) ;  /* 80% of max volume. */
        audio_sched -> setSafetyMargin ( 1.0 ) ;
        current_options.get_fg_root(path);
        strcat(path, "/Sounds/");
@@ -748,8 +695,6 @@ static void fgIdleFunction ( void ) {
        strcat(slfile, "wasp.wav");
 
        s1 = new slSample ( slfile );
-       // s1 = new slSample ( "/dos/X-System-HSR/sounds/xp_recip.wav", 
-       //                     audio_sched );
        printf("Rate = %d  Bps = %d  Stereo = %d\n", 
               s1 -> getRate(), s1 -> getBps(), s1 -> getStereo());
        audio_sched -> loopSample ( s1 );
@@ -761,7 +706,7 @@ static void fgIdleFunction ( void ) {
        // audio_sched -> playSample ( s2 );
 #endif
 
-       sleep(1);
+       // sleep(1);
        idle_state = 1000;
     } 
 
@@ -799,7 +744,7 @@ static void fgReshape( int width, int height ) {
        // yes we've finished all our initializations and are running
        // the main loop, so this will now work without seg faulting
        // the system.
-       fgUpdateViewParams();
+       v->UpdateViewParams();
     }
     
     // xglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
@@ -819,7 +764,14 @@ int fgGlutInit( int *argc, char **argv ) {
     xglutInitWindowSize(640, 480);
 
     // Initialize windows
-    xglutCreateWindow("Flight Gear");
+    if ( current_options.get_game_mode() == 0 ) {
+       // Open the regular window
+       xglutCreateWindow("Flight Gear");
+    } else {
+       // Open the cool new 'game mode' window
+       glutGameModeString("width=640 height=480 bpp=16");
+       glutEnterGameMode();
+    }
 
     return(1);
 }
@@ -867,17 +819,6 @@ int main( int argc, char **argv ) {
 
     fgPrintf(FG_GENERAL, FG_INFO, "Flight Gear:  Version %s\n\n", VERSION);
 
-    // Initialize the Window/Graphics environment.
-    if( !fgGlutInit(&argc, argv) ) {
-       fgPrintf( FG_GENERAL, FG_EXIT, "GLUT initialization failed ...\n" );
-    }
-
-    // Initialize the various GLUT Event Handlers.
-    if( !fgGlutInitEvents() ) {
-       fgPrintf( FG_GENERAL, FG_EXIT, 
-                 "GLUT event handler initialization failed ...\n" );
-    }
-
     // Attempt to locate and parse a config file
     // First check fg_root
     current_options.get_fg_root(config);
@@ -900,6 +841,27 @@ int main( int argc, char **argv ) {
        current_options.usage();
        fgPrintf( FG_GENERAL, FG_EXIT, "\nExiting ...\n");
     }
+    
+    // Initialize the Window/Graphics environment.
+    if( !fgGlutInit(&argc, argv) ) {
+       fgPrintf( FG_GENERAL, FG_EXIT, "GLUT initialization failed ...\n" );
+    }
+
+    // Initialize the various GLUT Event Handlers.
+    if( !fgGlutInitEvents() ) {
+       fgPrintf( FG_GENERAL, FG_EXIT, 
+                 "GLUT event handler initialization failed ...\n" );
+    }
+
+    // First do some quick general initializations
+    if( !fgInitGeneral()) {
+       fgPrintf( FG_GENERAL, FG_EXIT, 
+                 "General initializations failed ...\n" );
+    }
+
+    // Init the user interface (we need to do this before passing off
+    // control to glut
+    guiInit();
 
     // pass control off to the master GLUT event handler
     glutMainLoop();
@@ -910,6 +872,45 @@ int main( int argc, char **argv ) {
 
 
 // $Log$
+// Revision 1.46  1998/08/22 14:49:56  curt
+// Attempting to iron out seg faults and crashes.
+// Did some shuffling to fix a initialization order problem between view
+// position, scenery elevation.
+//
+// Revision 1.45  1998/08/20 20:32:31  curt
+// Reshuffled some of the code in and around views.[ch]xx
+//
+// Revision 1.44  1998/08/20 15:10:33  curt
+// Added GameGLUT support.
+//
+// Revision 1.43  1998/08/12 21:01:47  curt
+// Master volume from 30% -> 80%
+//
+// Revision 1.42  1998/07/30 23:48:25  curt
+// Output position & orientation when pausing.
+// Eliminated libtool use.
+// Added options to specify initial position and orientation.
+// Changed default fov to 55 degrees.
+// Added command line option to start in paused or unpaused state.
+//
+// Revision 1.41  1998/07/27 18:41:24  curt
+// Added a pause command "p"
+// Fixed some initialization order problems between pui and glut.
+// Added an --enable/disable-sound option.
+//
+// Revision 1.40  1998/07/24 21:56:59  curt
+// Set near clip plane to 0.5 meters when close to the ground.  Also, let the view get a bit closer to the ground before hitting the hard limit.
+//
+// Revision 1.39  1998/07/24 21:39:08  curt
+// Debugging output tweaks.
+// Cast glGetString to (char *) to avoid compiler errors.
+// Optimizations to fgGluLookAt() by Norman Vine.
+//
+// Revision 1.38  1998/07/22 21:40:43  curt
+// Clear to adjusted fog color (for sunrise/sunset effects)
+// Make call to fog sunrise/sunset adjustment method.
+// Add a stdc++ library bug work around to fg_init.cxx
+//
 // Revision 1.37  1998/07/20 12:49:44  curt
 // Tweaked color buffer clearing defaults.  We clear the color buffer if we
 // are doing textures.  Assumptions:  If we are doing textures we have hardware