- Timestamp:
- May 22, 2006, 2:08:44 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc
r7759 r7760 18 18 #include "util/loading/factory.h" 19 19 20 #include "p_node.h" 21 #include "state.h" 22 20 23 #include "glincl.h" 21 24 //#include "shell_command.h" … … 23 26 #define GLX_GLXEXT_PROTOTYPES 24 27 #include <GL/glx.h> 28 #include <GL/glut.h> 25 29 26 30 //#include <GL/glext.h> //OpenGL Extensions … … 78 82 79 83 // set fog mode 80 GLenum fogMode = GL_EXP 2;84 GLenum fogMode = GL_EXP; 81 85 82 86 // set fog density 83 float fogDensity = 0.0 3f;87 float fogDensity = 0.001f; 84 88 85 89 // set fog near & far distance 86 float fogStart = 0.0 5f;87 float fogEnd = 100 .0f;90 float fogStart = 0.0f; 91 float fogEnd = 1000.0f; 88 92 89 93 // Set fog color 90 float fogColor[4] = {0. 0, 1.0, 0.0, 1.0};94 float fogColor[4] = {0.6f,0.58f,0.79f,0.0f}; 91 95 92 glClearColor(fogColor[0],fogColor[1],fogColor[2],0.0f);93 glShadeModel(GL_SMOOTH);94 glEnable(GL_DEPTH_TEST);95 glEnable(GL_CULL_FACE);96 glCullFace(GL_BACK);97 96 98 97 glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfEXT"); … … 105 104 glFogf (GL_FOG_START, fogStart); 106 105 glFogf (GL_FOG_END, fogEnd); 107 glFogfv(GL_FOG_COLOR, fogColor); 106 glFogfv(GL_FOG_COLOR, fogColor); 108 107 glFogi (GL_FOG_MODE, fogMode); 109 108 glFogf (GL_FOG_DENSITY,fogDensity); … … 139 138 { 140 139 PRINTF(0)("Deactivating VolFogEffect\n"); 140 141 glDisable(GL_FOG); 141 142 } 142 143 … … 147 148 void VolFogEffect::draw() const 148 149 { 149 150 glPushAttrib(GL_ENABLE_BIT); 151 glClearColor(fogColor[0],fogColor[1],fogColor[2],0.0f); 152 glShadeModel(GL_SMOOTH); 153 glEnable(GL_DEPTH_TEST); 154 glEnable(GL_CULL_FACE); 155 glCullFace(GL_BACK); 156 150 157 /* clear all pixels in colour buffer */ 151 158 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 154 161 //glEnable(GL_BLEND); 155 162 //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); 156 157 /* draw the panels */ 158 glBegin(GL_QUADS); // Floor 159 glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,0.0f); 160 glFogCoordfEXT(0.0f); glVertex3f(100.0f,0.0f,0.0f); 161 glFogCoordfEXT(0.0f); glVertex3f(100.0f,0.0f, 100.0f); 162 glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f, 100.0f); 163 164 int i; 165 //glLoadIdentity(); 166 167 168 glBegin( GL_LINES ); 169 glNormal3f(0,1,0); 170 for(i=-20;i<=20;i+=2) 171 { 172 float fog_c; 173 float diff[3]; 174 175 diff[0] = State::getCameraNode()->getAbsCoor().x - i; 176 diff[2] = State::getCameraNode()->getAbsCoor().z + 20; 177 diff[1] = State::getCameraNode()->getAbsCoor().y; 178 fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); 179 glFogCoordfEXT(fog_c*2); 180 glVertex3f(i,0,-20); 181 182 diff[0] = State::getCameraNode()->getAbsCoor().x - i; 183 diff[2] = State::getCameraNode()->getAbsCoor().z + 20; 184 diff[1] = State::getCameraNode()->getAbsCoor().y; 185 fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); 186 glFogCoordfEXT(fog_c*2); 187 glVertex3f(i,0,20); 188 189 diff[0] = State::getCameraNode()->getAbsCoor().x - i; 190 diff[2] = State::getCameraNode()->getAbsCoor().z + 20; 191 diff[1] = State::getCameraNode()->getAbsCoor().y; 192 fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); 193 glFogCoordfEXT(fog_c*2); 194 glVertex3f(-20,0,i); 195 196 diff[0] = State::getCameraNode()->getAbsCoor().x - i; 197 diff[2] = State::getCameraNode()->getAbsCoor().z + 20; 198 diff[1] = State::getCameraNode()->getAbsCoor().y; 199 fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); 200 glFogCoordfEXT(fog_c*2); 201 glVertex3f(20,0,i); 202 } 163 203 glEnd(); 164 204 165 glBegin(GL_QUADS); // Roof 166 glFogCoordfEXT(1.0f); glVertex3f(0.0f, 100.0f,0.0f); 167 glFogCoordfEXT(1.0f); glVertex3f( 100.0f, 100.0f,0.0f); 168 glFogCoordfEXT(1.0f); glVertex3f( 100.0f, 100.0f, 100.0f); 169 glFogCoordfEXT(1.0f); glVertex3f(0.0f, 100.0f, 100.0f); 170 glEnd(); 171 172 glBegin(GL_QUADS); // Back Wall 173 glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,0.0f); 174 glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f,0.0f); 175 glFogCoordfEXT(1.0f); glVertex3f( 100.0f, 100.0f,0.0f); 176 glFogCoordfEXT(1.0f); glVertex3f(0.0f, 100.0f,0.0f); 177 glEnd(); 178 179 glBegin(GL_QUADS); // Front Wall 180 glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,100.0f); 181 glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f,100.0f); 182 glFogCoordfEXT(1.0f); glVertex3f( 100.0f, 100.0f,100.0f); 183 glFogCoordfEXT(1.0f); glVertex3f(0.0f, 100.0f,100.0f); 184 glEnd(); 185 186 glBegin(GL_QUADS); // Right Wall 187 glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f, 100.0f); 188 glFogCoordfEXT(1.0f); glVertex3f( 100.0f, 100.0f, 100.0f); 189 glFogCoordfEXT(1.0f); glVertex3f( 100.0f, 100.0f,0.0f); 190 glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f,0.0f); 191 glEnd(); 192 193 glBegin(GL_QUADS); // Left Wall 194 glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f, 100.0f); 195 glFogCoordfEXT(1.0f); glVertex3f(0.0f, 100.0f, 100.0f); 196 glFogCoordfEXT(1.0f); glVertex3f(0.0f, 100.0f,0.0f); 197 glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,0.0f); 198 glEnd(); 199 200 /* process all buffered OpenGL commands */ 201 glFlush(); 205 glPopAttrib(); 202 206 203 207 }
Note: See TracChangeset
for help on using the changeset viewer.