]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/sky/moon.cxx
Activate the driver fog workaround again. It doesn't seem to be solved yet.
[simgear.git] / simgear / scene / sky / moon.cxx
index f5c81b3b6928ae5717c58040921cb1a71b41f218..fdf1fc8750c959816a1269e510bce051eef598bb 100644 (file)
@@ -34,6 +34,7 @@
 #include <plib/ssg.h>
 
 #include <simgear/constants.h>
+#include <simgear/screen/colors.hxx>
 
 #include "sphere.hxx"
 #include "moon.hxx"
@@ -47,7 +48,7 @@ static int sgMoonOrbPreDraw( ssgEntity *e ) {
     ssgLeaf *f = (ssgLeaf *)e;
     if ( f -> hasState () ) f->getState()->apply() ;
 
-    glPushAttrib( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT );
+    glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT );
     // cout << "push error = " << glGetError() << endl;
 
     glDisable( GL_DEPTH_TEST );
@@ -61,8 +62,6 @@ static int sgMoonOrbPreDraw( ssgEntity *e ) {
 static int sgMoonOrbPostDraw( ssgEntity *e ) {
     /* cout << endl << "Moon orb post draw" << endl << "----------------" 
         << endl << endl; */
-    // glEnable( GL_DEPTH_TEST );
-    // glEnable( GL_FOG );
 
     // Some drivers don't properly reset glBendFunc with a
     // glPopAttrib() so we reset it to the 'default' here.
@@ -71,14 +70,6 @@ static int sgMoonOrbPostDraw( ssgEntity *e ) {
     glPopAttrib();
     // cout << "pop error = " << glGetError() << endl;
     
-    /* test
-    glDisable( GL_LIGHTING );
-    glDisable( GL_CULL_FACE );
-    glEnable( GL_COLOR_MATERIAL );
-    glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
-    glEnable( GL_CULL_FACE );
-    glEnable( GL_LIGHTING ); */
-
     return true;
 }
 
@@ -104,9 +95,6 @@ static int sgMoonHaloPreDraw( ssgEntity *e ) {
 static int sgMoonHaloPostDraw( ssgEntity *e ) {
     /* cout << endl << "Moon halo post draw" << endl << "----------------" 
         << endl << endl; */
-    // glEnable( GL_DEPTH_TEST );
-    // glEnable( GL_FOG );
-    // glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
     
     glPopAttrib();
     // cout << "pop error = " << glGetError() << endl;
@@ -117,7 +105,9 @@ static int sgMoonHaloPostDraw( ssgEntity *e ) {
 
 
 // Constructor
-SGMoon::SGMoon( void ) {
+SGMoon::SGMoon( void ) :
+    prev_moon_angle(-1)
+{
 }
 
 
@@ -140,7 +130,7 @@ ssgBranch * SGMoon::build( SGPath path, double moon_size ) {
     orb_state->enable( GL_COLOR_MATERIAL );
     orb_state->setColourMaterial( GL_DIFFUSE );
     orb_state->setMaterial( GL_AMBIENT, 0, 0, 0, 1.0 );
-    orb_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
+    orb_state->setMaterial( GL_EMISSION, 0.0, 0.0, 0.0, 1 );
     orb_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
     orb_state->enable( GL_BLEND );
     orb_state->enable( GL_ALPHA_TEST );
@@ -229,38 +219,31 @@ ssgBranch * SGMoon::build( SGPath path, double moon_size ) {
 // 90 degrees = moon rise/set
 // 180 degrees = darkest midnight
 bool SGMoon::repaint( double moon_angle ) {
-    if ( moon_angle * SGD_RADIANS_TO_DEGREES < 100 ) {
-       // else moon is well below horizon (so no point in repainting it)
-    
-       // x_10 = moon_angle^10
-       double x_10 = moon_angle * moon_angle * moon_angle * moon_angle
-           * moon_angle * moon_angle * moon_angle * moon_angle * moon_angle
-           * moon_angle;
-
-       float ambient = (float)(0.4 * pow (1.1, - x_10 / 30.0));
-       if (ambient < 0.3) { ambient = 0.3; }
-       if (ambient > 1.0) { ambient = 1.0; }
-
-       sgVec4 color;
-       sgSetVec4( color,
-                  (ambient * 6.0)  - 1.0, // minimum value = 0.8
-                  (ambient * 11.0) - 3.0, // minimum value = 0.3
-                  (ambient * 12.0) - 3.6, // minimum value = 0.0
-                  0.5 );
-
-       // temp test, forces the color to always be white
-       // sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
-
-       if (color[0] > 1.0) color[0] = 1.0;
-       if (color[1] > 1.0) color[1] = 1.0;
-       if (color[2] > 1.0) color[2] = 1.0;
-
-       // cout << "color = " << color[0] << " " << color[1] << " " 
-       //      << color[2] << endl;
-
-       float *ptr;
-       ptr = cl->get( 0 );
-       sgCopyVec4( ptr, color );
+
+    if (prev_moon_angle != moon_angle) {
+        prev_moon_angle = moon_angle;
+
+        float moon_factor = 4*cos(moon_angle);
+
+        if (moon_factor > 1) moon_factor = 1.0;
+        if (moon_factor < -1) moon_factor = -1.0;
+        moon_factor = moon_factor/2 + 0.5;
+
+        sgVec4 color;
+        color[1] = sqrt(moon_factor);
+        color[0] = sqrt(color[1]);
+        color[2] = moon_factor * moon_factor;
+        color[2] *= color[2];
+        color[3] = 1.0;
+
+        gamma_correct_rgb( color );
+
+        // cout << "color = " << color[0] << " " << color[1] << " "
+        //      << color[2] << endl;
+
+        float *ptr;
+        ptr = cl->get( 0 );
+        sgCopyVec4( ptr, color );
     }
 
     return true;