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