1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
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 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: hdavid, amaechler |
---|
13 | */ |
---|
14 | |
---|
15 | #include "volfog_effect.h" |
---|
16 | |
---|
17 | #include "util/loading/load_param.h" |
---|
18 | #include "util/loading/factory.h" |
---|
19 | |
---|
20 | #include "glincl.h" |
---|
21 | |
---|
22 | #include "shell_command.h" |
---|
23 | |
---|
24 | using namespace std; |
---|
25 | |
---|
26 | CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT); |
---|
27 | |
---|
28 | VolFogEffect::VolFogEffect(const TiXmlElement* root) |
---|
29 | { |
---|
30 | this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect"); |
---|
31 | |
---|
32 | if (root != NULL) |
---|
33 | this->loadParams(root); |
---|
34 | |
---|
35 | this->init(); |
---|
36 | |
---|
37 | //if (! this->init()) // Check And Enable Fog Extension If Available |
---|
38 | //return false; // Return False If Extension Not Supported |
---|
39 | |
---|
40 | // Set Up Fog |
---|
41 | //glEnable(GL_FOG); // Enable Fog |
---|
42 | //glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Fade Is Linear |
---|
43 | //glFogfv(GL_FOG_COLOR, fogColor); // Set The Fog Color |
---|
44 | //glFogf(GL_FOG_START, 1.0f); // Set The Fog Start |
---|
45 | //glFogf(GL_FOG_END, 0.0f); // Set The Fog End |
---|
46 | //glHint(GL_FOG_HINT, GL_NICEST); // Per-Pixel Fog Calculation |
---|
47 | //glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); // Set Fog Based On Vertice Coordinates |
---|
48 | |
---|
49 | this->activate(); |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | VolFogEffect::~VolFogEffect() |
---|
54 | { |
---|
55 | this->deactivate(); |
---|
56 | } |
---|
57 | |
---|
58 | void VolFogEffect::loadParams(const TiXmlElement* root) |
---|
59 | { |
---|
60 | WeatherEffect::loadParams(root); |
---|
61 | } |
---|
62 | |
---|
63 | bool VolFogEffect::init() |
---|
64 | { |
---|
65 | PRINTF(0)("Initalize VolFogEffect\n"); |
---|
66 | |
---|
67 | fogColor[0] = 0.6f; |
---|
68 | fogColor[1] = 0.3f; |
---|
69 | fogColor[2] = 0.0f; |
---|
70 | fogColor[3] = 1.0f; |
---|
71 | |
---|
72 | //glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing |
---|
73 | //glEnable (GL_DEPTH_TEST); // Enable Depth Testing |
---|
74 | //glShadeModel (GL_SMOOTH); // Select Smooth Shading |
---|
75 | //glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most AccurateAbility |
---|
76 | |
---|
77 | char extensions[ 16384 ]; |
---|
78 | char Extension_Name[] = "GL_EXT_fog_coord"; |
---|
79 | char *buf; |
---|
80 | |
---|
81 | sprintf( extensions, "%s", (char *)glGetString( GL_EXTENSIONS ) ); |
---|
82 | buf = strtok( extensions, " " ); |
---|
83 | while( buf != NULL ) |
---|
84 | { |
---|
85 | if( !strcmp( Extension_Name, buf ) ) |
---|
86 | { |
---|
87 | PRINTF(0)( "%s found, great.\n", Extension_Name ); |
---|
88 | return true; |
---|
89 | } |
---|
90 | buf = strtok( NULL, " " ); |
---|
91 | } |
---|
92 | |
---|
93 | PRINTF(0)( "%s\n", (char *)glGetString( GL_EXTENSIONS ) ); |
---|
94 | PRINTF(0)( "%s not found, dammit.\n", Extension_Name ); |
---|
95 | return false; |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | bool VolFogEffect::activate() |
---|
100 | { |
---|
101 | PRINTF(0)("Activating VolFogEffect\n"); |
---|
102 | } |
---|
103 | |
---|
104 | bool VolFogEffect::deactivate() |
---|
105 | { |
---|
106 | PRINTF(0)("Deactivating VolFogEffect\n"); |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | /** |
---|
111 | * draws the effect, if needed |
---|
112 | */ |
---|
113 | void VolFogEffect::draw() const |
---|
114 | { |
---|
115 | glPushAttrib(GL_ENABLE_BIT); |
---|
116 | |
---|
117 | glClearDepth (1.0f); |
---|
118 | glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing |
---|
119 | glEnable (GL_DEPTH_TEST); // Enable Depth Testing |
---|
120 | glShadeModel (GL_SMOOTH); // Select Smooth Shading |
---|
121 | glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most AccurateAbili |
---|
122 | |
---|
123 | |
---|
124 | // Set Up Fog |
---|
125 | glEnable(GL_FOG); // Enable Fog |
---|
126 | glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Fade Is Linear |
---|
127 | glFogfv(GL_FOG_COLOR, fogColor); // Set The Fog Color |
---|
128 | glFogf(GL_FOG_START, 1.0f); // Set The Fog Start |
---|
129 | glFogf(GL_FOG_END, 0.0f); // Set The Fog End |
---|
130 | glHint(GL_FOG_HINT, GL_NICEST); // Per-Pixel Fog Calculation |
---|
131 | glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); // Set Fog Based On Vertice Coordinates |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | //glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer |
---|
136 | //glLoadIdentity (); // Reset The Modelview Matrix |
---|
137 | |
---|
138 | //glTranslatef(camx, 0.0f, camz); // Move To Our Camera Z/X Position |
---|
139 | |
---|
140 | // glFogCoordEXT is very similar to glVertex3f. If you understand |
---|
141 | // the way vertexs are applied in OpenGL, you will not have any dificulty |
---|
142 | // understanding glFogCoordEXT. |
---|
143 | |
---|
144 | // In this tutorial we are applyng the fog in a corridor, so the fog |
---|
145 | // goes from the less density (the minor z) to a bigger density (the biggest z). |
---|
146 | // If you check the fog_start and fog_eng, it's 0 and 1. |
---|
147 | |
---|
148 | // So, we will pass to the function glFogCoordEXT, the fog value corresponding |
---|
149 | // with the glVertex3f value.If we are drawing a quad from z minus to z major, |
---|
150 | // we do exactly the same with glFogCoord. |
---|
151 | |
---|
152 | // For example, in the first quad, is vertex coordinates in the Z field are all |
---|
153 | // -15.0f. So we want the fog to completely fill this quad, so we assign 0 to all |
---|
154 | // the glFogCoordExt. |
---|
155 | |
---|
156 | glBegin(GL_QUADS); // Back Wall |
---|
157 | glFogCoordfEXT( 0.0f); glVertex3f(-2.5f,-2.5f,-15.0f); |
---|
158 | glFogCoordfEXT( 0.0f); glVertex3f( 2.5f,-2.5f,-15.0f); |
---|
159 | glFogCoordfEXT( 0.0f); glVertex3f( 2.5f, 2.5f,-15.0f); |
---|
160 | glFogCoordfEXT( 0.0f); glVertex3f(-2.5f, 2.5f,-15.0f); |
---|
161 | glEnd(); |
---|
162 | |
---|
163 | glBegin(GL_QUADS); // Floor |
---|
164 | glFogCoordfEXT( 0.0f); glVertex3f(-2.5f,-2.5f,-15.0f); |
---|
165 | glFogCoordfEXT( 0.0f); glVertex3f( 2.5f,-2.5f,-15.0f); |
---|
166 | glFogCoordfEXT( 1.0f); glVertex3f( 2.5f,-2.5f, 15.0f); |
---|
167 | glFogCoordfEXT( 1.0f); glVertex3f(-2.5f,-2.5f, 15.0f); |
---|
168 | glEnd(); |
---|
169 | |
---|
170 | glBegin(GL_QUADS); // Roof |
---|
171 | glFogCoordfEXT( 0.0f); glVertex3f(-2.5f, 2.5f,-15.0f); |
---|
172 | glFogCoordfEXT( 0.0f); glVertex3f( 2.5f, 2.5f,-15.0f); |
---|
173 | glFogCoordfEXT( 1.0f); glVertex3f( 2.5f, 2.5f, 15.0f); |
---|
174 | glFogCoordfEXT( 1.0f); glVertex3f(-2.5f, 2.5f, 15.0f); |
---|
175 | glEnd(); |
---|
176 | |
---|
177 | glBegin(GL_QUADS); // Right Wall |
---|
178 | glFogCoordfEXT( 1.0f); glVertex3f( 2.5f,-2.5f, 15.0f); |
---|
179 | glFogCoordfEXT( 1.0f); glVertex3f( 2.5f, 2.5f, 15.0f); |
---|
180 | glFogCoordfEXT( 0.0f); glVertex3f( 2.5f, 2.5f,-15.0f); |
---|
181 | glFogCoordfEXT( 0.0f); glVertex3f( 2.5f,-2.5f,-15.0f); |
---|
182 | glEnd(); |
---|
183 | |
---|
184 | glBegin(GL_QUADS); // Left Wall |
---|
185 | glFogCoordfEXT( 1.0f); glVertex3f(-2.5f,-2.5f, 15.0f); |
---|
186 | glFogCoordfEXT( 1.0f); glVertex3f(-2.5f, 2.5f, 15.0f); |
---|
187 | glFogCoordfEXT( 0.0f); glVertex3f(-2.5f, 2.5f,-15.0f); |
---|
188 | glFogCoordfEXT( 0.0f); glVertex3f(-2.5f,-2.5f,-15.0f); |
---|
189 | glEnd(); |
---|
190 | |
---|
191 | //glFlush (); // Flush The GL Rendering Pipeline |
---|
192 | glPopAttrib(); |
---|
193 | } |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | /** |
---|
198 | * ticks the effect if there is any time dependancy |
---|
199 | */ |
---|
200 | void VolFogEffect::tick(float dt) |
---|
201 | { |
---|
202 | } |
---|