Changeset 8457 in orxonox.OLD for branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc
- Timestamp:
- Jun 15, 2006, 1:43:24 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc
r8455 r8457 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 … … 51 51 CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT); 52 52 53 VolFogEffect::VolFogEffect(const TiXmlElement* root) 54 { 55 this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect"); 53 VolFogEffect::VolFogEffect(const TiXmlElement* root) { 54 this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect"); 56 55 57 58 56 if (root != NULL) 57 this->loadParams(root); 59 58 60 61 59 // Initialize Effect 60 this->init(); 62 61 63 64 62 // Activate Effect 63 this->activate(); 65 64 } 66 65 67 66 68 VolFogEffect::~VolFogEffect() 69 { 70 this->deactivate(); 67 VolFogEffect::~VolFogEffect() { 68 this->deactivate(); 71 69 } 72 70 73 void VolFogEffect::loadParams(const TiXmlElement* root) 74 { 75 WeatherEffect::loadParams(root); 71 void VolFogEffect::loadParams(const TiXmlElement* root) { 72 WeatherEffect::loadParams(root); 76 73 } 77 74 78 void VolFogEffect::init() 79 { 80 PRINTF(0)("Initalize VolFogEffect\n"); 75 void VolFogEffect::init() { 76 PRINTF(0)("Initalize VolFogEffect\n"); 81 77 82 83 78 // set fog mode 79 GLenum fogMode = GL_EXP; 84 80 85 86 81 // set fog density 82 float fogDensity = 0.001f; 87 83 88 89 90 84 // set fog near & far distance 85 float fogStart = 0.0f; 86 float fogEnd = 1000.0f; 91 87 92 93 88 // Set fog color 89 float fogColor[4] = {0.6f,0.58f,0.79f,0.0f}; 94 90 95 91 96 97 98 99 100 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"); 101 97 102 103 104 105 106 107 108 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); 109 105 110 111 106 // enable the fog 107 glEnable(GL_FOG); 112 108 113 114 115 116 109 if (glewInit() == GLEW_OK) 110 PRINTF(0)("glewInit OK\n"); 111 else 112 PRINTF(0)("glewInit failed\n"); 117 113 118 119 114 if (glewGetExtension("GL_EXT_fog_coord")) 115 PRINTF(0)("GL_EXT_fog_coord extension found\n"); 120 116 } 121 117 122 118 123 void VolFogEffect::activate() 124 { 125 PRINTF(0)("Activating VolFogEffect\n"); 119 void VolFogEffect::activate() { 120 PRINTF(0)("Activating VolFogEffect\n"); 126 121 } 127 122 128 void VolFogEffect::deactivate() 129 { 130 PRINTF(0)("Deactivating VolFogEffect\n"); 123 void VolFogEffect::deactivate() { 124 PRINTF(0)("Deactivating VolFogEffect\n"); 131 125 132 126 glDisable(GL_FOG); 133 127 } 134 128 … … 137 131 * draws the effect, if needed 138 132 */ 139 void VolFogEffect::draw() const 140 { 141 glPushAttrib(GL_ENABLE_BIT); 142 glClearColor(fogColor[0],fogColor[1],fogColor[2],0.0f); 143 glShadeModel(GL_SMOOTH); 144 glEnable(GL_DEPTH_TEST); 145 glEnable(GL_CULL_FACE); 146 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); 147 140 148 149 141 /* clear all pixels in colour buffer */ 142 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 150 143 151 152 153 144 /* Enable blending */ 145 //glEnable(GL_BLEND); 146 //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); 154 147 155 156 148 int i; 149 glLoadIdentity(); 157 150 158 151 159 glBegin( GL_LINES ); 160 glNormal3f(0,1,0); 161 for(i=-20;i<=20;i+=2) 162 { 163 float fog_c; 164 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]; 165 157 166 167 168 169 170 171 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); 172 164 173 174 175 176 177 178 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); 179 171 180 181 182 183 184 185 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); 186 178 187 188 189 190 191 192 193 194 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(); 195 187 196 glPopAttrib();188 glPopAttrib(); 197 189 198 190 } … … 202 194 * ticks the effect if there is any time dependancy 203 195 */ 204 void VolFogEffect::tick(float dt) 205 { 206 } 196 void VolFogEffect::tick(float dt) {}
Note: See TracChangeset
for help on using the changeset viewer.