2
Copyright (C) 2006 Parallel Realities
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
See the GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
// Just contains lots of misc drawing related functions...
25
bool withinViewableRange(Entity *entity)
27
if (entity->cluster != -1)
29
if (isClusterVisible(entity->cluster) == 0)
35
return camera->frustum.containsEntity(entity);
38
void drawCyclinder(Vector position, int segments, float size, float height, GLColor c)
44
glEnable(GL_TEXTURE_2D);
45
glDepthMask(GL_FALSE);
47
glBindTexture(GL_TEXTURE_2D, textureManager->getTexture("textures/game/fire.png")->data);
49
for (int i = 0 ; i < segments ; i++)
52
f1 -= graphics->getAnimTimer() * 0.05;
55
f2 = ((i + 1) * 2 * PI);
56
f2 -= graphics->getAnimTimer() * 0.05;
60
v1.x += (cos(f1) * size);
61
v1.y += (sin(f1) * size);
64
v2.x += (cos(f2) * size);
65
v2.y += (sin(f2) * size);
73
glTexCoord2f(0.0, 1.0); glVertex3f(v1.x, v1.y, v1.z);
74
glTexCoord2f(1.0, 1.0); glVertex3f(v2.x, v2.y, v2.z);
75
glTexCoord2f(1.0, 0.0); glVertex3f(v2.x, v2.y, v2.z + height);
76
glTexCoord2f(0.0, 0.0); glVertex3f(v1.x, v1.y, v1.z + height);
86
void drawBox(Vector position, float width, float length, float height, float tcm)
94
glTranslatef(position.x, position.y, position.z);
98
glTexCoord2f(tcm, tcm); glVertex3f( width, length, -height);
99
glTexCoord2f(0.0, tcm); glVertex3f(-width, length, -height);
100
glTexCoord2f(0.0, 0.0); glVertex3f(-width, length, height);
101
glTexCoord2f(tcm, 0.0); glVertex3f( width, length, height);
103
glTexCoord2f(0.0, 0.0); glVertex3f( width,-length, height);
104
glTexCoord2f(tcm, 0.0); glVertex3f(-width,-length, height);
105
glTexCoord2f(tcm, tcm); glVertex3f(-width,-length, -height);
106
glTexCoord2f(0.0, tcm); glVertex3f( width,-length, -height);
109
glTexCoord2f(0.0, 0.0); glVertex3f( width, length, height);
110
glTexCoord2f(tcm, 0.0); glVertex3f(-width, length, height);
111
glTexCoord2f(tcm, tcm); glVertex3f(-width,-length, height);
112
glTexCoord2f(0.0, tcm); glVertex3f( width,-length, height);
115
glTexCoord2f(0.0, 0.0); glVertex3f( width,-length, -height);
116
glTexCoord2f(tcm, 0.0); glVertex3f(-width,-length, -height);
117
glTexCoord2f(tcm, tcm); glVertex3f(-width, length, -height);
118
glTexCoord2f(0.0, tcm); glVertex3f( width, length, -height);
120
glTexCoord2f(tcm, 0.0); glVertex3f(-width, length, height);
121
glTexCoord2f(tcm, tcm); glVertex3f(-width, length, -height);
122
glTexCoord2f(0.0, tcm); glVertex3f(-width,-length, -height);
123
glTexCoord2f(0.0, 0.0); glVertex3f(-width,-length, height);
125
glTexCoord2f(0.0, tcm); glVertex3f( width, length, -height);
126
glTexCoord2f(0.0, 0.0); glVertex3f( width, length, height);
127
glTexCoord2f(tcm, 0.0); glVertex3f( width,-length, height);
128
glTexCoord2f(tcm, tcm); glVertex3f( width,-length, -height);
135
void drawBoundingBox(Entity *entity)
137
glColor4f(0.75, 0.75, 1.0, 0.25);
139
glDisable(GL_TEXTURE_2D);
142
drawBox(entity->position, entity->boundingBox.maxs.x * 2, entity->boundingBox.maxs.y * 2, entity->boundingBox.maxs.z * 2, 1);
145
glEnable(GL_TEXTURE_2D);
148
void drawSelectedUnit()
154
if ((player->target == NULL) || (game->cutsceneType != CUTSCENE_NONE))
161
c += 0.01 * engine->getTimeDifference(TD_ANIMATION);
170
c -= 0.01 * engine->getTimeDifference(TD_ANIMATION);
178
point = graphics->convertToScreenCoords(player->target->position);
180
graphics->setMode(MODE_2D);
182
glColor4f(0.0, 1.0, 0.0, c);
184
if (game->autoFaceTimer > 0)
186
glColor4f(1.0, 0.0, 0.0, c);
189
graphics->blit(textureManager->getTexture("textures/game/targetter.png"), (int)point.x, (int)point.y, true);
190
graphics->setMode(MODE_3D);
193
void drawSkyDome(Vector position, int size, Texture *texture)
195
glDepthMask(GL_FALSE);
200
glEnable(GL_TEXTURE_2D);
202
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
203
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
205
glBindTexture(GL_TEXTURE_2D, texture->data);
207
drawBox(position, 24, 24, 24, mission->skySphereSize);
211
glDepthMask(GL_TRUE);
213
glDisable(GL_TEXTURE_GEN_S);
214
glDisable(GL_TEXTURE_GEN_T);
217
void enableMultiTexturing()
219
glPushAttrib(GL_ALL_ATTRIB_BITS);
223
glActiveTextureARB(GL_TEXTURE0_ARB);
225
glEnable(GL_TEXTURE_2D);
227
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
231
glActiveTextureARB(GL_TEXTURE1_ARB);
233
glEnable(GL_TEXTURE_2D);
235
/* Set up environment to draw textures, lightmaps etc. */
237
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
239
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
240
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
242
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
244
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE);
245
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
247
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
249
/* Set back to unit 0 */
251
glActiveTextureARB(GL_TEXTURE0_ARB);
253
glEnableClientState(GL_VERTEX_ARRAY);
254
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
256
glClientActiveTextureARB(GL_TEXTURE1_ARB);
257
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
259
glClientActiveTextureARB(GL_TEXTURE0_ARB);
262
void finishMultiTexturing()
264
glActiveTextureARB(GL_TEXTURE1_ARB);
265
glDisable(GL_TEXTURE_2D);
267
glActiveTextureARB(GL_TEXTURE0_ARB);
269
glClientActiveTextureARB(GL_TEXTURE1_ARB);
270
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
271
glClientActiveTextureARB(GL_TEXTURE0_ARB);
273
glDisableClientState(GL_VERTEX_ARRAY);
274
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
279
void renderScaledTexture(Texture *texture)
281
glEnable(GL_TEXTURE_2D);
283
float scaleX = graphics->screen->w;
284
scaleX /= texture->iw;
286
float scaleY = graphics->screen->h;
287
scaleY /= texture->ih;
289
glBindTexture(GL_TEXTURE_2D, texture->data);
293
glTexCoord2f(0.0f, 0.0f); glVertex2f(0, 0);
294
glTexCoord2f(1.0f, 0.0f); glVertex2f(texture->tw * scaleX, 0);
295
glTexCoord2f(1.0f, 1.0f); glVertex2f(texture->tw * scaleX, texture->th * scaleY);
296
glTexCoord2f(0.0f, 1.0f); glVertex2f(0, texture->th * scaleY);