Changeset 7546 in orxonox.OLD for branches/atmospheric_engine/src
- Timestamp:
- May 6, 2006, 9:14:10 AM (19 years ago)
- Location:
- branches/atmospheric_engine/src/lib/graphics/effects
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc
r7532 r7546 33 33 this->loadParams(root); 34 34 35 this->init(); 36 37 //if (! this->init()) // Check And Enable Fog Extension If Available 38 //return false; // Return False If Extension Not Supported 39 40 // Set Up Fog 41 //glEnable(GL_FOG); // Enable Fog 42 //glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Fade Is Linear 43 //glFogfv(GL_FOG_COLOR, fogColor); // Set The Fog Color 44 //glFogf(GL_FOG_START, 1.0f); // Set The Fog Start 45 //glFogf(GL_FOG_END, 0.0f); // Set The Fog End 46 //glHint(GL_FOG_HINT, GL_NICEST); // Per-Pixel Fog Calculation 47 //glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); // Set Fog Based On Vertice Coordinates 48 35 49 this->activate(); 36 50 } … … 45 59 { 46 60 WeatherEffect::loadParams(root); 47 48 //LoadParam(root, "fog-altitude", this, VolFogEffect, setFogAltitude);49 //LoadParam(root, "fog-color", this, VolFogEffect, startFogColor);50 LoadParam(root, "test", this, VolFogEffect, test);51 }52 53 void VolFogEffect::test(int t)54 {55 PRINTF(0)("Test: %i\n", t);56 61 } 57 62 … … 59 64 { 60 65 PRINTF(0)("Initalize VolFogEffect\n"); 61 }; 66 67 fogColor[0] = 0.6f; 68 fogColor[1] = 0.3f; 69 fogColor[2] = 0.0f; 70 fogColor[3] = 1.0f; 71 72 //glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing 73 //glEnable (GL_DEPTH_TEST); // Enable Depth Testing 74 //glShadeModel (GL_SMOOTH); // Select Smooth Shading 75 //glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most AccurateAbility 76 77 char extensions[ 16384 ]; 78 char Extension_Name[] = "GL_EXT_fog_coord"; 79 char *buf; 80 81 sprintf( extensions, "%s", (char *)glGetString( GL_EXTENSIONS ) ); 82 buf = strtok( extensions, " " ); 83 while( buf != NULL ) 84 { 85 if( !strcmp( Extension_Name, buf ) ) 86 { 87 PRINTF(0)( "%s found, great.\n", Extension_Name ); 88 return true; 89 } 90 buf = strtok( NULL, " " ); 91 } 92 93 PRINTF(0)( "%s\n", (char *)glGetString( GL_EXTENSIONS ) ); 94 PRINTF(0)( "%s not found, dammit.\n", Extension_Name ); 95 return false; 96 } 62 97 63 98 64 99 bool VolFogEffect::activate() 65 100 { 66 //PRINTF(0)( "Enabling Volumetric Fog Effect, altitude: %i, color %f, %f, %f\n", this->fogAltitude, this->colorVector.x, this->colorVector.y, this->colorVector.z); 67 68 PRINTF(0)("Activate VolFogEffect\n"); 101 PRINTF(0)("Activating VolFogEffect\n"); 69 102 } 70 103 71 104 bool VolFogEffect::deactivate() 72 105 { 73 PRINTF(0)("Deactivate VolFogEffect\n"); 74 } 75 76 /* 77 void VolFogEffect::setFogColor(int v) 78 { 79 float z; 80 float f; 81 82 z = 0.0 - vertices[v].y; 83 f = (60.0 - z) / (60.0 - 0.0); 84 glColor4f(this->colorVector.x, this->colorVector.y, this->colorVector.z, f); 85 } 86 */ 106 PRINTF(0)("Deactivating VolFogEffect\n"); 107 } 108 87 109 88 110 /** … … 91 113 void VolFogEffect::draw() const 92 114 { 93 // PRINTF(0)("DRAW VolFogEffect\n"); 94 95 glDepthMask(GL_TRUE); 96 glEnable(GL_BLEND); 97 glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); 98 // glDisable(GL_TEXTURE_2D); 99 // draw the fog panels 100 101 glBegin(GL_QUADS); 102 103 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0)); 104 glVertex3f( 10.0f,-10.0f, 10.0f); // Top Right Of The Quad (Bottom) 105 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0)); 106 glVertex3f(-10.0f,-10.0f, 10.0f); // Top Left Of The Quad (Bottom) 107 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0)); 108 glVertex3f(-10.0f,-10.0f,-10.0f); // Bottom Left Of The Quad (Bottom) 109 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0)); 110 glVertex3f( 10.0f,-10.0f,-10.0f); // Bottom Right Of The Quad (Bottom) 111 112 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0)); 113 glVertex3f( 10.0f, 10.0f, 10.0f); // Top Right Of The Quad (Front) 114 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0)); 115 glVertex3f(-10.0f, 10.0f, 10.0f); // Top Left Of The Quad (Front) 116 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0)); 117 glVertex3f(-10.0f,-10.0f, 10.0f); // Bottom Left Of The Quad (Front) 118 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0)); 119 glVertex3f( 10.0f,-10.0f, 10.0f); // Bottom Right Of The Quad (Front) 120 121 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0)); 122 glVertex3f( 10.0f,-10.0f,-10.0f); // Top Right Of The Quad (Back) 123 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0)); 124 glVertex3f(-10.0f,-10.0f,-10.0f); // Top Left Of The Quad (Back) 125 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0)); 126 glVertex3f(-10.0f, 10.0f,-10.0f); // Bottom Left Of The Quad (Back) 127 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0)); 128 glVertex3f( 10.0f, 10.0f,-10.0f); // Bottom Right Of The Quad (Back) 129 130 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0)); 131 glVertex3f(-10.0f, 10.0f, 10.0f); // Top Right Of The Quad (Left) 132 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0)); 133 glVertex3f(-10.0f, 10.0f,-10.0f); // Top Left Of The Quad (Left) 134 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0)); 135 glVertex3f(-10.0f,-10.0f,-10.0f); // Bottom Left Of The Quad (Left) 136 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0)); 137 glVertex3f(-10.0f,-10.0f, 10.0f); // Bottom Right Of The Quad (Left) 138 139 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0)); 140 glVertex3f( 10.0f, 10.0f,-10.0f); // Top Right Of The Quad (Right) 141 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - 10.0f)) / (10.0 - 0.0)); 142 glVertex3f( 10.0f, 10.0f, 10.0f); // Top Left Of The Quad (Right) 143 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0)); 144 glVertex3f( 10.0f,-10.0f, 10.0f); // Bottom Left Of The Quad (Right) 145 glColor4f(0.6, 0.2, 0.0, (10.0 - (0.0 - -10.0f)) / (10.0 - 0.0)); 146 glVertex3f( 10.0f,-10.0f,-10.0f); // Bottom Right Of The Quad (Right) 147 148 glEnd(); 149 150 // restore rendering state 151 152 // glEnable(GL_TEXTURE_2D); 153 glDisable(GL_BLEND); 154 115 glPushAttrib(GL_ENABLE_BIT); 116 117 glClearDepth (1.0f); 118 glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing 119 glEnable (GL_DEPTH_TEST); // Enable Depth Testing 120 glShadeModel (GL_SMOOTH); // Select Smooth Shading 121 glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most AccurateAbili 122 123 124 // Set Up Fog 125 glEnable(GL_FOG); // Enable Fog 126 glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Fade Is Linear 127 glFogfv(GL_FOG_COLOR, fogColor); // Set The Fog Color 128 glFogf(GL_FOG_START, 1.0f); // Set The Fog Start 129 glFogf(GL_FOG_END, 0.0f); // Set The Fog End 130 glHint(GL_FOG_HINT, GL_NICEST); // Per-Pixel Fog Calculation 131 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); // Set Fog Based On Vertice Coordinates 132 133 134 135 //glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer 136 //glLoadIdentity (); // Reset The Modelview Matrix 137 138 //glTranslatef(camx, 0.0f, camz); // Move To Our Camera Z/X Position 139 140 // glFogCoordEXT is very similar to glVertex3f. If you understand 141 // the way vertexs are applied in OpenGL, you will not have any dificulty 142 // understanding glFogCoordEXT. 143 144 // In this tutorial we are applyng the fog in a corridor, so the fog 145 // goes from the less density (the minor z) to a bigger density (the biggest z). 146 // If you check the fog_start and fog_eng, it's 0 and 1. 147 148 // So, we will pass to the function glFogCoordEXT, the fog value corresponding 149 // with the glVertex3f value.If we are drawing a quad from z minus to z major, 150 // we do exactly the same with glFogCoord. 151 152 // For example, in the first quad, is vertex coordinates in the Z field are all 153 // -15.0f. So we want the fog to completely fill this quad, so we assign 0 to all 154 // the glFogCoordExt. 155 156 glBegin(GL_QUADS); // Back Wall 157 glFogCoordfEXT( 0.0f); glVertex3f(-2.5f,-2.5f,-15.0f); 158 glFogCoordfEXT( 0.0f); glVertex3f( 2.5f,-2.5f,-15.0f); 159 glFogCoordfEXT( 0.0f); glVertex3f( 2.5f, 2.5f,-15.0f); 160 glFogCoordfEXT( 0.0f); glVertex3f(-2.5f, 2.5f,-15.0f); 161 glEnd(); 162 163 glBegin(GL_QUADS); // Floor 164 glFogCoordfEXT( 0.0f); glVertex3f(-2.5f,-2.5f,-15.0f); 165 glFogCoordfEXT( 0.0f); glVertex3f( 2.5f,-2.5f,-15.0f); 166 glFogCoordfEXT( 1.0f); glVertex3f( 2.5f,-2.5f, 15.0f); 167 glFogCoordfEXT( 1.0f); glVertex3f(-2.5f,-2.5f, 15.0f); 168 glEnd(); 169 170 glBegin(GL_QUADS); // Roof 171 glFogCoordfEXT( 0.0f); glVertex3f(-2.5f, 2.5f,-15.0f); 172 glFogCoordfEXT( 0.0f); glVertex3f( 2.5f, 2.5f,-15.0f); 173 glFogCoordfEXT( 1.0f); glVertex3f( 2.5f, 2.5f, 15.0f); 174 glFogCoordfEXT( 1.0f); glVertex3f(-2.5f, 2.5f, 15.0f); 175 glEnd(); 176 177 glBegin(GL_QUADS); // Right Wall 178 glFogCoordfEXT( 1.0f); glVertex3f( 2.5f,-2.5f, 15.0f); 179 glFogCoordfEXT( 1.0f); glVertex3f( 2.5f, 2.5f, 15.0f); 180 glFogCoordfEXT( 0.0f); glVertex3f( 2.5f, 2.5f,-15.0f); 181 glFogCoordfEXT( 0.0f); glVertex3f( 2.5f,-2.5f,-15.0f); 182 glEnd(); 183 184 glBegin(GL_QUADS); // Left Wall 185 glFogCoordfEXT( 1.0f); glVertex3f(-2.5f,-2.5f, 15.0f); 186 glFogCoordfEXT( 1.0f); glVertex3f(-2.5f, 2.5f, 15.0f); 187 glFogCoordfEXT( 0.0f); glVertex3f(-2.5f, 2.5f,-15.0f); 188 glFogCoordfEXT( 0.0f); glVertex3f(-2.5f,-2.5f,-15.0f); 189 glEnd(); 190 191 //glFlush (); // Flush The GL Rendering Pipeline 192 glPopAttrib(); 155 193 } 156 194 -
branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.h
r7530 r7546 9 9 10 10 #include "weather_effect.h" 11 12 // Variables Necessary For FogCoordfEXT 13 #define GL_FOG_COORDINATE_SOURCE_EXT 0x8450 14 #define GL_FOG_COORDINATE_EXT 0x8451 11 15 12 16 class VolFogEffect : public WeatherEffect … … 26 30 virtual void tick(float dt); 27 31 28 //inline void startFogColor(float r, float g, float b) { this->colorVector = Vector(r, g, b); } 29 //inline void setFogAltitude(float altitude) { this->fogAltitude = altitude; } 30 void test(int t); 32 private: 31 33 32 private: 33 //void setFogColor(int v); 34 //GLfloat fogAltitude; 35 //Vector colorVector; 34 GLfloat fogColor[4]; 35 36 36 }; 37 37
Note: See TracChangeset
for help on using the changeset viewer.