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 | if (glewInit() == GLEW_OK) |
---|
57 | PRINTF(0)("glewInit OK\n"); |
---|
58 | else |
---|
59 | PRINTF(0)("glewInit failed\n"); |
---|
60 | |
---|
61 | // Set fog color |
---|
62 | float fogColor[4] = {0.0, 1.0, 0.0, 1.0}; |
---|
63 | |
---|
64 | /* set up fog params */ |
---|
65 | glEnable(GL_FOG); // Enable Fog |
---|
66 | glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Fade Is Linear |
---|
67 | glFogfv(GL_FOG_COLOR, fogColor); // Set The Fog Color |
---|
68 | glFogf(GL_FOG_START, 0.0f); // Set The Fog Start |
---|
69 | glFogf(GL_FOG_END, 1.0f); // Set The Fog End |
---|
70 | glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); // Set The Fog based on vertice coordinates |
---|
71 | // glHint(GL_FOG_HINT, GL_NICEST); // Per-Pixel Fog Calculation |
---|
72 | |
---|
73 | // glClearColor(0.0, 0.0, 0.0, 1.0); //sets bg color?! |
---|
74 | |
---|
75 | /* enable texturing & set texturing function */ |
---|
76 | // glEnable(GL_TEXTURE_2D); |
---|
77 | // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
---|
78 | |
---|
79 | if (glewGetExtension("GL_EXT_fog_coord")) |
---|
80 | { |
---|
81 | PRINTF(0)("GL_EXT_fog_coord extension found\n"); |
---|
82 | return true; |
---|
83 | } |
---|
84 | else |
---|
85 | { |
---|
86 | PRINTF(0)("GL_EXT_fog_coord extension NOT found\n"); |
---|
87 | return false; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | bool VolFogEffect::activate() |
---|
93 | { |
---|
94 | PRINTF(0)("Activating VolFogEffect\n"); |
---|
95 | } |
---|
96 | |
---|
97 | bool VolFogEffect::deactivate() |
---|
98 | { |
---|
99 | PRINTF(0)("Deactivating VolFogEffect\n"); |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | /** |
---|
104 | * draws the effect, if needed |
---|
105 | */ |
---|
106 | void VolFogEffect::draw() const |
---|
107 | { |
---|
108 | //glPushAttrib(GL_ENABLE_BIT); |
---|
109 | |
---|
110 | /* clear all pixels in colour buffer */ |
---|
111 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
---|
112 | |
---|
113 | /* Enable blending */ |
---|
114 | //glEnable(GL_BLEND); |
---|
115 | //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); |
---|
116 | |
---|
117 | //glLoadIdentity (); // Reset The Modelview Matrix |
---|
118 | |
---|
119 | // glBindTexture(GL_TEXTURE_2D, 0); |
---|
120 | /* draw the panels */ |
---|
121 | glBegin(GL_QUADS); // Floor |
---|
122 | glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,0.0f); |
---|
123 | glFogCoordfEXT(0.0f); glVertex3f(100.0f,0.0f,0.0f); |
---|
124 | glFogCoordfEXT(0.0f); glVertex3f(100.0f,0.0f, 100.0f); |
---|
125 | glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f, 100.0f); |
---|
126 | glEnd(); |
---|
127 | |
---|
128 | glBegin(GL_QUADS); // Roof |
---|
129 | glFogCoordfEXT(1.0f); glVertex3f(0.0f, 100.0f,0.0f); |
---|
130 | glFogCoordfEXT(1.0f); glVertex3f( 100.0f, 100.0f,0.0f); |
---|
131 | glFogCoordfEXT(1.0f); glVertex3f( 100.0f, 100.0f, 100.0f); |
---|
132 | glFogCoordfEXT(1.0f); glVertex3f(0.0f, 100.0f, 100.0f); |
---|
133 | glEnd(); |
---|
134 | |
---|
135 | glBegin(GL_QUADS); // Back Wall |
---|
136 | glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,0.0f); |
---|
137 | glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f,0.0f); |
---|
138 | glFogCoordfEXT(1.0f); glVertex3f( 100.0f, 100.0f,0.0f); |
---|
139 | glFogCoordfEXT(1.0f); glVertex3f(0.0f, 100.0f,0.0f); |
---|
140 | glEnd(); |
---|
141 | |
---|
142 | glBegin(GL_QUADS); // Front Wall |
---|
143 | glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,100.0f); |
---|
144 | glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f,100.0f); |
---|
145 | glFogCoordfEXT(1.0f); glVertex3f( 100.0f, 100.0f,100.0f); |
---|
146 | glFogCoordfEXT(1.0f); glVertex3f(0.0f, 100.0f,100.0f); |
---|
147 | glEnd(); |
---|
148 | |
---|
149 | glBegin(GL_QUADS); // Right Wall |
---|
150 | glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f, 100.0f); |
---|
151 | glFogCoordfEXT(1.0f); glVertex3f( 100.0f, 100.0f, 100.0f); |
---|
152 | glFogCoordfEXT(1.0f); glVertex3f( 100.0f, 100.0f,0.0f); |
---|
153 | glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f,0.0f); |
---|
154 | glEnd(); |
---|
155 | |
---|
156 | glBegin(GL_QUADS); // Left Wall |
---|
157 | glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f, 100.0f); |
---|
158 | glFogCoordfEXT(1.0f); glVertex3f(0.0f, 100.0f, 100.0f); |
---|
159 | glFogCoordfEXT(1.0f); glVertex3f(0.0f, 100.0f,0.0f); |
---|
160 | glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,0.0f); |
---|
161 | glEnd(); |
---|
162 | |
---|
163 | /* process all buffered OpenGL commands */ |
---|
164 | glFlush(); |
---|
165 | |
---|
166 | // glPopAttrib(); |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | /** |
---|
171 | * ticks the effect if there is any time dependancy |
---|
172 | */ |
---|
173 | void VolFogEffect::tick(float dt) |
---|
174 | { |
---|
175 | } |
---|