[7504] | 1 | /* |
---|
[8495] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
[7504] | 3 | |
---|
[8495] | 4 | Copyright (C) 2004 orx |
---|
[7504] | 5 | |
---|
[8495] | 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. |
---|
[7504] | 10 | |
---|
| 11 | ### File Specific: |
---|
[8495] | 12 | main-programmer: hdavid, amaechler |
---|
[7504] | 13 | */ |
---|
| 14 | |
---|
| 15 | #include "volfog_effect.h" |
---|
| 16 | |
---|
| 17 | #include "util/loading/load_param.h" |
---|
| 18 | #include "util/loading/factory.h" |
---|
| 19 | |
---|
[7760] | 20 | #include "p_node.h" |
---|
| 21 | #include "state.h" |
---|
| 22 | |
---|
[8495] | 23 | #include "glincl.h" |
---|
| 24 | //#include "shell_command.h" |
---|
[9727] | 25 | #include "debug.h" |
---|
[7504] | 26 | |
---|
[9727] | 27 | |
---|
[7759] | 28 | #define GLX_GLXEXT_PROTOTYPES |
---|
[8523] | 29 | //#include <GL/glx.h> |
---|
[7795] | 30 | // #include <GL/glut.h> |
---|
[7759] | 31 | |
---|
| 32 | //#include <GL/glext.h> //OpenGL Extensions |
---|
[8316] | 33 | //#include <GL/glxext.h> // GLX Extensions |
---|
[7759] | 34 | |
---|
| 35 | #ifndef GL_EXT_fog_coord |
---|
| 36 | #define GL_EXT_fog_coord 1 |
---|
| 37 | typedef void (APIENTRY * PFNGLFOGCOORDFEXTPROC) (GLfloat coord); |
---|
| 38 | typedef void (APIENTRY * PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord); |
---|
| 39 | typedef void (APIENTRY * PFNGLFOGCOORDDEXTPROC) (GLdouble coord); |
---|
| 40 | typedef void (APIENTRY * PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord); |
---|
| 41 | typedef void (APIENTRY * PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); |
---|
| 42 | #endif |
---|
| 43 | |
---|
| 44 | PFNGLFOGCOORDFEXTPROC glFogCoordfEXT = 0; |
---|
| 45 | PFNGLFOGCOORDFVEXTPROC glFogCoordfvEXT = 0; |
---|
| 46 | PFNGLFOGCOORDDEXTPROC glFogCoorddEXT = 0; |
---|
| 47 | PFNGLFOGCOORDDVEXTPROC glFogCoorddvEXT = 0; |
---|
| 48 | PFNGLFOGCOORDPOINTEREXTPROC glFogCoordPointerEXT = 0; |
---|
| 49 | |
---|
| 50 | |
---|
[10114] | 51 | |
---|
| 52 | ObjectListDefinition(VolFogEffect); |
---|
[9709] | 53 | CREATE_FACTORY(VolFogEffect); |
---|
[7504] | 54 | |
---|
[8495] | 55 | VolFogEffect::VolFogEffect(const TiXmlElement* root) { |
---|
[9686] | 56 | this->registerObject(this, VolFogEffect::_objectList); |
---|
[7504] | 57 | |
---|
[8495] | 58 | if (root != NULL) |
---|
| 59 | this->loadParams(root); |
---|
[7532] | 60 | |
---|
[8495] | 61 | // Initialize Effect |
---|
| 62 | this->init(); |
---|
[7546] | 63 | |
---|
[8495] | 64 | // Activate Effect |
---|
| 65 | this->activate(); |
---|
[7504] | 66 | } |
---|
| 67 | |
---|
| 68 | |
---|
[8495] | 69 | VolFogEffect::~VolFogEffect() { |
---|
| 70 | this->deactivate(); |
---|
[7504] | 71 | } |
---|
| 72 | |
---|
[8495] | 73 | void VolFogEffect::loadParams(const TiXmlElement* root) { |
---|
| 74 | WeatherEffect::loadParams(root); |
---|
[7504] | 75 | } |
---|
| 76 | |
---|
[8495] | 77 | void VolFogEffect::init() { |
---|
[9006] | 78 | PRINTF(3)("Initalize VolFogEffect\n"); |
---|
[7504] | 79 | |
---|
[8495] | 80 | // set fog mode |
---|
| 81 | GLenum fogMode = GL_EXP; |
---|
[7759] | 82 | |
---|
[8495] | 83 | // set fog density |
---|
| 84 | float fogDensity = 0.001f; |
---|
[7759] | 85 | |
---|
[8495] | 86 | // set fog near & far distance |
---|
| 87 | float fogStart = 0.0f; |
---|
| 88 | float fogEnd = 1000.0f; |
---|
[7759] | 89 | |
---|
[8495] | 90 | // Set fog color |
---|
| 91 | float fogColor[4] = {0.6f,0.58f,0.79f,0.0f}; |
---|
[7504] | 92 | |
---|
[8316] | 93 | |
---|
[8523] | 94 | /* glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfEXT"); |
---|
[8495] | 95 | glFogCoordfvEXT = (PFNGLFOGCOORDFVEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfvEXT"); |
---|
| 96 | glFogCoorddEXT = (PFNGLFOGCOORDDEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoorddEXT"); |
---|
| 97 | glFogCoorddvEXT = (PFNGLFOGCOORDDVEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoorddvEXT"); |
---|
| 98 | glFogCoordPointerEXT = (PFNGLFOGCOORDPOINTEREXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordPointerEXT"); |
---|
[8523] | 99 | */ |
---|
[8495] | 100 | // set the fog attributes |
---|
| 101 | glFogf (GL_FOG_START, fogStart); |
---|
| 102 | glFogf (GL_FOG_END, fogEnd); |
---|
| 103 | glFogfv(GL_FOG_COLOR, fogColor); |
---|
| 104 | glFogi (GL_FOG_MODE, fogMode); |
---|
| 105 | glFogf (GL_FOG_DENSITY,fogDensity); |
---|
| 106 | glFogi (GL_FOG_COORDINATE_SOURCE_EXT,GL_FOG_COORDINATE_EXT); |
---|
[7561] | 107 | |
---|
[8495] | 108 | // enable the fog |
---|
| 109 | glEnable(GL_FOG); |
---|
[7557] | 110 | |
---|
[8495] | 111 | if (glewInit() == GLEW_OK) |
---|
[9006] | 112 | PRINTF(4)("glewInit OK\n"); |
---|
[8495] | 113 | else |
---|
[9006] | 114 | PRINTF(4)("glewInit failed\n"); |
---|
[7759] | 115 | |
---|
[8495] | 116 | if (glewGetExtension("GL_EXT_fog_coord")) |
---|
[9006] | 117 | PRINTF(4)("GL_EXT_fog_coord extension found\n"); |
---|
[7546] | 118 | } |
---|
| 119 | |
---|
| 120 | |
---|
[8495] | 121 | void VolFogEffect::activate() { |
---|
[9006] | 122 | PRINTF(3)("Activating VolFogEffect\n"); |
---|
[7504] | 123 | } |
---|
| 124 | |
---|
[8495] | 125 | void VolFogEffect::deactivate() { |
---|
[9006] | 126 | PRINTF(3)("Deactivating VolFogEffect\n"); |
---|
[7760] | 127 | |
---|
[8495] | 128 | glDisable(GL_FOG); |
---|
[7504] | 129 | } |
---|
| 130 | |
---|
[7520] | 131 | |
---|
[7516] | 132 | /** |
---|
[7652] | 133 | * draws the effect, if needed |
---|
| 134 | */ |
---|
[8495] | 135 | void VolFogEffect::draw() const { |
---|
| 136 | glPushAttrib(GL_ENABLE_BIT); |
---|
| 137 | glClearColor(fogColor[0],fogColor[1],fogColor[2],0.0f); |
---|
| 138 | glShadeModel(GL_SMOOTH); |
---|
| 139 | glEnable(GL_DEPTH_TEST); |
---|
| 140 | glEnable(GL_CULL_FACE); |
---|
| 141 | glCullFace(GL_BACK); |
---|
[7760] | 142 | |
---|
[8495] | 143 | /* clear all pixels in colour buffer */ |
---|
| 144 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
---|
[7530] | 145 | |
---|
[8495] | 146 | /* Enable blending */ |
---|
| 147 | //glEnable(GL_BLEND); |
---|
| 148 | //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); |
---|
[8316] | 149 | |
---|
[8495] | 150 | int i; |
---|
| 151 | glLoadIdentity(); |
---|
[7558] | 152 | |
---|
[8316] | 153 | |
---|
[8495] | 154 | glBegin( GL_LINES ); |
---|
| 155 | glNormal3f(0,1,0); |
---|
| 156 | for(i=-20;i<=20;i+=2) { |
---|
| 157 | float fog_c; |
---|
| 158 | float diff[3]; |
---|
[7520] | 159 | |
---|
[8495] | 160 | diff[0] = State::getCameraNode()->getAbsCoor().x - i; |
---|
| 161 | diff[2] = State::getCameraNode()->getAbsCoor().z + 20; |
---|
| 162 | diff[1] = State::getCameraNode()->getAbsCoor().y; |
---|
| 163 | fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); |
---|
| 164 | glFogCoordfEXT(fog_c*2); |
---|
| 165 | glVertex3f(i,0,-20); |
---|
[7520] | 166 | |
---|
[8495] | 167 | diff[0] = State::getCameraNode()->getAbsCoor().x - i; |
---|
| 168 | diff[2] = State::getCameraNode()->getAbsCoor().z + 20; |
---|
| 169 | diff[1] = State::getCameraNode()->getAbsCoor().y; |
---|
| 170 | fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); |
---|
| 171 | glFogCoordfEXT(fog_c*2); |
---|
| 172 | glVertex3f(i,0,20); |
---|
[7520] | 173 | |
---|
[8495] | 174 | diff[0] = State::getCameraNode()->getAbsCoor().x - i; |
---|
| 175 | diff[2] = State::getCameraNode()->getAbsCoor().z + 20; |
---|
| 176 | diff[1] = State::getCameraNode()->getAbsCoor().y; |
---|
| 177 | fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); |
---|
| 178 | glFogCoordfEXT(fog_c*2); |
---|
| 179 | glVertex3f(-20,0,i); |
---|
[7546] | 180 | |
---|
[8495] | 181 | diff[0] = State::getCameraNode()->getAbsCoor().x - i; |
---|
| 182 | diff[2] = State::getCameraNode()->getAbsCoor().z + 20; |
---|
| 183 | diff[1] = State::getCameraNode()->getAbsCoor().y; |
---|
| 184 | fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]); |
---|
| 185 | glFogCoordfEXT(fog_c*2); |
---|
| 186 | glVertex3f(20,0,i); |
---|
| 187 | } |
---|
| 188 | glEnd(); |
---|
[7546] | 189 | |
---|
[8495] | 190 | glPopAttrib(); |
---|
[7546] | 191 | |
---|
[7557] | 192 | } |
---|
[7546] | 193 | |
---|
| 194 | |
---|
[7516] | 195 | /** |
---|
[7652] | 196 | * ticks the effect if there is any time dependancy |
---|
| 197 | */ |
---|
[8495] | 198 | void VolFogEffect::tick(float dt) {} |
---|