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 | #include "shell_command.h" |
---|
22 | |
---|
23 | using namespace std; |
---|
24 | |
---|
25 | CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT); |
---|
26 | |
---|
27 | VolFogEffect::VolFogEffect(const TiXmlElement* root) |
---|
28 | { |
---|
29 | this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect"); |
---|
30 | |
---|
31 | if (root != NULL) |
---|
32 | this->loadParams(root); |
---|
33 | |
---|
34 | // Initialize Effect |
---|
35 | this->init(); |
---|
36 | |
---|
37 | // Activate Effect |
---|
38 | this->activate(); |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | VolFogEffect::~VolFogEffect() |
---|
43 | { |
---|
44 | this->deactivate(); |
---|
45 | } |
---|
46 | |
---|
47 | void VolFogEffect::loadParams(const TiXmlElement* root) |
---|
48 | { |
---|
49 | WeatherEffect::loadParams(root); |
---|
50 | } |
---|
51 | |
---|
52 | bool VolFogEffect::init() |
---|
53 | { |
---|
54 | PRINTF(0)("Initalize VolFogEffect\n"); |
---|
55 | |
---|
56 | // Set fog color |
---|
57 | float fogColor[4] = {0.2, 0.2, 0.2, 1.0}; |
---|
58 | |
---|
59 | /* set up fog params */ |
---|
60 | glEnable(GL_FOG); // Enable Fog |
---|
61 | glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Fade Is Linear |
---|
62 | glFogfv(GL_FOG_COLOR, fogColor); // Set The Fog Color |
---|
63 | glFogf(GL_FOG_START, 0.0f); // Set The Fog Start |
---|
64 | glFogf(GL_FOG_END, 10.0f); // Set The Fog End |
---|
65 | glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); // Set The Fog based on vertice coordinates |
---|
66 | // glHint(GL_FOG_HINT, GL_NICEST); // Per-Pixel Fog Calculation |
---|
67 | |
---|
68 | // glClearColor(0.0, 0.0, 0.0, 1.0); //sets bg color?! |
---|
69 | |
---|
70 | /* enable texturing & set texturing function */ |
---|
71 | // glEnable(GL_TEXTURE_2D); |
---|
72 | // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
---|
73 | |
---|
74 | // ********************************************* |
---|
75 | |
---|
76 | char extensions[ 16384 ]; |
---|
77 | char Extension_Name[] = "GL_EXT_fog_coord"; |
---|
78 | char *buf; |
---|
79 | |
---|
80 | sprintf( extensions, "%s", (char *)glGetString( GL_EXTENSIONS ) ); |
---|
81 | buf = strtok( extensions, " " ); |
---|
82 | while( buf != NULL ) |
---|
83 | { |
---|
84 | if( !strcmp( Extension_Name, buf ) ) |
---|
85 | { |
---|
86 | PRINTF(0)( "%s found, great.\n", Extension_Name ); |
---|
87 | return true; |
---|
88 | } |
---|
89 | buf = strtok( NULL, " " ); |
---|
90 | } |
---|
91 | |
---|
92 | PRINTF(0)( "%s\n", (char *)glGetString( GL_EXTENSIONS ) ); |
---|
93 | PRINTF(0)( "%s not found.\n", Extension_Name ); |
---|
94 | return false; |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | bool VolFogEffect::activate() |
---|
99 | { |
---|
100 | PRINTF(0)("Activating VolFogEffect\n"); |
---|
101 | } |
---|
102 | |
---|
103 | bool VolFogEffect::deactivate() |
---|
104 | { |
---|
105 | PRINTF(0)("Deactivating VolFogEffect\n"); |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | /** |
---|
110 | * draws the effect, if needed |
---|
111 | */ |
---|
112 | void VolFogEffect::draw() const |
---|
113 | { |
---|
114 | //glPushAttrib(GL_ENABLE_BIT); |
---|
115 | |
---|
116 | /* clear all pixels in colour buffer */ |
---|
117 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
---|
118 | |
---|
119 | glEnable(GL_BLEND); |
---|
120 | glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); |
---|
121 | |
---|
122 | //glLoadIdentity (); // Reset The Modelview Matrix |
---|
123 | |
---|
124 | // glBindTexture(GL_TEXTURE_2D, 0); |
---|
125 | /* draw the panels */ |
---|
126 | glBegin(GL_QUADS); // Floor |
---|
127 | glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,0.0f); |
---|
128 | glFogCoordfEXT(0.0f); glVertex3f(100.0f,0.0f,0.0f); |
---|
129 | glFogCoordfEXT(0.0f); glVertex3f(100.0f,0.0f, 100.0f); |
---|
130 | glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f, 100.0f); |
---|
131 | glEnd(); |
---|
132 | |
---|
133 | glBegin(GL_QUADS); // Roof |
---|
134 | glFogCoordfEXT(5.0f); glVertex3f(0.0f, 100.0f,0.0f); |
---|
135 | glFogCoordfEXT(5.0f); glVertex3f( 100.0f, 100.0f,0.0f); |
---|
136 | glFogCoordfEXT(5.0f); glVertex3f( 100.0f, 100.0f, 100.0f); |
---|
137 | glFogCoordfEXT(5.0f); glVertex3f(0.0f, 100.0f, 100.0f); |
---|
138 | glEnd(); |
---|
139 | |
---|
140 | glBegin(GL_QUADS); // Back Wall |
---|
141 | glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,0.0f); |
---|
142 | glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f,0.0f); |
---|
143 | glFogCoordfEXT(5.0f); glVertex3f( 100.0f, 100.0f,0.0f); |
---|
144 | glFogCoordfEXT(5.0f); glVertex3f(0.0f, 100.0f,0.0f); |
---|
145 | glEnd(); |
---|
146 | |
---|
147 | glBegin(GL_QUADS); // Front Wall |
---|
148 | glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,100.0f); |
---|
149 | glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f,100.0f); |
---|
150 | glFogCoordfEXT(50.0f); glVertex3f( 100.0f, 100.0f,100.0f); |
---|
151 | glFogCoordfEXT(50.0f); glVertex3f(0.0f, 100.0f,100.0f); |
---|
152 | glEnd(); |
---|
153 | |
---|
154 | glBegin(GL_QUADS); // Right Wall |
---|
155 | glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f, 100.0f); |
---|
156 | glFogCoordfEXT(5.0f); glVertex3f( 100.0f, 100.0f, 100.0f); |
---|
157 | glFogCoordfEXT(5.0f); glVertex3f( 100.0f, 100.0f,0.0f); |
---|
158 | glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f,0.0f); |
---|
159 | glEnd(); |
---|
160 | |
---|
161 | glBegin(GL_QUADS); // Left Wall |
---|
162 | glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f, 100.0f); |
---|
163 | glFogCoordfEXT(5.0f); glVertex3f(0.0f, 100.0f, 100.0f); |
---|
164 | glFogCoordfEXT(5.0f); glVertex3f(0.0f, 100.0f,0.0f); |
---|
165 | glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,0.0f); |
---|
166 | glEnd(); |
---|
167 | |
---|
168 | /* process all buffered OpenGL commands */ |
---|
169 | glFlush(); |
---|
170 | |
---|
171 | // glPopAttrib(); |
---|
172 | } |
---|
173 | |
---|
174 | |
---|
175 | /** |
---|
176 | * ticks the effect if there is any time dependancy |
---|
177 | */ |
---|
178 | void VolFogEffect::tick(float dt) |
---|
179 | { |
---|
180 | } |
---|