Changeset 8495 in orxonox.OLD for trunk/src/lib/graphics/effects/volfog_effect.cc
- Timestamp:
- Jun 15, 2006, 9:50:56 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/effects/volfog_effect.cc
r8362 r8495 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2004 orx 5 5 6 7 8 9 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: hdavid, amaechler 13 13 */ 14 14 … … 21 21 #include "state.h" 22 22 23 #include "glincl.h" 24 //#include "shell_command.h" 23 25 24 26 #define GLX_GLXEXT_PROTOTYPES … … 49 51 CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT); 50 52 51 VolFogEffect::VolFogEffect(const TiXmlElement* root) 52 { 53 this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect"); 53 VolFogEffect::VolFogEffect(const TiXmlElement* root) { 54 this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect"); 54 55 55 56 56 if (root != NULL) 57 this->loadParams(root); 57 58 58 59 59 // Initialize Effect 60 this->init(); 60 61 61 62 62 // Activate Effect 63 this->activate(); 63 64 } 64 65 65 66 66 VolFogEffect::~VolFogEffect() 67 { 68 this->deactivate(); 67 VolFogEffect::~VolFogEffect() { 68 this->deactivate(); 69 69 } 70 70 71 void VolFogEffect::loadParams(const TiXmlElement* root) 72 { 73 WeatherEffect::loadParams(root); 71 void VolFogEffect::loadParams(const TiXmlElement* root) { 72 WeatherEffect::loadParams(root); 74 73 } 75 74 76 bool VolFogEffect::init() 77 { 78 PRINTF(0)("Initalize VolFogEffect\n"); 75 void VolFogEffect::init() { 76 PRINTF(0)("Initalize VolFogEffect\n"); 79 77 80 81 78 // set fog mode 79 GLenum fogMode = GL_EXP; 82 80 83 84 81 // set fog density 82 float fogDensity = 0.001f; 85 83 86 87 88 84 // set fog near & far distance 85 float fogStart = 0.0f; 86 float fogEnd = 1000.0f; 89 87 90 91 88 // Set fog color 89 float fogColor[4] = {0.6f,0.58f,0.79f,0.0f}; 92 90 93 91 94 95 96 97 98 92 glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfEXT"); 93 glFogCoordfvEXT = (PFNGLFOGCOORDFVEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfvEXT"); 94 glFogCoorddEXT = (PFNGLFOGCOORDDEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoorddEXT"); 95 glFogCoorddvEXT = (PFNGLFOGCOORDDVEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoorddvEXT"); 96 glFogCoordPointerEXT = (PFNGLFOGCOORDPOINTEREXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordPointerEXT"); 99 97 100 101 102 103 104 105 106 98 // set the fog attributes 99 glFogf (GL_FOG_START, fogStart); 100 glFogf (GL_FOG_END, fogEnd); 101 glFogfv(GL_FOG_COLOR, fogColor); 102 glFogi (GL_FOG_MODE, fogMode); 103 glFogf (GL_FOG_DENSITY,fogDensity); 104 glFogi (GL_FOG_COORDINATE_SOURCE_EXT,GL_FOG_COORDINATE_EXT); 107 105 108 109 106 // enable the fog 107 glEnable(GL_FOG); 110 108 111 112 113 114 109 if (glewInit() == GLEW_OK) 110 PRINTF(0)("glewInit OK\n"); 111 else 112 PRINTF(0)("glewInit failed\n"); 115 113 116 if (glewGetExtension("GL_EXT_fog_coord")) 117 { 118 PRINTF(0)("GL_EXT_fog_coord extension found\n"); 119 return true; 120 } 121 else 122 { 123 PRINTF(0)("GL_EXT_fog_coord extension NOT found\n"); 124 return false; 125 } 114 if (glewGetExtension("GL_EXT_fog_coord")) 115 PRINTF(0)("GL_EXT_fog_coord extension found\n"); 126 116 } 127 117 128 118 129 bool VolFogEffect::activate() 130 { 131 PRINTF(0)("Activating VolFogEffect\n"); 132 133 return true; 119 void VolFogEffect::activate() { 120 PRINTF(0)("Activating VolFogEffect\n"); 134 121 } 135 122 136 bool VolFogEffect::deactivate() 137 { 138 PRINTF(0)("Deactivating VolFogEffect\n"); 123 void VolFogEffect::deactivate() { 124 PRINTF(0)("Deactivating VolFogEffect\n"); 139 125 140 glDisable(GL_FOG); 141 142 return true; 126 glDisable(GL_FOG); 143 127 } 144 128 … … 147 131 * draws the effect, if needed 148 132 */ 149 void VolFogEffect::draw() const 150 { 151 glPushAttrib(GL_ENABLE_BIT); 152 glClearColor(fogColor[0],fogColor[1],fogColor[2],0.0f); 153 glShadeModel(GL_SMOOTH); 154 glEnable(GL_DEPTH_TEST); 155 glEnable(GL_CULL_FACE); 156 glCullFace(GL_BACK); 133 void VolFogEffect::draw() const { 134 glPushAttrib(GL_ENABLE_BIT); 135 glClearColor(fogColor[0],fogColor[1],fogColor[2],0.0f); 136 glShadeModel(GL_SMOOTH); 137 glEnable(GL_DEPTH_TEST); 138 glEnable(GL_CULL_FACE); 139 glCullFace(GL_BACK); 157 140 158 159 141 /* clear all pixels in colour buffer */ 142 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 160 143 161 162 163 144 /* Enable blending */ 145 //glEnable(GL_BLEND); 146 //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); 164 147 165 166 148 int i; 149 glLoadIdentity(); 167 150 168 151 169 glBegin( GL_LINES ); 170 glNormal3f(0,1,0); 171 for(i=-20;i<=20;i+=2) 172 { 173 float fog_c; 174 float diff[3]; 152 glBegin( GL_LINES ); 153 glNormal3f(0,1,0); 154 for(i=-20;i<=20;i+=2) { 155 float fog_c; 156 float diff[3]; 175 157 176 177 178 179 180 181 158 diff[0] = State::getCameraNode()->getAbsCoor().x - i; 159 diff[2] = State::getCameraNode()->getAbsCoor().z + 20; 160 diff[1] = State::getCameraNode()->getAbsCoor().y; 161 fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); 162 glFogCoordfEXT(fog_c*2); 163 glVertex3f(i,0,-20); 182 164 183 184 185 186 187 188 165 diff[0] = State::getCameraNode()->getAbsCoor().x - i; 166 diff[2] = State::getCameraNode()->getAbsCoor().z + 20; 167 diff[1] = State::getCameraNode()->getAbsCoor().y; 168 fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); 169 glFogCoordfEXT(fog_c*2); 170 glVertex3f(i,0,20); 189 171 190 191 192 193 194 195 172 diff[0] = State::getCameraNode()->getAbsCoor().x - i; 173 diff[2] = State::getCameraNode()->getAbsCoor().z + 20; 174 diff[1] = State::getCameraNode()->getAbsCoor().y; 175 fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); 176 glFogCoordfEXT(fog_c*2); 177 glVertex3f(-20,0,i); 196 178 197 198 199 200 201 202 203 204 179 diff[0] = State::getCameraNode()->getAbsCoor().x - i; 180 diff[2] = State::getCameraNode()->getAbsCoor().z + 20; 181 diff[1] = State::getCameraNode()->getAbsCoor().y; 182 fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); 183 glFogCoordfEXT(fog_c*2); 184 glVertex3f(20,0,i); 185 } 186 glEnd(); 205 187 206 glPopAttrib();188 glPopAttrib(); 207 189 208 190 } … … 212 194 * ticks the effect if there is any time dependancy 213 195 */ 214 void VolFogEffect::tick(float dt) 215 { 216 } 196 void VolFogEffect::tick(float dt) {}
Note: See TracChangeset
for help on using the changeset viewer.