Index: branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc
===================================================================
--- branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc	(revision 7532)
+++ branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc	(revision 7546)
@@ -33,4 +33,18 @@
     this->loadParams(root);
 
+  this->init();
+
+  //if (! this->init())                        // Check And Enable Fog Extension If Available
+    //return false;                         // Return False If Extension Not Supported
+
+  // Set Up Fog 
+  //glEnable(GL_FOG);                         // Enable Fog
+  //glFogi(GL_FOG_MODE, GL_LINEAR);                   // Fog Fade Is Linear
+  //glFogfv(GL_FOG_COLOR, fogColor);                  // Set The Fog Color
+  //glFogf(GL_FOG_START,  1.0f);                    // Set The Fog Start
+  //glFogf(GL_FOG_END,    0.0f);                    // Set The Fog End
+  //glHint(GL_FOG_HINT, GL_NICEST);                   // Per-Pixel Fog Calculation
+  //glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);    // Set Fog Based On Vertice Coordinates
+
   this->activate();
 }
@@ -45,13 +59,4 @@
 {
   WeatherEffect::loadParams(root);
-
-  //LoadParam(root, "fog-altitude", this, VolFogEffect, setFogAltitude);
-  //LoadParam(root, "fog-color", this, VolFogEffect, startFogColor);
-  LoadParam(root, "test", this, VolFogEffect, test);
-}
-
-void VolFogEffect::test(int t)
-{
-  PRINTF(0)("Test: %i\n", t);
 }
 
@@ -59,30 +64,47 @@
 {
   PRINTF(0)("Initalize VolFogEffect\n");
-};
+
+  fogColor[0] = 0.6f;
+  fogColor[1] = 0.3f;
+  fogColor[2] = 0.0f;
+  fogColor[3] = 1.0f;
+
+  //glDepthFunc (GL_LEQUAL);                            // The Type Of Depth Testing
+  //glEnable (GL_DEPTH_TEST);                           // Enable Depth Testing
+  //glShadeModel (GL_SMOOTH);                           // Select Smooth Shading
+  //glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most AccurateAbility
+
+  char extensions[ 16384 ];
+  char Extension_Name[] = "GL_EXT_fog_coord";
+  char *buf;
+
+  sprintf( extensions, "%s", (char *)glGetString( GL_EXTENSIONS ) );
+  buf = strtok( extensions, " " );
+  while( buf != NULL )
+  {
+    if( !strcmp( Extension_Name, buf ) )
+    {
+      PRINTF(0)( "%s found, great.\n", Extension_Name );
+      return true;
+    }
+    buf = strtok( NULL, " " );
+  }
+
+  PRINTF(0)( "%s\n", (char *)glGetString( GL_EXTENSIONS ) );
+  PRINTF(0)( "%s not found, dammit.\n", Extension_Name );
+  return false;
+}
 
 
 bool VolFogEffect::activate()
 {
-  //PRINTF(0)( "Enabling Volumetric Fog Effect, altitude: %i, color %f, %f, %f\n", this->fogAltitude, this->colorVector.x, this->colorVector.y, this->colorVector.z);
-
-  PRINTF(0)("Activate VolFogEffect\n");
+  PRINTF(0)("Activating VolFogEffect\n");
 }
 
 bool VolFogEffect::deactivate()
 {
-  PRINTF(0)("Deactivate VolFogEffect\n");
-}
-
-/*
-void VolFogEffect::setFogColor(int v)
-{
-	float z;	
-	float f;	
-
-	z = 0.0 - vertices[v].y;
-	f = (60.0 - z) / (60.0 - 0.0);	
-	glColor4f(this->colorVector.x, this->colorVector.y, this->colorVector.z, f);
-}
-*/
+  PRINTF(0)("Deactivating VolFogEffect\n");
+}
+
 
 /**
@@ -91,66 +113,82 @@
 void VolFogEffect::draw() const
 {
-	// PRINTF(0)("DRAW VolFogEffect\n");
-
-	glDepthMask(GL_TRUE);
-	glEnable(GL_BLEND);
-	glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
-	// glDisable(GL_TEXTURE_2D);
-	// draw the fog panels
-	
-	glBegin(GL_QUADS);
-
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0));
-	glVertex3f( 10.0f,-10.0f, 10.0f);	// Top Right Of The Quad (Bottom)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0));
-	glVertex3f(-10.0f,-10.0f, 10.0f);	// Top Left Of The Quad (Bottom)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0));
-	glVertex3f(-10.0f,-10.0f,-10.0f);	// Bottom Left Of The Quad (Bottom)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0));
-	glVertex3f( 10.0f,-10.0f,-10.0f);	// Bottom Right Of The Quad (Bottom)
-	
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0));
-	glVertex3f( 10.0f, 10.0f, 10.0f);	// Top Right Of The Quad (Front)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0));
-	glVertex3f(-10.0f, 10.0f, 10.0f);	// Top Left Of The Quad (Front)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0));
-	glVertex3f(-10.0f,-10.0f, 10.0f);	// Bottom Left Of The Quad (Front)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0));
-	glVertex3f( 10.0f,-10.0f, 10.0f);	// Bottom Right Of The Quad (Front)
-	
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0));
-	glVertex3f( 10.0f,-10.0f,-10.0f);	// Top Right Of The Quad (Back)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0));
-	glVertex3f(-10.0f,-10.0f,-10.0f);	// Top Left Of The Quad (Back)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0));
-	glVertex3f(-10.0f, 10.0f,-10.0f);	// Bottom Left Of The Quad (Back)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0));
-	glVertex3f( 10.0f, 10.0f,-10.0f);	// Bottom Right Of The Quad (Back)
-	
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0));
-	glVertex3f(-10.0f, 10.0f, 10.0f);	// Top Right Of The Quad (Left)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0));
-	glVertex3f(-10.0f, 10.0f,-10.0f);	// Top Left Of The Quad (Left)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0));
-	glVertex3f(-10.0f,-10.0f,-10.0f);	// Bottom Left Of The Quad (Left)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0));
-	glVertex3f(-10.0f,-10.0f, 10.0f);	// Bottom Right Of The Quad (Left)
-	
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0));
-	glVertex3f( 10.0f, 10.0f,-10.0f);	// Top Right Of The Quad (Right)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0));
-	glVertex3f( 10.0f, 10.0f, 10.0f);	// Top Left Of The Quad (Right)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0));
-	glVertex3f( 10.0f,-10.0f, 10.0f);	// Bottom Left Of The Quad (Right)
-	glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0));
-	glVertex3f( 10.0f,-10.0f,-10.0f);	// Bottom Right Of The Quad (Right)
-
-	glEnd();
-
-	// restore rendering state
-
-	// glEnable(GL_TEXTURE_2D);
-	glDisable(GL_BLEND);
-
+    glPushAttrib(GL_ENABLE_BIT);
+
+glClearDepth (1.0f); 
+  glDepthFunc (GL_LEQUAL);                            // The Type Of Depth Testing
+  glEnable (GL_DEPTH_TEST);                           // Enable Depth Testing
+  glShadeModel (GL_SMOOTH);                           // Select Smooth Shading
+  glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most AccurateAbili
+
+
+  // Set Up Fog 
+  glEnable(GL_FOG);                         // Enable Fog
+  glFogi(GL_FOG_MODE, GL_LINEAR);                   // Fog Fade Is Linear
+  glFogfv(GL_FOG_COLOR, fogColor);                  // Set The Fog Color
+  glFogf(GL_FOG_START,  1.0f);                    // Set The Fog Start
+  glFogf(GL_FOG_END,    0.0f);                    // Set The Fog End
+  glHint(GL_FOG_HINT, GL_NICEST);                   // Per-Pixel Fog Calculation
+  glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);    // Set Fog Based On Vertice Coordinates
+
+
+
+  //glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        // Clear Screen And Depth Buffer
+  //glLoadIdentity ();                          // Reset The Modelview Matrix
+
+  //glTranslatef(camx, 0.0f, camz);             // Move To Our Camera Z/X Position
+
+  // glFogCoordEXT is very similar to glVertex3f. If you understand
+  // the way vertexs are applied in OpenGL, you will not have any dificulty
+  // understanding glFogCoordEXT.
+
+  // In this tutorial we are applyng the fog in a corridor, so the fog
+  // goes from the less density (the minor z) to a bigger density (the biggest z).
+  // If you check the fog_start and fog_eng, it's 0 and 1.
+
+  // So, we will pass to the function glFogCoordEXT, the fog value corresponding
+  // with the glVertex3f value.If we are drawing a quad from z minus to z major, 
+  // we do exactly the same with glFogCoord.
+
+  // For example, in the first quad, is vertex coordinates in the Z field are all 
+  // -15.0f. So we want the fog to completely fill this quad, so we assign 0 to all
+  // the glFogCoordExt.
+  
+  glBegin(GL_QUADS);                          // Back Wall
+    glFogCoordfEXT( 0.0f); glVertex3f(-2.5f,-2.5f,-15.0f);
+    glFogCoordfEXT( 0.0f); glVertex3f( 2.5f,-2.5f,-15.0f);
+    glFogCoordfEXT( 0.0f); glVertex3f( 2.5f, 2.5f,-15.0f);
+    glFogCoordfEXT( 0.0f); glVertex3f(-2.5f, 2.5f,-15.0f);
+  glEnd();
+
+  glBegin(GL_QUADS);                          // Floor
+    glFogCoordfEXT( 0.0f); glVertex3f(-2.5f,-2.5f,-15.0f);
+    glFogCoordfEXT( 0.0f); glVertex3f( 2.5f,-2.5f,-15.0f);
+    glFogCoordfEXT( 1.0f); glVertex3f( 2.5f,-2.5f, 15.0f);
+    glFogCoordfEXT( 1.0f); glVertex3f(-2.5f,-2.5f, 15.0f);
+  glEnd();
+
+  glBegin(GL_QUADS);                          // Roof
+    glFogCoordfEXT( 0.0f); glVertex3f(-2.5f, 2.5f,-15.0f);
+    glFogCoordfEXT( 0.0f); glVertex3f( 2.5f, 2.5f,-15.0f);
+    glFogCoordfEXT( 1.0f); glVertex3f( 2.5f, 2.5f, 15.0f);
+    glFogCoordfEXT( 1.0f); glVertex3f(-2.5f, 2.5f, 15.0f);
+  glEnd();
+
+  glBegin(GL_QUADS);                          // Right Wall
+    glFogCoordfEXT( 1.0f); glVertex3f( 2.5f,-2.5f, 15.0f);
+    glFogCoordfEXT( 1.0f); glVertex3f( 2.5f, 2.5f, 15.0f);
+    glFogCoordfEXT( 0.0f); glVertex3f( 2.5f, 2.5f,-15.0f);
+    glFogCoordfEXT( 0.0f); glVertex3f( 2.5f,-2.5f,-15.0f);
+  glEnd();
+
+  glBegin(GL_QUADS);                          // Left Wall
+    glFogCoordfEXT( 1.0f); glVertex3f(-2.5f,-2.5f, 15.0f);
+    glFogCoordfEXT( 1.0f); glVertex3f(-2.5f, 2.5f, 15.0f);
+    glFogCoordfEXT( 0.0f); glVertex3f(-2.5f, 2.5f,-15.0f);
+    glFogCoordfEXT( 0.0f); glVertex3f(-2.5f,-2.5f,-15.0f);
+  glEnd();
+ 
+  //glFlush ();                             // Flush The GL Rendering Pipeline
+  glPopAttrib();
 }
 
