]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/main.cxx
Removed cloud layers added for testing.
[flightgear.git] / src / Main / main.cxx
index d457557ebdd3614fe69360de46077f2a95407434..05414d4cd278dfd4b3cbc2e0556dee7229c19fba 100644 (file)
@@ -35,7 +35,7 @@
 #endif
 
 #include <GL/glut.h>
-#include <simgear/xgl/xgl.h>
+#include <GL/gl.h>
 
 #include <stdio.h>
 #include <string.h>
 #  include <unistd.h>          // for stat()
 #endif
 
+// #ifdef HAVE_LIBX11
+// #  include <GL/glext.h>
+// #endif
+
 #include <plib/pu.h>
 #include <plib/ssg.h>
 
@@ -81,6 +85,7 @@
 #ifdef FG_NETWORK_OLK
 #include <NetworkOLK/network.h>
 #endif
+#include <Objects/matlib.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
 #ifdef ENABLE_AUDIO_SUPPORT
@@ -365,7 +370,7 @@ void fgRenderFrame( void ) {
 
        sgVec3 po;              // chase view pilot_offset
        sgVec3 wup;             // chase view world up
-       sgSetVec3( po, 0.0, 0.0, 50.0 );
+       sgSetVec3( po, 0.0, 0.0, 100.0 );
        sgCopyVec3( wup, pilot_view->get_world_up() );
        sgMat4 CXFM;            // chase view + pilot offset xform
        sgMakeRotMat4( CXFM,
@@ -490,7 +495,7 @@ void fgRenderFrame( void ) {
            // cout << "----> updating fog params" << endl;
                
            // for GL_FOG_EXP
-           fog_exp_density = -log(0.01 / actual_visibility);
+           fog_exp_density = -log(0.01) / actual_visibility;
     
            // for GL_FOG_EXP2
            fog_exp2_density = sqrt( -log(0.01) ) / actual_visibility;
@@ -555,7 +560,7 @@ void fgRenderFrame( void ) {
        }
 
        glEnable( GL_DEPTH_TEST );
-       if ( fgGetString("/sim/rendering/fog") != "disabled" ) {
+       if ( fgGetString("/sim/rendering/fog") != (string)"disabled" ) {
            glEnable( GL_FOG );
            glFogi( GL_FOG_MODE, GL_EXP2 );
            glFogfv( GL_FOG_COLOR, l->adj_fog_color );
@@ -565,13 +570,14 @@ void fgRenderFrame( void ) {
        ssgGetLight( 0 ) -> setPosition( l->sun_vec );
 
         // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
-        // we only set GL_AMBIENT we will never get a completely dark
-        // scene.  Thus instead of playing with GL_AMBIENT, we just
-        // set that to black and instead modify GL_LIGHT_MODEL_AMBIENT.
+        // we only update GL_AMBIENT for our lights we will never get
+        // a completely dark scene.  So, we set GL_LIGHT_MODEL_AMBIENT
+        // explicitely to black.
        GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
-       ssgGetLight( 0 ) -> setColour( GL_AMBIENT, black );
+       GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
+       glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
 
-       glLightModelfv( GL_LIGHT_MODEL_AMBIENT, l->scene_ambient );
+       ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
        ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
        // ssgGetLight( 0 ) -> setColour( GL_SPECULAR, l->scene_white );
 
@@ -678,7 +684,14 @@ void fgRenderFrame( void ) {
 
        if ( fgGetBool("/sim/rendering/skyblend") ) {
            // draw the sky backdrop
+
+            // we need a white diffuse light for the phase of the moon
+            ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
+
            thesky->preDraw();
+
+            // return to the desired diffuse color
+            ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
        }
 
        // draw the ssg scene
@@ -779,9 +792,9 @@ void fgUpdateTimeDepCalcs() {
        cur_fdm_state->update( 0 );
        FGSteam::update( 0 );
 
-       if ( global_tile_mgr.queue_size() == 0 ) {
+       //if ( global_tile_mgr.queue_size() == 0 ) {
            initial_freeze = false;
-       }
+           //}
     }
 
     if ( fgGetString("/sim/view-mode") == "pilot" ) {
@@ -1022,8 +1035,13 @@ static void fgMainLoop( void ) {
 #endif
 
     // see if we need to load any new scenery tiles
-    global_tile_mgr.update( cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES,
-                           cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES );
+    global_tile_mgr.update( cur_fdm_state->get_Longitude()
+                            * SGD_RADIANS_TO_DEGREES,
+                           cur_fdm_state->get_Latitude()
+                            * SGD_RADIANS_TO_DEGREES );
+
+    // see if we need to load any deferred-load textures
+    material_lib.load_next_deferred();
 
     // Process/manage pending events
     global_events.Process();
@@ -1371,9 +1389,7 @@ int main( int argc, char **argv ) {
     // Allocate global data structures.  This needs to happen before
     // we parse command line options
 
-    SGPropertyNode *props = new SGPropertyNode;
     globals = new FGGlobals;
-    globals->set_props( props );
 
     // seed the random number generater
     sg_srandom_time();
@@ -1436,6 +1452,20 @@ int main( int argc, char **argv ) {
     // fonts !!!
     guiInit();
 
+#ifdef GL_EXT_texture_lod_bias
+    glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ;
+#endif
+
+#if 0
+#ifdef GL_EXT_texture_filter_anisotropic
+    float max_anisotropy;
+    glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy );
+    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
+                     max_anisotropy );
+    cout << "Max anisotropy = " << max_anisotropy << endl;
+#endif
+#endif
+
     // set current_options lon/lat if an airport id is specified
     // cout << "3. airport_id = " << fgGetString("/sim/startup/airport-id") << endl;
     if ( fgGetString("/sim/startup/airport-id").length() ) {
@@ -1515,10 +1545,11 @@ int main( int argc, char **argv ) {
                   0.0 );
     globals->set_ephem( ephem );
 
+    thesky = new SGSky;
+
     SGPath sky_tex_path( globals->get_fg_root() );
     sky_tex_path.append( "Textures" );
     sky_tex_path.append( "Sky" );
-    thesky = new SGSky;
     thesky->texture_path( sky_tex_path.str() );
 
     thesky->build( 550.0, 550.0,
@@ -1528,14 +1559,14 @@ int main( int argc, char **argv ) {
                   globals->get_ephem()->getStars(), 60000.0 );
 
     if ( fgGetBool("/environment/clouds/status") ) {
+       // thesky->add_cloud_layer( 2000.0, 200.0, 50.0, 40000.0,
+        //                          SG_CLOUD_OVERCAST );
        thesky->add_cloud_layer( 2600.0, 200.0, 50.0, 40000.0,
-                                SG_CLOUD_MOSTLY_SUNNY );
+                                SG_CLOUD_MOSTLY_CLOUDY );
+       // thesky->add_cloud_layer( 3000.0, 200.0, 50.0, 40000.0,
+       //                          SG_CLOUD_MOSTLY_SUNNY );
        thesky->add_cloud_layer( 6000.0, 20.0, 10.0, 40000.0,
                                 SG_CLOUD_CIRRUS );
-       // thesky->add_cloud_layer( 1000.0, 200.0, 50.0,
-       //                          SG_CLOUD_MOSTLY_SUNNY );
-       // thesky->add_cloud_layer( 1800.0, 400.0, 100.0, SG_CLOUD_OVERCAST );
-       // thesky->add_cloud_layer( 5000.0, 20.0, 10.0, SG_CLOUD_CIRRUS );
     }
 
     // Initialize MagVar model
@@ -1560,18 +1591,29 @@ int main( int argc, char **argv ) {
     acmodel_selector = new ssgSelector;
     acmodel_pos = new ssgTransform;
 
+    // Get the model location, and load textures from the same
+    // directory.  Use an absolute path for the model to avoid
+    // incompatibilities in different versions of PLIB.
     string acmodel_path =
        fgGetString("/sim/model/path", "Models/Geometry/glider.ac");
+    SGPath full_model = globals->get_fg_root();
+    full_model.append(acmodel_path);
 
-    string full_model = globals->get_fg_root() + "/"
-       + acmodel_path;
-    int pos = full_model.rfind("/");
-    
-    SGPath texturepath( full_model.substr(0, pos) );
-    cout << "Texture path = " << texturepath.str() << endl;
-    ssgTexturePath( (char *)texturepath.c_str() );
+#if !defined( PLIB_1_2_X )
+    // this should be redundant ... but it breaks for relative paths
+    // ssgModelPath( (char *)full_model.dir().c_str() );
+#endif
 
-    ssgEntity *acmodel_obj = ssgLoad((char *)(acmodel_path.c_str()));
+    ssgTexturePath( (char *)full_model.dir().c_str() );
+    ssgEntity *acmodel_obj = ssgLoad( (char *)full_model.c_str() );
+    if( !acmodel_obj ) {
+        // fall back to default
+        acmodel_obj = ssgLoad( (char *)"Models/Geometry/glider.ac" );
+        if( !acmodel_obj ) {
+            SG_LOG( SG_GENERAL, SG_ALERT, "FAILED to LOAD an AC model! ..." );
+            exit(-1);
+        }
+    }
 
     // find moving parts (if this is an MDL model)
     flaps_selector = (ssgSelector*)fgFindNode( acmodel_obj, "FLAPS" );
@@ -1718,7 +1760,7 @@ void fgLoadDCS(void) {
         SG_LOG ( SG_TERRAIN, SG_ALERT, "Finished object processing." );
 
         ship_sel->clrTraversalMaskBits( SSGTRAV_HOT );
-        scene->addKid( ship_sel ); //add selector node to root node
+        scene->addKid( ship_sel ); //add selector node to root node 
     }
 
     return;