]> git.mxchange.org Git - flightgear.git/blobdiff - Main/GLUTmain.c
Tweaks to Gnu automake/autoconf system.
[flightgear.git] / Main / GLUTmain.c
index a5ac4bc61358c1337ac6f4dd1aa7372f27fddf01..0dd996cdefaacadf8dc76f14f9218a8a80389904 100644 (file)
@@ -24,7 +24,9 @@
  **************************************************************************/
 
 
-#ifdef WIN32
+#include <config.h>
+
+#ifdef HAVE_WINDOWS_H
 #  include <windows.h>                     
 #endif
 
 #include <XGL/xgl.h>
 #include <stdio.h>
 
+#ifdef HAVE_STDLIB_H
+#   include <stdlib.h>
+#endif
+#ifdef HAVE_GETOPT_H
+#   include <getopt.h>
+#endif
+
 #include <Main/GLUTkey.h>
 #include <Main/fg_init.h>
 #include <Main/fg_debug.h>
+#include <Main/fg_getopt.h>
 #include <Main/views.h>
 
-#include <Include/fg_constants.h>
+#include <Include/cmdargs.h>       // Line to command line arguments
+#include <Include/fg_constants.h>  // for VERSION
 #include <Include/general.h>
 
 #include <Aircraft/aircraft.h>
@@ -61,7 +72,7 @@
 
 
 /* This is a record containing global housekeeping information */
-struct fgGENERAL general;
+fgGENERAL general;
 
 /* view parameters */
 static GLfloat win_ratio = 1.0;
@@ -82,21 +93,117 @@ int show_hud;
 /* Yet another other hack. Used for my prototype instrument code. (Durk) */
 int displayInstruments; 
 
-
+// The following defines flight gear options. Because glutlib will also
+// want to parse its own options, those options must not be included here
+// or they will get parsed by the main program option parser. Hence case
+// is significant for any option added that might be in conflict with
+// glutlib's parser.
+//
+// glutlib parses for:
+//    -display
+//    -direct   (invalid in Win32)
+//    -geometry
+//    -gldebug
+//    -iconized
+//    -indirect (invalid in Win32)
+//    -synce
+//
+// Note that glutlib depends upon strings while this program's
+// option parser wants only initial characters followed by numbers
+// or pathnames.
+//
+const char *fg_cmdargopts = "a:c:Hhp:r:v:x:?";
+//
+// Where
+//   -a aircraftfilename    aircraft start over ride
+//   -c0x0000 - 0xffffffff  debug class setting
+//    H,h.? help on command line use (does not need Option struct)
+//   -p  priority
+//   -r flightgear          root path to program support files
+//   -v0 -v1                initial view mode (hud/no_hud currently)
+//   -xlogpathname          debug logfile name
+//
+// Defaults in arguments to indicate not set on command line.
+// Program defaults set variables from constants if neither command
+// options or environmental variables effect values.
+//
+
+char  acArgbuf          [ MAXPATH + 1] = "\0";
+int   debugArgValue                    = -2;
+int   priorityArgValue                 = -1;
+char  rootArgbuf        [ MAXPATH + 1] = "\0";
+int   viewArg                          = -1;
+char  logArgbuf         [ MAXPATH + 1] = "\0";
+
+// There is a reason for defining the option structs by name and then
+// creating an array of pointers to options. C++ is unfriendly to
+// initializing arrays of objects that are not built in types. Always
+// look forward. (Besides, you can follow what is going on better and
+// add or modify with greater security. -ch
+//
+Option aircraftOption = { 'a',
+                          OPT_STRING,
+                          acArgbuf,
+                          "Startup aircraft pathname override"
+                        };
+Option debugOption    = { 'c',
+                          OPT_LHEX,       // Long int (32 bits)
+                          &debugArgValue,
+                          "Debug trace level"
+                        };
+Option priorityOption = { 'p',
+                          OPT_INTEGER,
+                          &priorityArgValue,
+                          "Debug priority Threshold"
+                        };
+Option rootOption     = { 'r',
+                          OPT_STRING,
+                          rootArgbuf,
+                          "Root directory for execution"
+                        };
+Option hudOption      = { 'v',
+                          OPT_INTEGER,
+                          &viewArg,
+                          "View mode start" // Naked,HUD,Panel,Chase,Tower...
+                        };
+//
+// Only naked view and HUD are implemented at this time
+//
+Option logfileOption  = { 'x',
+                          OPT_STRING,
+                          logArgbuf,
+                          "Debug log file name"
+                        };
+
+//
+#define OptsDefined 6
+Option *CmdLineOptions[ OptsDefined ] = {
+  &aircraftOption,
+  &debugOption,
+  &hudOption,
+  &priorityOption,
+  &rootOption,
+  &logfileOption
+  };
+
+const char *DefaultRootDir  = "\\Flightgear";
+const char *DefaultAircraft = "Navion.acf";
+const char *DefaultDebuglog = "fgdebug.log";
+const int   DefaultViewMode = HUD_VIEW;
+//
+// Debug defaults handled in fg_debug.c
+//
 /**************************************************************************
  * fgInitVisuals() -- Initialize various GL/view parameters
  **************************************************************************/
 
 static void fgInitVisuals( void ) {
     struct fgLIGHT *l;
-    struct fgTIME *t;
     struct fgWEATHER *w;
 
     l = &cur_light_params;
-    t = &cur_time_params;
     w = &current_weather;
 
-    
     /* xglDisable( GL_DITHER ); */
 
     /* If enabled, normal vectors specified with glNormal are scaled
@@ -108,7 +215,7 @@ static void fgInitVisuals( void ) {
     xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
 
     xglFogi (GL_FOG_MODE, GL_LINEAR);
-    /* xglFogf (GL_FOG_START, 1.0); */
+    xglFogf (GL_FOG_START, 10.0);
     xglFogf (GL_FOG_END, w->visibility);
     /* xglFogf (GL_FOG_DENSITY, w->visibility); */
     xglHint (GL_FOG_HINT, GL_NICEST /* GL_FASTEST */ );
@@ -125,12 +232,12 @@ static void fgInitVisuals( void ) {
 static void fgUpdateViewParams( void ) {
     fgFLIGHT *f;
     struct fgLIGHT *l;
-    struct fgTIME *t;
+//  struct fgTIME *t;
     struct fgVIEW *v;
 
     f = current_aircraft.flight;
     l = &cur_light_params;
-    t = &cur_time_params;
+//  t = &cur_time_params;
     v = &current_view;
 
     fgViewUpdate(f, v, l);
@@ -138,10 +245,10 @@ static void fgUpdateViewParams( void ) {
     if (displayInstruments)
       {
        xglViewport(0, (GLint)(winHeight / 2 ) , (GLint)winWidth, (GLint)winHeight / 2);
-       /* Tell GL we are about to modify the projection parameters */    
+       /* Tell GL we are about to modify the projection parameters */
        xglMatrixMode(GL_PROJECTION);
        xglLoadIdentity();
-       gluPerspective(55.0, 2.0/win_ratio, 1.0, 100000.0);
+       gluPerspective(45.0, 2.0/win_ratio, 1.0, 100000.0);
       }
     else
       {
@@ -149,7 +256,7 @@ static void fgUpdateViewParams( void ) {
        /* Tell GL we are about to modify the projection parameters */    
        xglMatrixMode(GL_PROJECTION);
        xglLoadIdentity();
-       gluPerspective(55.0, 1.0/win_ratio, 1.0, 100000.0);
+       gluPerspective(45.0, 1.0/win_ratio, 10.0, 100000.0);
       }
 
     xglMatrixMode(GL_MODELVIEW);
@@ -162,6 +269,13 @@ static void fgUpdateViewParams( void ) {
               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) */
+    /* 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) */
     /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
               v->view_pos.x + v->surface_to_sun[0], 
@@ -195,7 +309,7 @@ static void fgUpdateInstrViewParams( void ) {
     xglMatrixMode(GL_MODELVIEW);
     xglPushMatrix();
     xglLoadIdentity();
-    
+
     xglColor3f(1.0, 1.0, 1.0);
     xglIndexi(7);
   
@@ -286,15 +400,26 @@ static void fgRenderFrame( void ) {
     xglPopMatrix();
 
     /* draw scenery */
-    xglShadeModel( GL_SMOOTH ); 
+    xglShadeModel( /* GL_FLAT */ GL_SMOOTH ); 
     xglEnable( GL_DEPTH_TEST );
     xglEnable( GL_FOG );
     xglFogfv (GL_FOG_COLOR, l->fog_color);
     /* set lighting parameters */
     xglLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_ambient );
     xglLightfv(GL_LIGHT0, GL_DIFFUSE, l->scene_diffuse );
+    /* texture parameters */
+    xglEnable( GL_TEXTURE_2D ); /* xglDisable( GL_TEXTURE_2D ); */
+    xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ) ;
+    xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ) ;
+    xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) ;
+    xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
+                     GL_LINEAR /* GL_LINEAR_MIPMAP_LINEAR */ ) ;
+    xglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
+    xglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
+
     fgTileMgrRender();
-    /* fgSceneryRender(); */
+
+    xglDisable( GL_TEXTURE_2D );
 
     /* display HUD */
     if( show_hud ) {
@@ -306,9 +431,7 @@ static void fgRenderFrame( void ) {
        fgUpdateInstrViewParams();
     }
 
-    #ifdef GLUT
-      xglutSwapBuffers();
-    #endif
+    xglutSwapBuffers();
 }
 
 
@@ -367,9 +490,9 @@ void fgUpdateTimeDepCalcs(int multi_loop) {
 void fgInitTimeDepCalcs( void ) {
     /* initialize timer */
 
-#ifdef USE_ITIMER
+#ifdef HAVE_SETITIMER
     fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs );
-#endif USE_ITIMER
+#endif HAVE_SETITIMER
 
 }
 
@@ -490,14 +613,17 @@ static void fgMainLoop( void ) {
 
     /* Calculate model iterations needed */
     elapsed = fgGetTimeInterval();
-    fgPrintf( FG_ALL, FG_BULK, "Time interval is = %d, previous remainder is = %d\n", 
+    fgPrintf( FG_ALL, FG_BULK, 
+             "Time interval is = %d, previous remainder is = %d\n", 
              elapsed, remainder);
-    fgPrintf( FG_ALL, FG_BULK, "--> Frame rate is = %.2f\n", 1000.0 / (float)elapsed);
+    fgPrintf( FG_ALL, FG_BULK, 
+             "--> Frame rate is = %.2f\n", 1000.0 / (float)elapsed);
     elapsed += remainder;
 
-    multi_loop = ((float)elapsed * 0.001) * DEFAULT_MODEL_HZ;
+    multi_loop = (int)(((float)elapsed * 0.001) * DEFAULT_MODEL_HZ);
     remainder = elapsed - ((multi_loop*1000) / DEFAULT_MODEL_HZ);
-    fgPrintf( FG_ALL, FG_BULK, "Model iterations needed = %d, new remainder = %d\n", 
+    fgPrintf( FG_ALL, FG_BULK, 
+             "Model iterations needed = %d, new remainder = %d\n", 
              multi_loop, remainder);
 
     /* Run flight model */
@@ -572,85 +698,161 @@ static void fgReshape( int width, int height ) {
 
 int main( int argc, char *argv[] ) {
     fgFLIGHT *f;
+    int parse_result;  // Used in command line argument.
 
     f = current_aircraft.flight;
+    //  First things first... We must have startup options dealt with.
 
     printf("Flight Gear:  Version %s\n\n", VERSION);
 
-    /**********************************************************************
+     /*********************************************************************
      * Initialize the Window/Graphics environment.
      **********************************************************************/
 
-    #ifdef GLUT
-      /* initialize GLUT */
-      xglutInit(&argc, argv);
+    /* initialize GLUT */
+    xglutInit(&argc, argv);
 
-      /* Define Display Parameters */
-      xglutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
+    /* Define Display Parameters */
+    xglutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
 
-      /* Define initial window size */
-      xglutInitWindowSize(640, 480);
+    /* Define initial window size */
+    xglutInitWindowSize(640, 480);
 
-      /* Initialize windows */
-      xglutCreateWindow("Flight Gear");
-    #endif
+    /* Initialize windows */
+    xglutCreateWindow("Flight Gear");
 
-    /* This is the general house keeping init routine */
-    fgInitGeneral();
+    // xglutInit above will extract all non-general program command line.
+    // We only need wory about our own.
 
-    /* This is the top level init routine which calls all the other
-     * subsystem initialization routines.  If you are adding a
-     * subsystem to flight gear, its initialization call should
-     * located in this routine.*/
-    fgInitSubsystems();
+    parse_result = getargs( argc, argv, OptsDefined, CmdLineOptions, NULL);
 
-    /* setup view parameters, only makes GL calls */
-    fgInitVisuals();
+    switch( parse_result ) {
+    case ALLDONE:
+       break;
 
-    if ( use_signals ) {
-       /* init timer routines, signals, etc.  Arrange for an alarm
-          signal to be generated, etc. */
-       fgInitTimeDepCalcs();
+    case HELP:
+        print_desc( OptsDefined, CmdLineOptions );
+        exit(0);
+
+    case INVALID:
+    default:
+        printf( "Flight Gear: Command line invalid.");
+        exit(0);
     }
 
-   /**********************************************************************
-     * Initialize the Event Handlers.
-     **********************************************************************/
+    // Deal with the effects of options no set by manipulating the command
+    // line, or possibly set to invalid states.
+
+    if(( viewArg >= 0) && (viewArg <= 1)) {
+       show_hud = viewArg; // For now view_mode TRUE - no HUD, else show_hud.
+    } else {
+       show_hud = DefaultViewMode;
+    }
+
+    // All other command line option responses are handled in the various
+    // initialization routines (or ignored if not implemented.
+
+    // This is the general house keeping init routine. It initializes the
+    // debug trail scheme and then any other stuff.
 
-    #ifdef GLUT
-      /* call fgReshape() on window resizes */
-      xglutReshapeFunc( fgReshape );
+    if( !fgInitGeneral()) {
 
-      /* call key() on keyboard event */
-      xglutKeyboardFunc( GLUTkey );
-      glutSpecialFunc( GLUTspecialkey );
+       // This is the top level init routine which calls all the other
+       // subsystem initialization routines.  If you are adding a
+       // subsystem to flight gear, its initialization call should
+       // located in this routine.
+       if( !fgInitSubsystems()) {
 
-      /* call fgMainLoop() whenever there is nothing else to do */
-      xglutIdleFunc( fgMainLoop );
+           // setup view parameters, only makes GL calls
+           fgInitVisuals();
 
-      /* draw the scene */
-      xglutDisplayFunc( fgRenderFrame );
+           if ( use_signals ) {
+               /* init timer routines, signals, etc.  Arrange for an alarm
+                  signal to be generated, etc. */
+               fgInitTimeDepCalcs();
+           }
+
+           /**********************************************************
+            * Initialize the GLUT Event Handlers.
+            **********************************************************/
+
+           // call fgReshape() on window resizes
+           xglutReshapeFunc( fgReshape );
+
+           // call key() on keyboard event
+           xglutKeyboardFunc( GLUTkey );
+           glutSpecialFunc( GLUTspecialkey );
+
+           // call fgMainLoop() whenever there is
+           // nothing else to do
+           xglutIdleFunc( fgMainLoop );
+
+           // draw the scene
+           xglutDisplayFunc( fgRenderFrame );
 
-      /* pass control off to the GLUT event handler */
-      glutMainLoop();
-    #endif
+           // pass control off to the GLUT event handler
+           glutMainLoop();
 
+        }  // End if subsystems initialize ok
+    } // End if general initializations went ok
+
+    if( fg_DebugOutput ) {
+       fclose( fg_DebugOutput );
+    }
     return(0);
 }
 
 
 #ifdef __SUNPRO_CC
-    extern "C" {
-       void __eprintf( void ) {
-       }
+extern "C" {
+    void __eprintf( void ) {
     }
+}
 #endif
 
 /* $Log$
-/* Revision 1.57  1998/02/07 15:29:40  curt
-/* Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
-/* <chotchkiss@namg.us.anritsu.com>
+/* Revision 1.69  1998/04/08 23:35:34  curt
+/* Tweaks to Gnu automake/autoconf system.
 /*
+ * Revision 1.68  1998/04/03 22:09:03  curt
+ * Converting to Gnu autoconf system.
+ *
+ * Revision 1.67  1998/03/23 21:24:37  curt
+ * Source code formating tweaks.
+ *
+ * Revision 1.66  1998/03/14 00:31:20  curt
+ * Beginning initial terrain texturing experiments.
+ *
+ * Revision 1.65  1998/03/09 22:45:57  curt
+ * Minor tweaks for building on sparc platform.
+ *
+ * Revision 1.64  1998/02/20 00:16:23  curt
+ * Thursday's tweaks.
+ *
+ * Revision 1.63  1998/02/16 16:17:39  curt
+ * Minor tweaks.
+ *
+ * Revision 1.62  1998/02/16 13:39:42  curt
+ * Miscellaneous weekend tweaks.  Fixed? a cache problem that caused whole
+ * tiles to occasionally be missing.
+ *
+ * Revision 1.61  1998/02/12 21:59:46  curt
+ * Incorporated code changes contributed by Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
+ * Revision 1.60  1998/02/11 02:50:40  curt
+ * Minor changes.
+ *
+ * Revision 1.59  1998/02/09 22:56:54  curt
+ * Removed "depend" files from cvs control.  Other minor make tweaks.
+ *
+ * Revision 1.58  1998/02/09 15:07:49  curt
+ * Minor tweaks.
+ *
+ * Revision 1.57  1998/02/07 15:29:40  curt
+ * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
+ * <chotchkiss@namg.us.anritsu.com>
+ *
  * Revision 1.56  1998/02/03 23:20:23  curt
  * Lots of little tweaks to fix various consistency problems discovered by
  * Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper