]> git.jsancho.org Git - lugaru.git/blob - Source/GameDraw.cpp
Removed unused globals
[lugaru.git] / Source / GameDraw.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
4
5 This file is part of Lugaru.
6
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "Game.h"
22 #include "openal_wrapper.h"
23 #include "Input.h"
24 #include "Awards.h"
25 #include "Menu.h"
26
27 extern XYZ viewer;
28 extern int environment;
29 extern float texscale;
30 extern Light light;
31 extern Terrain terrain;
32 extern float multiplier;
33 extern float viewdistance;
34 extern float fadestart;
35 extern float screenwidth, screenheight;
36 extern int kTextureSize;
37 extern FRUSTUM frustum;
38 extern Light light;
39 extern Objects objects;
40 extern int detail;
41 extern float usermousesensitivity;
42 extern float camerashake;
43 extern int slomo;
44 extern float slomodelay;
45 extern bool ismotionblur;
46 extern float woozy;
47 extern float blackout;
48 extern bool damageeffects;
49 extern float volume;
50 extern bool texttoggle;
51 extern float blurness;
52 extern float targetblurness;
53 extern float playerdist;
54 extern bool cellophane;
55 extern bool freeze;
56 extern float flashamount, flashr, flashg, flashb;
57 extern int flashdelay;
58 extern int netstate;
59 extern float motionbluramount;
60 extern bool isclient;
61 extern bool alwaysblur;
62 extern bool velocityblur;
63 extern bool debugmode;
64 extern int mainmenu;
65 extern int bloodtoggle;
66 extern int difficulty;
67 extern bool decals;
68 extern float texdetail;
69 extern bool musictoggle;
70 extern int tutoriallevel;
71 extern float smoketex;
72 extern float tutorialstagetime;
73 extern float tutorialmaxtime;
74 extern int tutorialstage;
75 extern bool againbonus;
76 extern float damagedealt;
77 extern bool invertmouse;
78
79 extern int numhotspots;
80 extern int killhotspot;
81 extern XYZ hotspot[40];
82 extern int hotspottype[40];
83 extern float hotspotsize[40];
84 extern char hotspottext[40][256];
85 extern int currenthotspot;;
86
87 extern bool campaign;
88 extern bool winfreeze;
89
90 extern bool gamestart;
91
92 extern bool gamestarted;
93
94 extern bool showdamagebar;
95
96
97
98 int drawtoggle = 0;
99 int numboundaries = 0;
100 XYZ boundary[360];
101 int change = 0;
102
103
104
105 enum drawmodes {
106     normalmode, motionblurmode, radialzoommode,
107     realmotionblurmode, doublevisionmode, glowmode,
108 };
109
110 void Game::flash()   // shouldn't be that way, these should be attributes and Person class should not change rendering.
111 {
112     flashr = 1;
113     flashg = 0;
114     flashb = 0;
115     flashamount = 1;
116     flashdelay = 1;
117 }
118
119 void DrawMenu();
120
121 /*********************> DrawGLScene() <*****/
122 int Game::DrawGLScene(StereoSide side)
123 {
124     static float texcoordwidth, texcoordheight;
125     static float texviewwidth, texviewheight;
126     static int l;
127     static XYZ checkpoint;
128     static float tempmult;
129     float tutorialopac;
130     static char string[256] = "";
131     static char string2[256] = "";
132     static char string3[256] = "";
133     static int drawmode = 0;
134
135     if ( stereomode == stereoAnaglyph ) {
136         switch (side) {
137         case stereoLeft:
138             glColorMask( 0.0, 1.0, 1.0, 1.0 );
139             break;
140         case stereoRight:
141             glColorMask( 1.0, 0.0, 0.0, 1.0 );
142             break;
143         default:
144             break;
145         }
146     } else {
147         glColorMask( 1.0, 1.0, 1.0, 1.0 );
148
149         if ( stereomode == stereoHorizontalInterlaced || stereomode == stereoVerticalInterlaced ) {
150             glStencilFunc(side == stereoLeft ? GL_NOTEQUAL : GL_EQUAL, 0x01, 0x01);
151         }
152     }
153
154     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
155         tempmult = multiplier;
156         multiplier = 0;
157     }
158
159     if (!mainmenu) {
160         if (editorenabled) {
161             numboundaries = mapradius * 2;
162             if (numboundaries > 360)
163                 numboundaries = 360;
164             for (int i = 0; i < numboundaries; i++) {
165                 boundary[i] = 0;
166                 boundary[i].z = 1;
167                 boundary[i] = mapcenter + DoRotation(boundary[i] * mapradius, 0, i * (360 / ((float)(numboundaries))), 0);
168             }
169         }
170
171         SetUpLighting();
172
173         static int changed;
174         changed = 0;
175
176         int olddrawmode = drawmode;
177         if (ismotionblur && !loading) {
178             if ((findLengthfast(&Person::players[0]->velocity) > 200) && velocityblur && !cameramode) {
179                 drawmode = motionblurmode;
180                 motionbluramount = 200 / (findLengthfast(&Person::players[0]->velocity));
181                 changed = 1;
182             }
183             if (Person::players[0]->damage - Person::players[0]->superpermanentdamage > (Person::players[0]->damagetolerance - Person::players[0]->superpermanentdamage) * 1 / 2 && damageeffects && !cameramode) {
184                 drawmode = doublevisionmode;
185                 changed = 1;
186             }
187         }
188
189         if (slomo && !loading) {
190             if (ismotionblur)
191                 drawmode = motionblurmode;
192             motionbluramount = .2;
193             slomodelay -= multiplier;
194             if (slomodelay < 0)
195                 slomo = 0;
196             camerashake = 0;
197             changed = 1;
198         }
199         if ((!changed && !slomo) || loading) {
200             drawmode = normalmode;
201             if (ismotionblur && (/*fps>100||*/alwaysblur)) {
202                 if (olddrawmode != realmotionblurmode)
203                     change = 1;
204                 else
205                     change = 0;
206                 drawmode = realmotionblurmode;
207             } else if (olddrawmode == realmotionblurmode)
208                 change = 2;
209             else
210                 change = 0;
211         }
212
213         if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted))
214             drawmode = normalmode;
215         if ((freeze || winfreeze) && ismotionblur && !mainmenu)
216             drawmode = radialzoommode;
217
218         if (winfreeze || mainmenu)
219             drawmode = normalmode;
220
221         if (drawtoggle != 2)
222             drawtoggle = 1 - drawtoggle;
223
224         if (!texcoordwidth) {
225             texviewwidth = kTextureSize;
226             if (texviewwidth > screenwidth)
227                 texviewwidth = screenwidth;
228             texviewheight = kTextureSize;
229             if (texviewheight > screenheight)
230                 texviewheight = screenheight;
231
232             texcoordwidth = screenwidth / kTextureSize;
233             texcoordheight = screenheight / kTextureSize;
234             if (texcoordwidth > 1)
235                 texcoordwidth = 1;
236             if (texcoordheight > 1)
237                 texcoordheight = 1;
238         }
239
240         glDrawBuffer(GL_BACK);
241         glReadBuffer(GL_BACK);
242
243         static XYZ terrainlight;
244         static float distance;
245         if (drawmode == normalmode)
246             Game::ReSizeGLScene(90, .1f);
247         if (drawmode != normalmode)
248             glViewport(0, 0, texviewwidth, texviewheight);
249         glDepthFunc(GL_LEQUAL);
250         glDepthMask(1);
251         glAlphaFunc(GL_GREATER, 0.0001f);
252         glEnable(GL_ALPHA_TEST);
253         glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
254         glClear(GL_DEPTH_BUFFER_BIT);
255
256         glMatrixMode (GL_MODELVIEW);
257         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
258         glLoadIdentity ();
259
260         // Move the camera for the current eye's point of view.
261         // Reverse the movement if we're reversing stereo
262         glTranslatef((stereoseparation / 2) * side * (stereoreverse  ? -1 : 1), 0, 0);
263
264         //camera effects
265         if (!cameramode && !freeze && !winfreeze) {
266             //shake
267             glRotatef(float(Random() % 100) / 10 * camerashake/*+(woozy*woozy)/10*/, 0, 0, 1);
268             //sway
269             glRotatef(pitch + sin(woozy / 2) * (Person::players[0]->damage / Person::players[0]->damagetolerance) * 5, 1, 0, 0);
270             glRotatef(yaw + sin(woozy) * (Person::players[0]->damage / Person::players[0]->damagetolerance) * 5, 0, 1, 0);
271         }
272         if (cameramode || freeze || winfreeze) {
273             glRotatef(pitch, 1, 0, 0);
274             glRotatef(yaw, 0, 1, 0);
275         }
276
277         if (environment == desertenvironment) {
278             glRotatef((float)(abs(Random() % 100)) / 3000 - 1, 1, 0, 0);
279             glRotatef((float)(abs(Random() % 100)) / 3000 - 1, 0, 1, 0);
280         }
281         SetUpLight(&light, 0);
282         glPushMatrix();
283
284         //heat blur effect in desert
285         if (abs(blurness - targetblurness) < multiplier * 10 || abs(blurness - targetblurness) > 2) {
286             blurness = targetblurness;
287             targetblurness = (float)(abs(Random() % 100)) / 40;
288         }
289         if (blurness < targetblurness)
290             blurness += multiplier * 5;
291         else
292             blurness -= multiplier * 5;
293
294         if (environment == desertenvironment && detail == 2)
295             glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness + .4 );
296         if (environment == desertenvironment) {
297             glRotatef((float)(abs(Random() % 100)) / 1000, 1, 0, 0);
298             glRotatef((float)(abs(Random() % 100)) / 1000, 0, 1, 0);
299         }
300         skybox->draw();
301         glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
302         glPopMatrix();
303         glTranslatef(-viewer.x, -viewer.y, -viewer.z);
304         frustum.GetFrustum();
305
306         //make shadow decals on terrain and objects
307         static XYZ point;
308         static float size, opacity, rotation;
309         rotation = 0;
310         for (unsigned k = 0; k < Person::players.size(); k++) {
311             if (!Person::players[k]->skeleton.free && Person::players[k]->playerdetail && Person::players[k]->howactive < typesleeping)
312                 if (frustum.SphereInFrustum(Person::players[k]->coords.x, Person::players[k]->coords.y + Person::players[k]->scale * 3, Person::players[k]->coords.z, Person::players[k]->scale * 7) && Person::players[k]->occluded < 25)
313                     for (int i = 0; i < Person::players[k]->skeleton.num_joints; i++) {
314                         if (Person::players[k]->skeleton.joints[i].label == leftknee || Person::players[k]->skeleton.joints[i].label == rightknee || Person::players[k]->skeleton.joints[i].label == groin) {
315                             point = DoRotation(Person::players[k]->skeleton.joints[i].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords;
316                             size = .4f;
317                             opacity = .4 - Person::players[k]->skeleton.joints[i].position.y * Person::players[k]->scale / 5 - (Person::players[k]->coords.y - terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z)) / 10;
318                             if (k != 0 && tutoriallevel == 1) {
319                                 opacity = .2 + .2 * sin(smoketex * 6 + i) - Person::players[k]->skeleton.joints[i].position.y * Person::players[k]->scale / 5 - (Person::players[k]->coords.y - terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z)) / 10;
320                             }
321                             terrain.MakeDecal(shadowdecal, point, size, opacity, rotation);
322                             for (l = 0; l < terrain.patchobjectnum[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz]; l++) {
323                                 int j = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
324                                 if (objects.position[j].y < Person::players[k]->coords.y || objects.type[j] == tunneltype || objects.type[j] == weirdtype) {
325                                     point = DoRotation(DoRotation(Person::players[k]->skeleton.joints[i].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords - objects.position[j], 0, -objects.yaw[j], 0);
326                                     size = .4f;
327                                     opacity = .4f;
328                                     if (k != 0 && tutoriallevel == 1) {
329                                         opacity = .2 + .2 * sin(smoketex * 6 + i);
330                                     }
331                                     objects.model[j].MakeDecal(shadowdecal, &point, &size, &opacity, &rotation);
332                                 }
333                             }
334                         }
335                     }
336             if ((Person::players[k]->skeleton.free || Person::players[k]->howactive >= typesleeping) && Person::players[k]->playerdetail)
337                 if (frustum.SphereInFrustum(Person::players[k]->coords.x, Person::players[k]->coords.y, Person::players[k]->coords.z, Person::players[k]->scale * 5) && Person::players[k]->occluded < 25)
338                     for (int i = 0; i < Person::players[k]->skeleton.num_joints; i++) {
339                         if (Person::players[k]->skeleton.joints[i].label == leftknee || Person::players[k]->skeleton.joints[i].label == rightknee || Person::players[k]->skeleton.joints[i].label == groin || Person::players[k]->skeleton.joints[i].label == leftelbow || Person::players[k]->skeleton.joints[i].label == rightelbow || Person::players[k]->skeleton.joints[i].label == neck) {
340                             if (Person::players[k]->skeleton.free)
341                                 point = Person::players[k]->skeleton.joints[i].position * Person::players[k]->scale + Person::players[k]->coords;
342                             else
343                                 point = DoRotation(Person::players[k]->skeleton.joints[i].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords;
344                             size = .4f;
345                             opacity = .4 - Person::players[k]->skeleton.joints[i].position.y * Person::players[k]->scale / 5 - (Person::players[k]->coords.y - terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z)) / 5;
346                             if (k != 0 && tutoriallevel == 1) {
347                                 opacity = .2 + .2 * sin(smoketex * 6 + i) - Person::players[k]->skeleton.joints[i].position.y * Person::players[k]->scale / 5 - (Person::players[k]->coords.y - terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z)) / 10;
348                             }
349                             terrain.MakeDecal(shadowdecal, point, size, opacity * .7, rotation);
350                             for (l = 0; l < terrain.patchobjectnum[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz]; l++) {
351                                 int j = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
352                                 if (objects.position[j].y < Person::players[k]->coords.y || objects.type[j] == tunneltype || objects.type[j] == weirdtype) {
353                                     if (Person::players[k]->skeleton.free)
354                                         point = DoRotation(Person::players[k]->skeleton.joints[i].position * Person::players[k]->scale + Person::players[k]->coords - objects.position[j], 0, -objects.yaw[j], 0);
355                                     else
356                                         point = DoRotation(DoRotation(Person::players[k]->skeleton.joints[i].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords - objects.position[j], 0, -objects.yaw[j], 0);
357                                     size = .4f;
358                                     opacity = .4f;
359                                     if (k != 0 && tutoriallevel == 1) {
360                                         opacity = .2 + .2 * sin(smoketex * 6 + i);
361                                     }
362                                     objects.model[j].MakeDecal(shadowdecal, &point, &size, &opacity, &rotation);
363                                 }
364                             }
365                         }
366                     }
367
368             if (!Person::players[k]->playerdetail)
369                 if (frustum.SphereInFrustum(Person::players[k]->coords.x, Person::players[k]->coords.y, Person::players[k]->coords.z, Person::players[k]->scale * 5)) {
370                     point = Person::players[k]->coords;
371                     size = .7;
372                     opacity = .4 - (Person::players[k]->coords.y - terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z)) / 5;
373                     terrain.MakeDecal(shadowdecal, point, size, opacity * .7, rotation);
374                     for (l = 0; l < terrain.patchobjectnum[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz]; l++) {
375                         int j = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
376                         point = DoRotation(Person::players[k]->coords - objects.position[j], 0, -objects.yaw[j], 0);
377                         size = .7;
378                         opacity = .4f;
379                         objects.model[j].MakeDecal(shadowdecal, &point, &size, &opacity, &rotation);
380                     }
381                 }
382         }
383
384         //Terrain
385         glEnable(GL_TEXTURE_2D);
386         glDepthMask(1);
387         glEnable(GL_DEPTH_TEST);
388         glEnable(GL_CULL_FACE);
389         glDisable(GL_BLEND);
390         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
391         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
392         terraintexture.bind();
393         terrain.draw(0);
394         terraintexture2.bind();
395         terrain.draw(1);
396
397         terrain.drawdecals();
398
399         //Model
400         glEnable(GL_CULL_FACE);
401         glEnable(GL_LIGHTING);
402         glDisable(GL_BLEND);
403         glEnable(GL_TEXTURE_2D);
404         glDepthMask(1);
405
406         glEnable(GL_COLOR_MATERIAL);
407
408         if (!cellophane) {
409             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
410             glEnable(GL_CULL_FACE);
411             glCullFace(GL_FRONT);
412             glDepthMask(1);
413             for (unsigned k = 0; k < Person::players.size(); k++) {
414                 if (k == 0 || tutoriallevel != 1) {
415                     glEnable(GL_BLEND);
416                     glEnable(GL_LIGHTING);
417                     terrainlight = terrain.getLighting(Person::players[k]->coords.x, Person::players[k]->coords.z);
418                     distance = distsq(&viewer, &Person::players[k]->coords);
419                     distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
420                     glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
421                     if (distance >= 1)
422                         glDisable(GL_BLEND);
423                     if (distance >= .5) {
424                         checkpoint = DoRotation(Person::players[k]->skeleton.joints[abs(Random() % Person::players[k]->skeleton.num_joints)].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords;
425                         checkpoint.y += 1;
426                         int i = -1;
427                         if (Person::players[k]->occluded != 0)
428                             i = checkcollide(viewer, checkpoint, Person::players[k]->lastoccluded);
429                         if (i == -1)
430                             i = checkcollide(viewer, checkpoint);
431                         if (i != -1) {
432                             Person::players[k]->occluded += 1;
433                             Person::players[k]->lastoccluded = i;
434                         } else {
435                             Person::players[k]->occluded = 0;
436                         }
437                         if (Person::players[k]->occluded < 25)
438                             Person::players[k]->DrawSkeleton();
439                     }
440                 }
441             }
442         }
443
444         if (!cameramode && musictype == stream_fighttheme)
445             playerdist = distsqflat(&Person::players[0]->coords, &viewer);
446         else
447             playerdist = -100;
448         glPushMatrix();
449         glCullFace(GL_BACK);
450         glEnable(GL_TEXTURE_2D);
451         objects.Draw();
452         glPopMatrix();
453
454         //draw hawk
455         glPushMatrix();
456         if (frustum.SphereInFrustum(realhawkcoords.x + hawk.boundingspherecenter.x, realhawkcoords.y + hawk.boundingspherecenter.y, realhawkcoords.z + hawk.boundingspherecenter.z, 2)) {
457             glAlphaFunc(GL_GREATER, 0.0001f);
458             glDepthMask(1);
459             glDisable(GL_CULL_FACE);
460             glDisable(GL_LIGHTING);
461             glEnable(GL_BLEND);
462             glTranslatef(hawkcoords.x, hawkcoords.y, hawkcoords.z);
463             glRotatef(hawkyaw, 0, 1, 0);
464             glTranslatef(25, 0, 0);
465             distance = distsq(&viewer, &realhawkcoords) * 1.2;
466             glColor4f(light.color[0], light.color[1], light.color[2], (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance);
467             if ((viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance > 1)
468                 glColor4f(light.color[0], light.color[1], light.color[2], 1);
469             if ((viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance > 0)
470                 hawk.drawdifftex(hawktexture);
471         }
472         glPopMatrix();
473
474         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
475         glEnable(GL_CULL_FACE);
476         glCullFace(GL_FRONT);
477         glDepthMask(1);
478         for (unsigned k = 0; k < Person::players.size(); k++) {
479             if (!(k == 0 || tutoriallevel != 1)) {
480                 glEnable(GL_BLEND);
481                 glEnable(GL_LIGHTING);
482                 terrainlight = terrain.getLighting(Person::players[k]->coords.x, Person::players[k]->coords.z);
483                 distance = distsq(&viewer, &Person::players[k]->coords);
484                 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
485                 glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
486                 if (distance >= 1)
487                     glDisable(GL_BLEND);
488                 if (distance >= .5) {
489                     checkpoint = DoRotation(Person::players[k]->skeleton.joints[abs(Random() % Person::players[k]->skeleton.num_joints)].position, 0, Person::players[k]->yaw, 0) * Person::players[k]->scale + Person::players[k]->coords;
490                     checkpoint.y += 1;
491                     int i = -1;
492                     if (Person::players[k]->occluded != 0)
493                         i = checkcollide(viewer, checkpoint, Person::players[k]->lastoccluded);
494                     if (i == -1)
495                         i = checkcollide(viewer, checkpoint);
496                     if (i != -1) {
497                         Person::players[k]->occluded += 1;
498                         Person::players[k]->lastoccluded = i;
499                     } else {
500                         Person::players[k]->occluded = 0;
501                     }
502                     if (Person::players[k]->occluded < 25)
503                         Person::players[k]->DrawSkeleton();
504                 }
505             }
506         }
507
508         glPushMatrix();
509         glEnable(GL_TEXTURE_2D);
510         weapons.Draw();
511         glPopMatrix();
512         glCullFace(GL_BACK);
513
514         glDisable(GL_COLOR_MATERIAL);
515
516         glDisable(GL_LIGHTING);
517         glDisable(GL_TEXTURE_2D);
518
519         glDepthMask(0);
520
521         Sprite::Draw();
522
523         //waypoints, pathpoints in editor
524         if (editorenabled) {
525             glEnable(GL_BLEND);
526             glDisable(GL_LIGHTING);
527             glDisable(GL_TEXTURE_2D);
528             glDisable(GL_COLOR_MATERIAL);
529             glColor4f(1, 1, 0, 1);
530
531             for (unsigned k = 0; k < Person::players.size(); k++) {
532                 if (Person::players[k]->numwaypoints > 1) {
533                     glBegin(GL_LINE_LOOP);
534                     for (int i = 0; i < Person::players[k]->numwaypoints; i++) {
535                         glVertex3f(Person::players[k]->waypoints[i].x, Person::players[k]->waypoints[i].y + .5, Person::players[k]->waypoints[i].z);
536                     }
537                     glEnd();
538                 }
539             }
540
541
542             if (numpathpoints > 1) {
543                 glColor4f(0, 1, 0, 1);
544                 for (unsigned k = 0; int(k) < numpathpoints; k++) {
545                     if (numpathpointconnect[k]) {
546                         for (int i = 0; i < numpathpointconnect[k]; i++) {
547                             glBegin(GL_LINE_LOOP);
548                             glVertex3f(pathpoint[k].x, pathpoint[k].y + .5, pathpoint[k].z);
549                             glVertex3f(pathpoint[pathpointconnect[k][i]].x, pathpoint[pathpointconnect[k][i]].y + .5, pathpoint[pathpointconnect[k][i]].z);
550                             glEnd();
551                         }
552                     }
553                 }
554                 glColor4f(1, 1, 1, 1);
555                 glPointSize(4);
556                 glBegin(GL_POINTS);
557                 glVertex3f(pathpoint[pathpointselected].x, pathpoint[pathpointselected].y + .5, pathpoint[pathpointselected].z);
558                 glEnd();
559             }
560         }
561
562         //Text
563
564         glEnable(GL_TEXTURE_2D);
565         glColor4f(.5, .5, .5, 1);
566         if (!console) {
567             if (!tutoriallevel)
568                 if (bonus > 0 && bonustime < 1 && !winfreeze && indialogue == -1/*bonustime<4*/) {
569                     const char *bonus_name;
570                     if (bonus < bonus_count)
571                         bonus_name = bonus_names[bonus];
572                     else
573                         bonus_name = "Excellent!"; // When does this happen?
574
575                     glColor4f(0, 0, 0, 1 - bonustime);
576                     text->glPrintOutline(1024 / 2 - 10 * strlen(bonus_name) - 4, 768 / 16 - 4 + 768 * 4 / 5, bonus_name, 1, 2.5, 1024, 768);
577                     glColor4f(1, 0, 0, 1 - bonustime);
578                     text->glPrint(1024 / 2 - 10 * strlen(bonus_name), 768 / 16 + 768 * 4 / 5, bonus_name, 1, 2, 1024, 768);
579
580                     sprintf (string, "%d", (int)bonusvalue);
581                     glColor4f(0, 0, 0, 1 - bonustime);
582                     text->glPrintOutline(1024 / 2 - 10 * strlen(string) - 4, 768 / 16 - 4 - 20 + 768 * 4 / 5, string, 1, 2.5 * .8, 1024, 768);
583                     glColor4f(1, 0, 0, 1 - bonustime);
584                     text->glPrint(1024 / 2 - 10 * strlen(string), 768 / 16 - 20 + 768 * 4 / 5, string, 1, 2 * .8, 1024, 768);
585                     glColor4f(.5, .5, .5, 1);
586                 }
587
588             if (tutoriallevel == 1) {
589                 tutorialopac = tutorialmaxtime - tutorialstagetime;
590                 if (tutorialopac > 1)
591                     tutorialopac = 1;
592                 if (tutorialopac < 0)
593                     tutorialopac = 0;
594
595                 sprintf (string, " ");
596                 sprintf (string2, " ");
597                 sprintf (string3, " ");
598                 if (tutorialstage == 0) {
599                     sprintf (string, " ");
600                     sprintf (string2, " ");
601                     sprintf (string3, " ");
602                 }
603                 if (tutorialstage == 1) {
604                     sprintf (string, "Welcome to the Lugaru training level!");
605                     sprintf (string2, " ");
606                     sprintf (string3, " ");
607                 }
608                 if (tutorialstage == 2) {
609                     sprintf (string, "BASIC MOVEMENT:");
610                     sprintf (string2, " ");
611                     sprintf (string3, " ");
612                 }
613                 if (tutorialstage == 3) {
614                     sprintf (string, "You can move the mouse to rotate the camera.");
615                     sprintf (string2, " ");
616                     sprintf (string3, " ");
617                 }
618                 if (tutorialstage == 4) {
619                     sprintf (string, "Try using the %s, %s, %s and %s keys to move around.", Input::keyToChar(forwardkey), Input::keyToChar(leftkey), Input::keyToChar(backkey), Input::keyToChar(rightkey));
620                     sprintf (string2, "All movement is relative to the camera.");
621                     sprintf (string3, " ");
622                 }
623                 if (tutorialstage == 5) {
624                     sprintf (string, "Please press %s to jump.", Input::keyToChar(jumpkey));
625                     sprintf (string2, "You can hold it longer to jump higher.");
626                     sprintf (string3, " ");
627                 }
628                 if (tutorialstage == 6) {
629                     sprintf (string, "You can press %s to crouch.", Input::keyToChar(crouchkey));
630                     sprintf (string2, "You can jump higher from a crouching position.");
631                     sprintf (string3, " ");
632                 }
633                 if (tutorialstage == 7) {
634                     sprintf (string, "While running, you can press %s to roll.", Input::keyToChar(crouchkey));
635                     sprintf (string2, " ");
636                     sprintf (string3, " ");
637                 }
638                 if (tutorialstage == 8) {
639                     sprintf (string, "While crouching, you can sneak around silently");
640                     sprintf (string2, "using the movement keys.");
641                     sprintf (string3, " ");
642                 }
643                 if (tutorialstage == 9) {
644                     sprintf (string, "Release the crouch key while sneaking and hold the movement keys");
645                     sprintf (string2, "to run animal-style.");
646                     sprintf (string3, " ");
647                 }
648                 if (tutorialstage == 10) {
649                     sprintf (string, "ADVANCED MOVEMENT:");
650                     sprintf (string2, " ");
651                     sprintf (string3, " ");
652                 }
653                 if (tutorialstage == 11) {
654                     sprintf (string, "When you jump at a wall, you can hold %s again", Input::keyToChar(jumpkey));
655                     sprintf (string2, "during impact to perform a walljump.");
656                     sprintf (string3, "Be sure to use the movement keys to press against the wall");
657                 }
658                 if (tutorialstage == 12) {
659                     sprintf (string, "While in the air, you can press crouch to flip.");
660                     sprintf (string2, "Walljumps and flips confuse enemies and give you more control.");
661                     sprintf (string3, " ");
662                 }
663                 if (tutorialstage == 13) {
664                     sprintf (string, "BASIC COMBAT:");
665                     sprintf (string2, " ");
666                     sprintf (string3, " ");
667                 }
668                 if (tutorialstage == 14) {
669                     sprintf (string, "There is now an imaginary enemy");
670                     sprintf (string2, "in the middle of the training area.");
671                     sprintf (string3, " ");
672                 }
673                 if (tutorialstage == 15) {
674                     if (attackkey == MOUSEBUTTON1)
675                         sprintf (string, "Click to attack when you are near an enemy.");
676                     else
677                         sprintf (string, "Press %s to attack when you are near an enemy.", Input::keyToChar(attackkey));
678                     sprintf (string2, "You can punch by standing still near an enemy and attacking.");
679                     sprintf (string3, " ");
680                 }
681                 if (tutorialstage == 16) {
682                     sprintf (string, "If you are close, you will perform a weak punch.");
683                     sprintf (string2, "The weak punch is excellent for starting attack combinations.");
684                     sprintf (string3, " ");
685                 }
686                 if (tutorialstage == 17) {
687                     sprintf (string, "Attacking while running results in a spin kick.");
688                     sprintf (string2, "This is one of your most powerful ground attacks.");
689                     sprintf (string3, " ");
690                 }
691                 if (tutorialstage == 18) {
692                     sprintf (string, "Sweep the enemy's legs out by attacking while crouched.");
693                     sprintf (string2, "This is a very fast attack, and easy to follow up.");
694                     sprintf (string3, " ");
695                 }
696                 if (tutorialstage == 19) {
697                     sprintf (string, "When an enemy is on the ground, you can deal some extra");
698                     sprintf (string2, "damage by running up and drop-kicking him.");
699                     sprintf (string3, "(Try knocking them down with a sweep first)");
700                 }
701                 if (tutorialstage == 20) {
702                     sprintf (string, "Your most powerful individual attack is the rabbit kick.");
703                     if (attackkey == MOUSEBUTTON1)
704                         sprintf (string2, "Run at the enemy while holding the mouse button, and press");
705                     else
706                         sprintf (string2, "Run at the enemy while holding %s, and press", Input::keyToChar(attackkey));
707                     sprintf (string3, "the jump key (%s) to attack.", Input::keyToChar(jumpkey));
708                 }
709                 if (tutorialstage == 21) {
710                     sprintf (string, "This attack is devastating if timed correctly.");
711                     sprintf (string2, "Even if timed incorrectly, it will knock the enemy over.");
712                     if (againbonus)
713                         sprintf (string3, "Try rabbit-kicking the imaginary enemy again.");
714                     else
715                         sprintf (string3, "Try rabbit-kicking the imaginary enemy.");
716                 }
717                 if (tutorialstage == 22) {
718                     sprintf (string, "If you sneak behind an enemy unnoticed, you can kill");
719                     sprintf (string2, "him instantly. Move close behind this enemy");
720                     sprintf (string3, "and attack.");
721                 }
722                 if (tutorialstage == 23) {
723                     sprintf (string, "Another important attack is the wall kick. When an enemy");
724                     sprintf (string2, "is near a wall, perform a walljump nearby and hold");
725                     sprintf (string3, "the attack key during impact with the wall.");
726                 }
727                 if (tutorialstage == 24) {
728                     sprintf (string, "You can tackle enemies by running at them animal-style");
729                     if (attackkey == MOUSEBUTTON1)
730                         sprintf (string2, "and pressing jump (%s) or attack(mouse button).", Input::keyToChar(jumpkey));
731                     else
732                         sprintf (string2, "and pressing jump (%s) or attack(%s).", Input::keyToChar(jumpkey), Input::keyToChar(attackkey));
733                     sprintf (string3, "This is especially useful when they are running away.");
734                 }
735                 if (tutorialstage == 25) {
736                     sprintf (string, "Dodge by pressing back and attack. Dodging is essential");
737                     sprintf (string2, "against enemies with swords or other long weapons.");
738                     sprintf (string3, " ");
739                 }
740                 if (tutorialstage == 26) {
741                     sprintf (string, "REVERSALS AND COUNTER-REVERSALS");
742                     sprintf (string2, " ");
743                     sprintf (string3, " ");
744                 }
745                 if (tutorialstage == 27) {
746                     sprintf (string, "The enemy can now reverse your attacks.");
747                     sprintf (string2, " ");
748                     sprintf (string3, " ");
749                 }
750                 if (tutorialstage == 28) {
751                     sprintf (string, "If you attack, you will notice that the enemy now sometimes");
752                     sprintf (string2, "catches your attack and uses it against you. Hold");
753                     sprintf (string3, "crouch (%s) after attacking to escape from reversals.", Input::keyToChar(crouchkey));
754                 }
755                 if (tutorialstage == 29) {
756                     sprintf (string, "Try escaping from two more reversals in a row.");
757                     sprintf (string2, " ");
758                     sprintf (string3, " ");
759                 }
760                 if (tutorialstage == 30) {
761                     sprintf (string, "Good!");
762                     sprintf (string2, " ");
763                     sprintf (string3, " ");
764                 }
765                 if (tutorialstage == 31) {
766                     sprintf (string, "To reverse an attack, you must tap crouch (%s) during the", Input::keyToChar(crouchkey));
767                     sprintf (string2, "enemy's attack. You must also be close to the enemy;");
768                     sprintf (string3, "this is especially important against armed opponents.");
769                 }
770                 if (tutorialstage == 32) {
771                     sprintf (string, "The enemy can attack in %d seconds.", (int)(tutorialmaxtime - tutorialstagetime));
772                     sprintf (string2, "This imaginary opponents attacks will be highlighted");
773                     sprintf (string3, "to make this easier.");
774                 }
775                 if (tutorialstage == 33) {
776                     sprintf (string, "Reverse three enemy attacks!");
777                     sprintf (string2, " ");
778                     sprintf (string3, " ");
779                 }
780                 if (tutorialstage == 34) {
781                     sprintf (string, "Reverse two more enemy attacks!");
782                     sprintf (string2, " ");
783                     sprintf (string3, " ");
784                 }
785                 if (tutorialstage == 35) {
786                     sprintf (string, "Reverse one more enemy attack!");
787                     sprintf (string2, " ");
788                     sprintf (string3, " ");
789                 }
790                 if (tutorialstage == 36) {
791                     sprintf (string, "Excellent!");
792                     sprintf (string2, " ");
793                     sprintf (string3, " ");
794                 }
795                 if (tutorialstage == 37) {
796                     sprintf (string, "Now spar with the enemy for %d more seconds.", (int)(tutorialmaxtime - tutorialstagetime));
797                     sprintf (string2, "Damage dealt: %d", (int)damagedealt);
798                     sprintf (string3, "Damage taken: %d.", (int)damagetaken);
799                 }
800                 if (tutorialstage == 38) {
801                     sprintf (string, "WEAPONS:");
802                     sprintf (string2, " ");
803                     sprintf (string3, " ");
804                 }
805                 if (tutorialstage == 39) {
806                     sprintf (string, "There is now an imaginary knife");
807                     sprintf (string2, "in the center of the training area.");
808                     sprintf (string3, " ");
809                 }
810                 if (tutorialstage == 40) {
811                     sprintf (string, "Stand, roll or handspring over the knife");
812                     sprintf (string2, "while pressing %s to pick it up.", Input::keyToChar(throwkey));
813                     sprintf (string3, "You can crouch and press the same key to drop it again.");
814                 }
815                 if (tutorialstage == 41) {
816                     sprintf (string, "You can equip and unequip weapons using the %s key.", Input::keyToChar(drawkey));
817                     sprintf (string2, "Sometimes it is best to keep them unequipped to");
818                     sprintf (string3, "prevent enemies from taking them. ");
819                 }
820                 if (tutorialstage == 42) {
821                     sprintf (string, "The knife is the smallest weapon and the least encumbering.");
822                     sprintf (string2, "You can equip or unequip it while standing, crouching,");
823                     sprintf (string3, "running or flipping.");
824                 }
825                 if (tutorialstage == 43) {
826                     sprintf (string, "You perform weapon attacks the same way as unarmed attacks,");
827                     sprintf (string2, "but sharp weapons cause permanent damage, instead of the");
828                     sprintf (string3, "temporary trauma from blunt weapons, fists and feet.");
829                 }
830                 if (tutorialstage == 44) {
831                     sprintf (string, "The enemy now has your knife!");
832                     sprintf (string2, "Please reverse two of his knife attacks.");
833                     sprintf (string3, " ");
834                 }
835                 if (tutorialstage == 45) {
836                     sprintf (string, "Please reverse one more of his knife attacks.");
837                     sprintf (string2, " ");
838                     sprintf (string3, " ");
839                 }
840                 if (tutorialstage == 46) {
841                     sprintf (string, "Now he has a sword!");
842                     sprintf (string2, "The sword has longer reach than your arms, so you");
843                     sprintf (string3, "must move close to reverse the sword slash.");
844                 }
845                 if (tutorialstage == 47) {
846                     sprintf (string, "Long weapons like the sword and staff are also useful for defense;");
847                     sprintf (string2, "you can parry enemy weapon attacks by pressing the attack key");
848                     sprintf (string3, "at the right time. Please try parrying the enemy's attacks!");
849                 }
850                 if (tutorialstage == 48) {
851                     sprintf (string, "The staff is like the sword, but has two main attacks.");
852                     sprintf (string2, "The standing smash is fast and effective, and the running");
853                     sprintf (string3, "spin smash is slower and more powerful.");
854                 }
855                 if (tutorialstage == 49) {
856                     sprintf (string, "When facing an enemy, you can throw the knife with %s.", Input::keyToChar(throwkey));
857                     sprintf (string2, "It is possible to throw the knife while flipping,");
858                     sprintf (string3, "but it is very inaccurate.");
859                 }
860                 if (tutorialstage == 50) {
861                     sprintf (string, "You now know everything you can learn from training.");
862                     sprintf (string2, "Everything else you must learn from experience!");
863                     sprintf (string3, " ");
864                 }
865                 if (tutorialstage == 51) {
866                     sprintf (string, "Walk out of the training area to return to the main menu.");
867                     sprintf (string2, " ");
868                     sprintf (string3, " ");
869                 }
870
871                 glColor4f(0, 0, 0, tutorialopac);
872                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string)*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
873                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5 - 20 * screenwidth / 1024, string2, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
874                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5 - 40 * screenwidth / 1024, string3, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
875                 glColor4f(1, 1, 1, tutorialopac);
876                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
877                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
878                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 40 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
879
880                 sprintf (string, "Press 'tab' to skip to the next item.");
881                 sprintf (string2, "Press escape at any time to");
882                 sprintf (string3, "pause or exit the tutorial.");
883
884                 glColor4f(0, 0, 0, 1);
885                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string)*screenwidth / 1024 * .8 - 4, 0 - 4 + screenheight * 1 / 10, string, 1, 1.5 * 1.25 * screenwidth / 1024 * .8, screenwidth, screenheight);
886                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024 * .8 - 4, 0 - 4 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * 1.25 * screenwidth / 1024 * .8, screenwidth, screenheight);
887                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024 * .8 - 4, 0 - 4 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * 1.25 * screenwidth / 1024 * .8, screenwidth, screenheight);
888                 glColor4f(0.5, 0.5, 0.5, 1);
889                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string)*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10, string, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
890                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
891                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
892             }
893             //Hot spots
894
895             if (numhotspots && (bonustime >= 1 || bonus <= 0 || bonustime < 0) && !tutoriallevel) {
896                 float closestdist = -1;
897                 float distance = 0;
898                 int closest = currenthotspot;
899                 for (int i = 0; i < numhotspots; i++) {
900                     distance = distsq(&Person::players[0]->coords, &hotspot[i]);
901                     if (closestdist == -1 || distance < closestdist) {
902                         if (distsq(&Person::players[0]->coords, &hotspot[i]) < hotspotsize[i] && ((hotspottype[i] <= 10 && hotspottype[i] >= 0) || (hotspottype[i] <= 40 && hotspottype[i] >= 20))) {
903                             closestdist = distance;
904                             closest = i;
905                         }
906                     }
907                 }
908                 if (closest != -1)
909                     currenthotspot = closest;
910                 if (currenthotspot != -1) {
911                     if (hotspottype[closest] <= 10) {
912                         if (distsq(&Person::players[0]->coords, &hotspot[closest]) < hotspotsize[closest])
913                             tutorialstagetime = 0;
914                         tutorialmaxtime = 1;
915                         tutorialopac = tutorialmaxtime - tutorialstagetime;
916                         if (tutorialopac > 1)
917                             tutorialopac = 1;
918                         if (tutorialopac < 0)
919                             tutorialopac = 0;
920
921                         sprintf (string, "%s", hotspottext[closest]);
922
923                         int lastline = 0;
924                         int line = 0;
925                         bool done = false;
926                         int i = 0;
927                         while (!done) {
928                             if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') {
929                                 glColor4f(0, 0, 0, tutorialopac);
930                                 text->glPrintOutline(screenwidth / 2 - 7.6 * (i - lastline)*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5 - 20 * screenwidth / 1024 * line, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
931                                 glColor4f(1, 1, 1, tutorialopac);
932                                 text->glPrint(screenwidth / 2 - 7.6 * (i - lastline)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
933                                 lastline = i + 1;
934                                 line++;
935                                 if (string[i] == '\0')
936                                     done = 1;
937                             }
938                             if (i >= 255)
939                                 done = 1;
940                             i++;
941                         }
942                     } else if (hotspottype[closest] >= 20 && dialoguegonethrough[hotspottype[closest] - 20] == 0) {
943                         whichdialogue = hotspottype[closest] - 20;
944                         for (int j = 0; j < numdialogueboxes[whichdialogue]; j++) {
945                             Person::players[participantfocus[whichdialogue][j]]->coords = participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
946                             Person::players[participantfocus[whichdialogue][j]]->yaw = participantyaw[whichdialogue][participantfocus[whichdialogue][j]];
947                             Person::players[participantfocus[whichdialogue][j]]->targetyaw = participantyaw[whichdialogue][participantfocus[whichdialogue][j]];
948                             Person::players[participantfocus[whichdialogue][j]]->velocity = 0;
949                             Person::players[participantfocus[whichdialogue][j]]->animTarget = Person::players[participantfocus[whichdialogue][j]]->getIdle();
950                             Person::players[participantfocus[whichdialogue][j]]->frameTarget = 0;
951                         }
952                         directing = 0;
953                         indialogue = 0;
954                         dialoguegonethrough[whichdialogue]++;
955                         if (dialogueboxsound[whichdialogue][indialogue] != 0) {
956                             int whichsoundplay;
957                             if (dialogueboxsound[whichdialogue][indialogue] == 1) whichsoundplay = rabbitchitter;
958                             if (dialogueboxsound[whichdialogue][indialogue] == 2) whichsoundplay = rabbitchitter2;
959                             if (dialogueboxsound[whichdialogue][indialogue] == 3) whichsoundplay = rabbitpainsound;
960                             if (dialogueboxsound[whichdialogue][indialogue] == 4) whichsoundplay = rabbitpain1sound;
961                             if (dialogueboxsound[whichdialogue][indialogue] == 5) whichsoundplay = rabbitattacksound;
962                             if (dialogueboxsound[whichdialogue][indialogue] == 6) whichsoundplay = rabbitattack2sound;
963                             if (dialogueboxsound[whichdialogue][indialogue] == 7) whichsoundplay = rabbitattack3sound;
964                             if (dialogueboxsound[whichdialogue][indialogue] == 8) whichsoundplay = rabbitattack4sound;
965                             if (dialogueboxsound[whichdialogue][indialogue] == 9) whichsoundplay = growlsound;
966                             if (dialogueboxsound[whichdialogue][indialogue] == 10) whichsoundplay = growl2sound;
967                             if (dialogueboxsound[whichdialogue][indialogue] == 11) whichsoundplay = snarlsound;
968                             if (dialogueboxsound[whichdialogue][indialogue] == 12) whichsoundplay = snarl2sound;
969                             if (dialogueboxsound[whichdialogue][indialogue] == 13) whichsoundplay = barksound;
970                             if (dialogueboxsound[whichdialogue][indialogue] == 14) whichsoundplay = bark2sound;
971                             if (dialogueboxsound[whichdialogue][indialogue] == 15) whichsoundplay = bark3sound;
972                             if (dialogueboxsound[whichdialogue][indialogue] == 16) whichsoundplay = barkgrowlsound;
973                             if (dialogueboxsound[whichdialogue][indialogue] == -1) whichsoundplay = fireendsound;
974                             if (dialogueboxsound[whichdialogue][indialogue] == -2) whichsoundplay = firestartsound;
975                             if (dialogueboxsound[whichdialogue][indialogue] == -3) whichsoundplay = consolesuccesssound;
976                             if (dialogueboxsound[whichdialogue][indialogue] == -4) whichsoundplay = consolefailsound;
977                             emit_sound_at(whichsoundplay, Person::players[participantfocus[whichdialogue][indialogue]]->coords);
978                         }
979                     }
980                 }
981             }
982
983             if (indialogue != -1 && !mainmenu) {
984                 glDisable(GL_DEPTH_TEST);
985                 glDisable(GL_CULL_FACE);
986                 glDisable(GL_LIGHTING);
987                 glDisable(GL_TEXTURE_2D);
988                 glDepthMask(0);
989                 glMatrixMode(GL_PROJECTION);
990                 glPushMatrix();
991                 glLoadIdentity();
992                 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
993                 glMatrixMode(GL_MODELVIEW);
994                 glPushMatrix();
995                 glLoadIdentity();
996                 if (dialogueboxlocation[whichdialogue][indialogue] == 1)
997                     glTranslatef(0, screenheight * 3 / 4, 0);
998                 glScalef(screenwidth, screenheight / 4, 1);
999                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1000                 glEnable(GL_BLEND);
1001
1002                 glColor4f(dialogueboxcolor[whichdialogue][indialogue][0], dialogueboxcolor[whichdialogue][indialogue][1], dialogueboxcolor[whichdialogue][indialogue][2], 0.7);
1003                 glBegin(GL_QUADS);
1004                 glVertex3f(0, 0, 0.0f);
1005                 glVertex3f(1, 0, 0.0f);
1006                 glVertex3f(1, 1, 0.0f);
1007                 glVertex3f(0, 1, 0.0f);
1008                 glEnd();
1009                 glMatrixMode(GL_PROJECTION);
1010                 glPopMatrix();
1011                 glMatrixMode(GL_MODELVIEW);
1012                 glPopMatrix();
1013                 glEnable(GL_DEPTH_TEST);
1014                 glEnable(GL_CULL_FACE);
1015                 glDisable(GL_BLEND);
1016                 glDepthMask(1);
1017                 glEnable(GL_TEXTURE_2D);
1018
1019                 tutorialopac = 1;
1020
1021                 float startx;
1022                 float starty;
1023
1024                 startx = screenwidth * 1 / 5;
1025                 if (dialogueboxlocation[whichdialogue][indialogue] == 1)
1026                     starty = screenheight / 16 + screenheight * 4 / 5;
1027                 if (dialogueboxlocation[whichdialogue][indialogue] == 2)
1028                     starty = screenheight * 1 / 5 - screenheight / 16;
1029
1030                 char tempname[264];
1031                 bool goodchar;
1032                 int tempnum = 0;
1033                 for (int i = 0; i < 264; i++) {
1034                     tempname[i] = '\0';
1035                 }
1036
1037                 for (int i = 0; i < (int)strlen(dialoguename[whichdialogue][indialogue]); i++) {
1038                     tempname[tempnum] = dialoguename[whichdialogue][indialogue][i];
1039                     goodchar = 1;
1040                     if (dialoguename[whichdialogue][indialogue][i] == '#' || dialoguename[whichdialogue][indialogue][i] == '\0')
1041                         goodchar = 0;
1042                     if (goodchar)
1043                         tempnum++;
1044                     else
1045                         tempname[tempnum] = '\0';
1046                 }
1047
1048                 sprintf (string, "%s: ", tempname);
1049
1050                 if (dialogueboxcolor[whichdialogue][indialogue][0] + dialogueboxcolor[whichdialogue][indialogue][1] + dialogueboxcolor[whichdialogue][indialogue][2] < 1.5) {
1051                     glColor4f(0, 0, 0, tutorialopac);
1052                     text->glPrintOutline(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
1053                     glColor4f(0.7, 0.7, 0.7, tutorialopac);
1054                     text->glPrint(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024, starty, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
1055                 } else {
1056                     glColor4f(0, 0, 0, tutorialopac);
1057                     text->glPrintOutline(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
1058                 }
1059
1060                 tempnum = 0;
1061                 for (int i = 0; i < (int)strlen(dialoguetext[whichdialogue][indialogue]) + 1; i++) {
1062                     tempname[tempnum] = dialoguetext[whichdialogue][indialogue][i];
1063                     if (dialoguetext[whichdialogue][indialogue][i] != '#')
1064                         tempnum++;
1065                 }
1066
1067                 sprintf (string, "%s", tempname);
1068
1069                 int lastline = 0;
1070                 int line = 0;
1071                 bool done = false;
1072                 int i = 0;
1073                 while (!done) {
1074                     if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') {
1075                         if (dialogueboxcolor[whichdialogue][indialogue][0] + dialogueboxcolor[whichdialogue][indialogue][1] + dialogueboxcolor[whichdialogue][indialogue][2] < 1.5) {
1076                             glColor4f(0, 0, 0, tutorialopac);
1077                             text->glPrintOutline(startx/*-7.6*(i-lastline)*screenwidth/1024*/ - 4, starty - 4 - 20 * screenwidth / 1024 * line, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
1078                             glColor4f(1, 1, 1, tutorialopac);
1079                             text->glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
1080                         } else {
1081                             glColor4f(0, 0, 0, tutorialopac);
1082                             text->glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
1083                         }
1084                         lastline = i + 1;
1085                         line++;
1086                         if (string[i] == '\0')
1087                             done = 1;
1088                     }
1089                     if (i >= 255)
1090                         done = 1;
1091                     i++;
1092                 }
1093             }
1094
1095             if (!tutoriallevel && !winfreeze && indialogue == -1 && !mainmenu) {
1096                 if (campaign) {
1097                     if (scoreadded)
1098                         sprintf (string, "Score: %d", (int)accountactive->getCampaignScore());
1099                     else
1100                         sprintf (string, "Score: %d", (int)accountactive->getCampaignScore() + (int)bonustotal);
1101                 }
1102                 if (!campaign)
1103                     sprintf (string, "Score: %d", (int)bonustotal);
1104                 glColor4f(0, 0, 0, 1);
1105                 text->glPrintOutline(1024 / 40 - 4, 768 / 16 - 4 + 768 * 14 / 16, string, 1, 1.5 * 1.25, 1024, 768);
1106                 glColor4f(1, 0, 0, 1);
1107                 text->glPrint(1024 / 40, 768 / 16 + 768 * 14 / 16, string, 1, 1.5, 1024, 768);
1108                 if (showdamagebar) {
1109                     glDisable(GL_DEPTH_TEST);
1110                     glDisable(GL_CULL_FACE);
1111                     glDisable(GL_LIGHTING);
1112                     glDisable(GL_TEXTURE_2D);
1113                     glDepthMask(0);
1114                     glMatrixMode(GL_PROJECTION);
1115                     glPushMatrix();
1116                     glLoadIdentity();
1117                     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1118                     glMatrixMode(GL_MODELVIEW);
1119                     glPushMatrix();
1120                     glLoadIdentity();
1121                     glTranslatef(15, screenheight * 17.5 / 20, 0);
1122                     glScalef(screenwidth / 3 + 20, screenheight / 20, 1);
1123                     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1124                     glEnable(GL_BLEND);
1125                     glColor4f(0.0, 0.4, 0.0, 0.7);
1126                     float bar = ((float)Person::players[0]->damage) / Person::players[0]->damagetolerance;
1127                     glBegin(GL_QUADS);
1128                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1129                     glVertex3f(1, 0, 0.0f);
1130                     glVertex3f(1, 1, 0.0f);
1131                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1132                     glEnd();
1133                     glColor4f(0.1, 0.0, 0.0, 1);
1134                     bar = ((float)Person::players[0]->bloodloss) / Person::players[0]->damagetolerance;
1135                     glBegin(GL_QUADS);
1136                     glVertex3f(0, 0, 0.0f);
1137                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1138                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1139                     glVertex3f(0, 1, 0.0f);
1140                     glEnd();
1141                     glColor4f(0.4, 0.0, 0.0, 0.7);
1142                     bar = ((float)Person::players[0]->damage) / Person::players[0]->damagetolerance;
1143                     glBegin(GL_QUADS);
1144                     glVertex3f(0, 0, 0.0f);
1145                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1146                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1147                     glVertex3f(0, 1, 0.0f);
1148                     glEnd();
1149                     glColor4f(0.4, 0.0, 0.0, 0.7);
1150                     bar = ((float)Person::players[0]->permanentdamage) / Person::players[0]->damagetolerance;
1151                     glBegin(GL_QUADS);
1152                     glVertex3f(0, 0, 0.0f);
1153                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1154                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1155                     glVertex3f(0, 1, 0.0f);
1156                     glEnd();
1157                     glColor4f(0.4, 0.0, 0.0, 0.7);
1158                     bar = ((float)Person::players[0]->superpermanentdamage) / Person::players[0]->damagetolerance;
1159                     glBegin(GL_QUADS);
1160                     glVertex3f(0, 0, 0.0f);
1161                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1162                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1163                     glVertex3f(0, 1, 0.0f);
1164                     glEnd();
1165                     glColor4f(0.0, 0.0, 0.0, 0.7);
1166                     glLineWidth(2.0);
1167                     glBegin(GL_LINE_STRIP);
1168                     glVertex3f(0, 0, 0.0f);
1169                     glVertex3f(1, 0, 0.0f);
1170                     glVertex3f(1, 1, 0.0f);
1171                     glVertex3f(0, 1, 0.0f);
1172                     glVertex3f(0, 0, 0.0f);
1173                     glEnd();
1174
1175                     glMatrixMode(GL_PROJECTION);
1176                     glPopMatrix();
1177                     glMatrixMode(GL_MODELVIEW);
1178                     glPopMatrix();
1179                     glEnable(GL_DEPTH_TEST);
1180                     glEnable(GL_CULL_FACE);
1181                     glDisable(GL_BLEND);
1182                     glDepthMask(1);
1183                     glEnable(GL_TEXTURE_2D);
1184
1185                     // writing the numbers :
1186                     sprintf (string, "Damages : %d/%d (%d)", (int)(Person::players[0]->damage), (int)(Person::players[0]->damagetolerance), (int)(Person::players[0]->bloodloss));
1187                     glColor4f(0, 0, 0, 1);
1188                     text->glPrintOutline(1024 / 40 - 4, 768 / 16 - 4 + 768 * 14 / 16 - 40, string, 1, 1.5 * 1.25, 1024, 768);
1189                     glColor4f(1, 0, 0, 1);
1190                     text->glPrint(1024 / 40, 768 / 16 + 768 * 14 / 16 - 40, string, 1, 1.5, 1024, 768);
1191                 }
1192             }
1193
1194             glColor4f(.5, .5, .5, 1);
1195
1196
1197             if ((texttoggle || editorenabled) && debugmode && !mainmenu) {
1198                 sprintf (string, "The framespersecond is %d.", (int)(fps));
1199                 text->glPrint(10, 30, string, 0, .8, 1024, 768);
1200
1201                 if (editorenabled)
1202                     sprintf (string, "Map editor enabled.");
1203                 else
1204                     sprintf (string, "Map editor disabled.");
1205                 text->glPrint(10, 60, string, 0, .8, 1024, 768);
1206                 if (editorenabled) {
1207                     sprintf (string, "Object size: %f", editorsize);
1208                     text->glPrint(10, 75, string, 0, .8, 1024, 768);
1209                     if (editoryaw >= 0)
1210                         sprintf (string, "Object yaw: %f", editoryaw);
1211                     else
1212                         sprintf (string, "Object yaw: Random");
1213                     text->glPrint(10, 90, string, 0, .8, 1024, 768);
1214                     if (editorpitch >= 0)
1215                         sprintf (string, "Object pitch: %f", editorpitch);
1216                     else
1217                         sprintf (string, "Object pitch: Random");
1218                     text->glPrint(10, 105, string, 0, .8, 1024, 768);
1219                     sprintf (string, "Object type: %d", editortype);
1220                     text->glPrint(10, 120, string, 0, .8, 1024, 768);
1221                     switch (editortype) {
1222                     case boxtype:
1223                         sprintf (string, "(box)");
1224                         break;
1225                     case treetrunktype:
1226                         sprintf (string, "(tree)");
1227                         break;
1228                     case walltype:
1229                         sprintf (string, "(wall)");
1230                         break;
1231                     case weirdtype:
1232                         sprintf (string, "(weird)");
1233                         break;
1234                     case spiketype:
1235                         sprintf (string, "(spike)");
1236                         break;
1237                     case rocktype:
1238                         sprintf (string, "(rock)");
1239                         break;
1240                     case bushtype:
1241                         sprintf (string, "(bush)");
1242                         break;
1243                     case tunneltype:
1244                         sprintf (string, "(tunnel)");
1245                         break;
1246                     case chimneytype:
1247                         sprintf (string, "(chimney)");
1248                         break;
1249                     case platformtype:
1250                         sprintf (string, "(platform)");
1251                         break;
1252                     case cooltype:
1253                         sprintf (string, "(cool)");
1254                         break;
1255                     case firetype:
1256                         sprintf (string, "(fire)");
1257                         break;
1258                     }
1259                     text->glPrint(130, 120, string, 0, .8, 1024, 768);
1260
1261                     sprintf (string, "Numplayers: %lu", Person::players.size());
1262                     text->glPrint(10, 155, string, 0, .8, 1024, 768);
1263                     sprintf (string, "Player %d: numwaypoints: %d", (int(Person::players.size()) - 1), Person::players.back()->numwaypoints);
1264                     text->glPrint(10, 140, string, 0, .8, 1024, 768);
1265                 }
1266                 sprintf (string, "Difficulty: %d", difficulty);
1267                 text->glPrint(10, 240, string, 0, .8, 1024, 768);
1268
1269             }
1270         }
1271
1272         if (drawmode == glowmode) {
1273             glDisable(GL_DEPTH_TEST);
1274             glDisable(GL_CULL_FACE);
1275             glDisable(GL_LIGHTING);
1276             glDisable(GL_TEXTURE_2D);
1277             glDepthMask(0);
1278             glMatrixMode(GL_PROJECTION);
1279             glPushMatrix();
1280             glLoadIdentity();
1281             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1282             glMatrixMode(GL_MODELVIEW);
1283             glPushMatrix();
1284             glLoadIdentity();
1285             glScalef(screenwidth, screenheight, 1);
1286             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1287             glEnable(GL_BLEND);
1288             glColor4f(0, 0, 0, .5);
1289             glBegin(GL_QUADS);
1290             glVertex3f(0, 0,  0.0f);
1291             glVertex3f(256, 0, 0.0f);
1292             glVertex3f(256, 256, 0.0f);
1293             glVertex3f(0, 256, 0.0f);
1294             glEnd();
1295             glMatrixMode(GL_PROJECTION);
1296             glPopMatrix();
1297             glMatrixMode(GL_MODELVIEW);
1298             glPopMatrix();
1299             glEnable(GL_DEPTH_TEST);
1300             glEnable(GL_CULL_FACE);
1301             glDisable(GL_BLEND);
1302             glDepthMask(1);
1303         }
1304
1305         if ((((blackout && damageeffects) || (Person::players[0]->bloodloss > 0 && damageeffects && Person::players[0]->blooddimamount > 0) || Person::players[0]->dead) && !cameramode) || console) {
1306             glDisable(GL_DEPTH_TEST);
1307             glDisable(GL_CULL_FACE);
1308             glDisable(GL_LIGHTING);
1309             glDisable(GL_TEXTURE_2D);
1310             glDepthMask(0);
1311             glMatrixMode(GL_PROJECTION);
1312             glPushMatrix();
1313             glLoadIdentity();
1314             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1315             glMatrixMode(GL_MODELVIEW);
1316             glPushMatrix();
1317             glLoadIdentity();
1318             glScalef(screenwidth, screenheight, 1);
1319             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1320             glEnable(GL_BLEND);
1321             if (Person::players[0]->dead)
1322                 blackout += multiplier * 3;
1323             if (Person::players[0]->dead == 1)
1324                 blackout = .4f;
1325             if (Person::players[0]->dead == 2 && blackout > .6)
1326                 blackout = .6;
1327             glColor4f(0, 0, 0, blackout);
1328             if (!Person::players[0]->dead) {
1329                 if ((Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5))*.3 < .3) {
1330                     glColor4f(0, 0, 0, Person::players[0]->blooddimamount * Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5)*.3);
1331                     blackout = Person::players[0]->blooddimamount * Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5) * .3;
1332                 } else {
1333                     glColor4f(0, 0, 0, Person::players[0]->blooddimamount * .3);
1334                     blackout = Person::players[0]->blooddimamount * .3;
1335                 }
1336             }
1337             if (console)
1338                 glColor4f(.7, 0, 0, .2);
1339             glBegin(GL_QUADS);
1340             glVertex3f(0, 0,  0.0f);
1341             glVertex3f(256, 0,  0.0f);
1342             glVertex3f(256, 256, 0.0f);
1343             glVertex3f(0, 256, 0.0f);
1344             glEnd();
1345             glMatrixMode(GL_PROJECTION);
1346             glPopMatrix();
1347             glMatrixMode(GL_MODELVIEW);
1348             glPopMatrix();
1349             glEnable(GL_DEPTH_TEST);
1350             glEnable(GL_CULL_FACE);
1351             glDisable(GL_BLEND);
1352             glDepthMask(1);
1353         }
1354
1355         if (flashamount > 0 && damageeffects) {
1356             if (flashamount > 1)
1357                 flashamount = 1;
1358             if (flashdelay <= 0)
1359                 flashamount -= multiplier;
1360             flashdelay--;
1361             if (flashamount < 0)
1362                 flashamount = 0;
1363             glDisable(GL_DEPTH_TEST);
1364             glDisable(GL_CULL_FACE);
1365             glDisable(GL_LIGHTING);
1366             glDepthMask(0);
1367             glMatrixMode(GL_PROJECTION);
1368             glPushMatrix();
1369             glLoadIdentity();
1370             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1371             glMatrixMode(GL_MODELVIEW);
1372             glPushMatrix();
1373             glLoadIdentity();
1374             glScalef(screenwidth, screenheight, 1);
1375             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1376             glEnable(GL_BLEND);
1377             glColor4f(flashr, flashg, flashb, flashamount);
1378             glBegin(GL_QUADS);
1379             glVertex3f(0, 0,  0.0f);
1380             glVertex3f(256, 0, 0.0f);
1381             glVertex3f(256, 256, 0.0f);
1382             glVertex3f(0, 256, 0.0f);
1383             glEnd();
1384             glMatrixMode(GL_PROJECTION);
1385             glPopMatrix();
1386             glMatrixMode(GL_MODELVIEW);
1387             glPopMatrix();
1388             glEnable(GL_DEPTH_TEST);
1389             glEnable(GL_CULL_FACE);
1390             glDisable(GL_BLEND);
1391             glDepthMask(1);
1392         }
1393
1394         if (!console) {
1395             displaytime[0] = 0;
1396             glEnable(GL_TEXTURE_2D);
1397             glColor4f(1, 1, 1, 1);
1398             for (unsigned i = 1; i < 15; i++)
1399                 if (displaytime[i] < 4)
1400                     for (unsigned j = 0; j < displaytext[i].size(); j++) {
1401                         glColor4f(1, 1, 1, 4 - displaytime[i]);
1402                         sprintf (string, "%c", displaytext[i][j]);
1403                         text->glPrint(30 + j * 10, 30 + i * 20 + (screenheight - 330), string, 0, 1, screenwidth, screenheight);
1404                     }
1405         }
1406
1407         if (difficulty < 2 && indialogue == -1) { // minimap
1408             float mapviewdist = 20000;
1409
1410             glDisable(GL_DEPTH_TEST);
1411             glColor3f (1.0, 1.0, 1.0); // no coloring
1412
1413             glEnable(GL_TEXTURE_2D);
1414             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1415             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1416             glDisable(GL_DEPTH_TEST);
1417             glDisable(GL_CULL_FACE);
1418             glDisable(GL_LIGHTING);
1419             glDepthMask(0);
1420             glMatrixMode(GL_PROJECTION);
1421             glPushMatrix();
1422             glLoadIdentity();
1423             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1424             glMatrixMode(GL_MODELVIEW);
1425             glPushMatrix();
1426             glLoadIdentity();
1427             glScalef((float)screenwidth / 2, (float)screenwidth / 2, 1);
1428             glTranslatef(1.75, .25, 0);
1429             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1430             glEnable(GL_BLEND);
1431             glColor4f(1, 1, 1, 1);
1432             glPushMatrix();
1433             float opac = .7;
1434             XYZ center;
1435             float radius;
1436             float distcheck;
1437             int numliveplayers = 0;
1438             center = 0;
1439             for (unsigned i = 0; i < Person::players.size(); i++) {
1440                 if (!Person::players[i]->dead)
1441                     numliveplayers++;
1442             }
1443
1444             int numadd = 0;
1445
1446             for (int i = 0; i < objects.numobjects; i++) {
1447                 if (objects.type[i] == treetrunktype || objects.type[i] == boxtype) {
1448                     center += objects.position[i];
1449                     numadd++;
1450                 }
1451             }
1452             for (unsigned i = 0; i < Person::players.size(); i++) {
1453                 if (!Person::players[i]->dead)
1454                     center += Person::players[i]->coords;
1455             }
1456             center /= numadd + numliveplayers;
1457
1458             center = Person::players[0]->coords;
1459
1460             float maxdistance = 0;
1461             float tempdist;
1462             for (int i = 0; i < objects.numobjects; i++) {
1463                 tempdist = distsq(&center, &objects.position[i]);
1464                 if (tempdist > maxdistance) {
1465                     maxdistance = tempdist;
1466                 }
1467             }
1468             for (unsigned i = 0; i < Person::players.size(); i++) {
1469                 if (!Person::players[i]->dead) {
1470                     tempdist = distsq(&center, &Person::players[i]->coords);
1471                     if (tempdist > maxdistance) {
1472                         maxdistance = tempdist;
1473                     }
1474                 }
1475             }
1476             radius = 110;
1477
1478             glScalef(.25 / radius * 256 * terrain.scale * .4, .25 / radius * 256 * terrain.scale * .4, 1);
1479             glPushMatrix();
1480             glScalef(1 / (1 / radius * 256 * terrain.scale * .4), 1 / (1 / radius * 256 * terrain.scale * .4), 1);
1481             glPopMatrix();
1482             glRotatef(Person::players[0]->lookyaw * -1 + 180, 0, 0, 1);
1483             glTranslatef(-(center.x / terrain.scale / 256 * -2 + 1), (center.z / terrain.scale / 256 * -2 + 1), 0);
1484             for (int i = 0; i < objects.numobjects; i++) {
1485                 if (objects.type[i] == treetrunktype) {
1486                     distcheck = distsq(&Person::players[0]->coords, &objects.position[i]);
1487                     if (distcheck < mapviewdist) {
1488                         Mapcircletexture.bind();
1489                         glColor4f(0, .3, 0, opac * (1 - distcheck / mapviewdist));
1490                         glPushMatrix();
1491                         glTranslatef(objects.position[i].x / terrain.scale / 256 * -2 + 1, objects.position[i].z / terrain.scale / 256 * 2 - 1, 0);
1492                         glRotatef(objects.yaw[i], 0, 0, 1);
1493                         glScalef(.003, .003, .003);
1494                         glBegin(GL_QUADS);
1495                         glTexCoord2f(0, 0);
1496                         glVertex3f(-1, -1, 0.0f);
1497                         glTexCoord2f(1, 0);
1498                         glVertex3f(1, -1, 0.0f);
1499                         glTexCoord2f(1, 1);
1500                         glVertex3f(1, 1, 0.0f);
1501                         glTexCoord2f(0, 1);
1502                         glVertex3f(-1, 1, 0.0f);
1503                         glEnd();
1504                         glPopMatrix();
1505                     }
1506                 }
1507                 if (objects.type[i] == boxtype) {
1508                     distcheck = distsq(&Person::players[0]->coords, &objects.position[i]);
1509                     if (distcheck < mapviewdist) {
1510                         Mapboxtexture.bind();
1511                         glColor4f(.4, .4, .4, opac * (1 - distcheck / mapviewdist));
1512                         glPushMatrix();
1513                         glTranslatef(objects.position[i].x / terrain.scale / 256 * -2 + 1, objects.position[i].z / terrain.scale / 256 * 2 - 1, 0);
1514                         glRotatef(objects.yaw[i], 0, 0, 1);
1515                         glScalef(.01 * objects.scale[i], .01 * objects.scale[i], .01 * objects.scale[i]);
1516                         glBegin(GL_QUADS);
1517                         glTexCoord2f(0, 0);
1518                         glVertex3f(-1, -1, 0.0f);
1519                         glTexCoord2f(1, 0);
1520                         glVertex3f(1, -1, 0.0f);
1521                         glTexCoord2f(1, 1);
1522                         glVertex3f(1, 1, 0.0f);
1523                         glTexCoord2f(0, 1);
1524                         glVertex3f(-1, 1, 0.0f);
1525                         glEnd();
1526                         glPopMatrix();
1527                     }
1528                 }
1529             }
1530             if (editorenabled) {
1531                 Mapcircletexture.bind();
1532                 for (int i = 0; i < numboundaries; i++) {
1533                     glColor4f(0, 0, 0, opac / 3);
1534                     glPushMatrix();
1535                     glTranslatef(boundary[i].x / terrain.scale / 256 * -2 + 1, boundary[i].z / terrain.scale / 256 * 2 - 1, 0);
1536                     glScalef(.002, .002, .002);
1537                     glBegin(GL_QUADS);
1538                     glTexCoord2f(0, 0);
1539                     glVertex3f(-1, -1, 0.0f);
1540                     glTexCoord2f(1, 0);
1541                     glVertex3f(1, -1, 0.0f);
1542                     glTexCoord2f(1, 1);
1543                     glVertex3f(1, 1, 0.0f);
1544                     glTexCoord2f(0, 1);
1545                     glVertex3f(-1, 1, 0.0f);
1546                     glEnd();
1547                     glPopMatrix();
1548                 }
1549             }
1550             for (unsigned i = 0; i < Person::players.size(); i++) {
1551                 distcheck = distsq(&Person::players[0]->coords, &Person::players[i]->coords);
1552                 if (distcheck < mapviewdist) {
1553                     glPushMatrix();
1554                     Maparrowtexture.bind();
1555                     if (i == 0)
1556                         glColor4f(1, 1, 1, opac);
1557                     else if (Person::players[i]->dead == 2 || Person::players[i]->howactive > typesleeping)
1558                         glColor4f(0, 0, 0, opac * (1 - distcheck / mapviewdist));
1559                     else if (Person::players[i]->dead)
1560                         glColor4f(.3, .3, .3, opac * (1 - distcheck / mapviewdist));
1561                     else if (Person::players[i]->aitype == attacktypecutoff)
1562                         glColor4f(1, 0, 0, opac * (1 - distcheck / mapviewdist));
1563                     else if (Person::players[i]->aitype == passivetype)
1564                         glColor4f(0, 1, 0, opac * (1 - distcheck / mapviewdist));
1565                     else
1566                         glColor4f(1, 1, 0, 1);
1567                     glTranslatef(Person::players[i]->coords.x / terrain.scale / 256 * -2 + 1, Person::players[i]->coords.z / terrain.scale / 256 * 2 - 1, 0);
1568                     glRotatef(Person::players[i]->yaw + 180, 0, 0, 1);
1569                     glScalef(.005, .005, .005);
1570                     glBegin(GL_QUADS);
1571                     glTexCoord2f(0, 0);
1572                     glVertex3f(-1, -1, 0.0f);
1573                     glTexCoord2f(1, 0);
1574                     glVertex3f(1, -1, 0.0f);
1575                     glTexCoord2f(1, 1);
1576                     glVertex3f(1, 1, 0.0f);
1577                     glTexCoord2f(0, 1);
1578                     glVertex3f(-1, 1, 0.0f);
1579                     glEnd();
1580                     glPopMatrix();
1581                 }
1582             }
1583             glPopMatrix();
1584             glDisable(GL_TEXTURE_2D);
1585             glMatrixMode(GL_PROJECTION);
1586             glPopMatrix();
1587             glMatrixMode(GL_MODELVIEW);
1588             glPopMatrix();
1589             glEnable(GL_DEPTH_TEST);
1590             glEnable(GL_CULL_FACE);
1591             glDisable(GL_BLEND);
1592             glDepthMask(1);
1593         }
1594
1595         if (loading && !stealthloading && (!campaign || Person::players[0]->dead)) {
1596             glDisable(GL_DEPTH_TEST);
1597             glDisable(GL_CULL_FACE);
1598             glDisable(GL_LIGHTING);
1599             glDisable(GL_TEXTURE_2D);
1600             glDepthMask(0);
1601             glMatrixMode(GL_PROJECTION);
1602             glPushMatrix();
1603             glLoadIdentity();
1604             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1605             glMatrixMode(GL_MODELVIEW);
1606             glPushMatrix();
1607             glLoadIdentity();
1608             glScalef(screenwidth, screenheight, 1);
1609             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1610             glEnable(GL_BLEND);
1611             glColor4f(0, 0, 0, .7);
1612             glBegin(GL_QUADS);
1613             glVertex3f(0, 0, 0.0f);
1614             glVertex3f(256, 0, 0.0f);
1615             glVertex3f(256, 256, 0.0f);
1616             glVertex3f(0, 256, 0.0f);
1617             glEnd();
1618             glMatrixMode(GL_PROJECTION);
1619             glPopMatrix();
1620             glMatrixMode(GL_MODELVIEW);
1621             glPopMatrix();
1622             glEnable(GL_DEPTH_TEST);
1623             glEnable(GL_CULL_FACE);
1624             glDisable(GL_BLEND);
1625             glDepthMask(1);
1626
1627             //logo
1628             glDisable(GL_DEPTH_TEST);
1629             glColor3f (1.0, 1.0, 1.0); // no coloring
1630
1631             glEnable(GL_TEXTURE_2D);
1632
1633             //Minimap
1634
1635             if (loading != 4) {
1636                 glEnable(GL_TEXTURE_2D);
1637                 glColor4f(1, 1, 1, 1);
1638                 sprintf (string, "Loading...");
1639                 text->glPrint(1024 / 2 - 90, 768 / 2, string, 1, 2, 1024, 768);
1640             }
1641             loading = 2;
1642             drawmode = normalmode;
1643         }
1644
1645         if (winfreeze && !campaign) {
1646             glDisable(GL_DEPTH_TEST);
1647             glDisable(GL_CULL_FACE);
1648             glDisable(GL_LIGHTING);
1649             glDisable(GL_TEXTURE_2D);
1650             glDepthMask(0);
1651             glMatrixMode(GL_PROJECTION);
1652             glPushMatrix();
1653             glLoadIdentity();
1654             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1655             glMatrixMode(GL_MODELVIEW);
1656             glPushMatrix();
1657             glLoadIdentity();
1658             glScalef(screenwidth, screenheight, 1);
1659             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1660             glEnable(GL_BLEND);
1661             glColor4f(0, 0, 0, .4);
1662             glBegin(GL_QUADS);
1663             glVertex3f(0, 0, 0.0f);
1664             glVertex3f(256, 0, 0.0f);
1665             glVertex3f(256, 256, 0.0f);
1666             glVertex3f(0, 256, 0.0f);
1667             glEnd();
1668             glMatrixMode(GL_PROJECTION);
1669             glPopMatrix();
1670             glMatrixMode(GL_MODELVIEW);
1671             glPopMatrix();
1672             glEnable(GL_DEPTH_TEST);
1673             glEnable(GL_CULL_FACE);
1674             glDisable(GL_BLEND);
1675             glDepthMask(1);
1676
1677             //logo
1678             glDisable(GL_DEPTH_TEST);
1679             glColor3f (1.0, 1.0, 1.0); // no coloring
1680
1681             glEnable(GL_TEXTURE_2D);
1682
1683             //Win Screen Won Victory
1684
1685             glEnable(GL_TEXTURE_2D);
1686             glColor4f(1, 1, 1, 1);
1687             sprintf (string, "Level Cleared!");
1688             text->glPrintOutlined(1024 / 2 - strlen(string) * 10, 768 * 7 / 8, string, 1, 2, 1024, 768);
1689
1690             sprintf (string, "Score:     %d", (int)(bonustotal - startbonustotal));
1691             text->glPrintOutlined(1024 / 30, 768 * 6 / 8, string, 1, 2, 1024, 768);
1692
1693             if (campaign)
1694                 sprintf (string, "Press Escape or Space to continue");
1695             else
1696                 sprintf (string, "Press Escape to return to menu or Space to continue");
1697             text->glPrintOutlined(640 / 2 - strlen(string) * 5, 480 * 1 / 16, string, 1, 1, 640, 480);
1698
1699             char temp[255];
1700
1701             for (int i = 0; i < 255; i++)
1702                 string[i] = '\0';
1703             sprintf (temp, "Time:      %d:", (int)(((int)leveltime - (int)(leveltime) % 60) / 60));
1704             strcat(string, temp);
1705             if ((int)(leveltime) % 60 < 10)
1706                 strcat(string, "0");
1707             sprintf (temp, "%d", (int)(leveltime) % 60);
1708             strcat(string, temp);
1709             text->glPrintOutlined(1024 / 30, 768 * 6 / 8 - 40, string, 1, 2, 1024, 768);
1710
1711             //Awards
1712             int awards[award_count];
1713             int numawards = award_awards(awards);
1714
1715             for (int i = 0; i < numawards && i < 6; i++)
1716                 text->glPrintOutlined(1024 / 30, 768 * 6 / 8 - 90 - 40 * i, award_names[awards[i]], 1, 2, 1024, 768);
1717         }
1718
1719         if (drawmode != normalmode) {
1720             glEnable(GL_TEXTURE_2D);
1721             glFinish();
1722             if (!drawtoggle || drawmode != realmotionblurmode || (drawtoggle == 2 || change == 1)) {
1723                 if (screentexture) {
1724
1725                     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
1726                     GLfloat subtractColor[4] = { 0.5, 0.5, 0.5, 0.0 };
1727                     glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, subtractColor);
1728                     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
1729                     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_CONSTANT_EXT);
1730                     glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
1731
1732                     glBindTexture( GL_TEXTURE_2D, screentexture);
1733                     glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);
1734                 }
1735             }
1736             if ((drawtoggle || change == 1) && drawmode == realmotionblurmode) {
1737                 if (screentexture2) {
1738                     glBindTexture( GL_TEXTURE_2D, screentexture2);
1739                     glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);
1740                 }
1741                 if (!screentexture2) {
1742                     glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1743
1744                     glGenTextures( 1, &screentexture2 );
1745                     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1746
1747                     glEnable(GL_TEXTURE_2D);
1748                     glBindTexture( GL_TEXTURE_2D, screentexture2);
1749                     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1750                     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1751
1752                     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1753                 }
1754             }
1755         }
1756
1757         glClear(GL_DEPTH_BUFFER_BIT);
1758         Game::ReSizeGLScene(90, .1f);
1759         glViewport(0, 0, screenwidth, screenheight);
1760
1761         if (drawmode != normalmode) {
1762             glDisable(GL_DEPTH_TEST);
1763             if (drawmode == motionblurmode) {
1764                 glDrawBuffer(GL_FRONT);
1765                 glReadBuffer(GL_BACK);
1766             }
1767             glColor3f (1.0, 1.0, 1.0); // no coloring
1768
1769             glEnable(GL_TEXTURE_2D);
1770             glBindTexture( GL_TEXTURE_2D, screentexture);
1771             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1772             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1773             glDisable(GL_DEPTH_TEST);
1774             glDisable(GL_CULL_FACE);
1775             glDisable(GL_LIGHTING);
1776             glDepthMask(0);
1777             glMatrixMode(GL_PROJECTION);
1778             glPushMatrix();
1779             glLoadIdentity();
1780             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1781             glMatrixMode(GL_MODELVIEW);
1782             glPushMatrix();
1783             glLoadIdentity();
1784             glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
1785             glTranslatef(1, 1, 0);
1786             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1787             glEnable(GL_BLEND);
1788             if (drawmode == motionblurmode) {
1789                 if (motionbluramount < .2)
1790                     motionbluramount = .2;
1791                 glColor4f(1, 1, 1, motionbluramount);
1792                 glPushMatrix();
1793                 glBegin(GL_QUADS);
1794                 glTexCoord2f(0, 0);
1795                 glVertex3f(-1, -1, 0.0f);
1796                 glTexCoord2f(texcoordwidth, 0);
1797                 glVertex3f(1, -1, 0.0f);
1798                 glTexCoord2f(texcoordwidth, texcoordheight);
1799                 glVertex3f(1, 1, 0.0f);
1800                 glTexCoord2f(0, texcoordheight);
1801                 glVertex3f(-1, 1, 0.0f);
1802                 glEnd();
1803                 glPopMatrix();
1804             }
1805             if (drawmode == realmotionblurmode) {
1806                 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1807                 glClear(GL_COLOR_BUFFER_BIT);
1808                 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
1809                 glBindTexture( GL_TEXTURE_2D, screentexture);
1810                 glColor4f(1, 1, 1, .5);
1811                 glPushMatrix();
1812                 glBegin(GL_QUADS);
1813                 glTexCoord2f(0, 0);
1814                 glVertex3f(-1, -1, 0.0f);
1815                 glTexCoord2f(texcoordwidth, 0);
1816                 glVertex3f(1, -1, 0.0f);
1817                 glTexCoord2f(texcoordwidth, texcoordheight);
1818                 glVertex3f(1, 1, 0.0f);
1819                 glTexCoord2f(0, texcoordheight);
1820                 glVertex3f(-1, 1, 0.0f);
1821                 glEnd();
1822                 glPopMatrix();
1823                 glBindTexture( GL_TEXTURE_2D, screentexture2);
1824                 glColor4f(1, 1, 1, .5);
1825                 glPushMatrix();
1826                 glBegin(GL_QUADS);
1827                 glTexCoord2f(0, 0);
1828                 glVertex3f(-1, -1, 0.0f);
1829                 glTexCoord2f(texcoordwidth, 0);
1830                 glVertex3f(1, -1, 0.0f);
1831                 glTexCoord2f(texcoordwidth, texcoordheight);
1832                 glVertex3f(1, 1, 0.0f);
1833                 glTexCoord2f(0, texcoordheight);
1834                 glVertex3f(-1, 1, 0.0f);
1835                 glEnd();
1836                 glPopMatrix();
1837                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1838             }
1839             if (drawmode == doublevisionmode) {
1840                 static float crosseyedness;
1841                 crosseyedness = abs(Person::players[0]->damage - Person::players[0]->superpermanentdamage - (Person::players[0]->damagetolerance - Person::players[0]->superpermanentdamage) * 1 / 2) / 30;
1842                 if (crosseyedness > 1)
1843                     crosseyedness = 1;
1844                 if (crosseyedness < 0)
1845                     crosseyedness = 0;
1846                 glColor4f(1, 1, 1, 1);
1847                 glDisable(GL_BLEND);
1848                 glPushMatrix();
1849                 glScalef(1, 1, 1);
1850                 glBegin(GL_QUADS);
1851                 glTexCoord2f(0, 0);
1852                 glVertex3f(-1, -1, 0.0f);
1853                 glTexCoord2f(texcoordwidth, 0);
1854                 glVertex3f(1, -1, 0.0f);
1855                 glTexCoord2f(texcoordwidth, texcoordheight);
1856                 glVertex3f(1, 1, 0.0f);
1857                 glTexCoord2f(0, texcoordheight);
1858                 glVertex3f(-1, 1, 0.0f);
1859                 glEnd();
1860                 glPopMatrix();
1861                 if (crosseyedness) {
1862                     glColor4f(1, 1, 1, .5);
1863                     glEnable(GL_BLEND);
1864                     glPushMatrix();
1865                     glTranslatef(.015 * crosseyedness, 0, 0);
1866                     glScalef(1, 1, 1);
1867                     glBegin(GL_QUADS);
1868                     glTexCoord2f(0, 0);
1869                     glVertex3f(-1, -1, 0.0f);
1870                     glTexCoord2f(texcoordwidth, 0);
1871                     glVertex3f(1, -1, 0.0f);
1872                     glTexCoord2f(texcoordwidth, texcoordheight);
1873                     glVertex3f(1, 1, 0.0f);
1874                     glTexCoord2f(0, texcoordheight);
1875                     glVertex3f(-1, 1, 0.0f);
1876                     glEnd();
1877                     glPopMatrix();
1878                 }
1879             }
1880             if (drawmode == glowmode) {
1881                 glColor4f(.5, .5, .5, .5);
1882                 glEnable(GL_BLEND);
1883                 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
1884                 glPushMatrix();
1885                 glTranslatef(.01, 0, 0);
1886                 glBegin(GL_QUADS);
1887                 glTexCoord2f(0, 0);
1888                 glVertex3f(-1, -1, 0.0f);
1889                 glTexCoord2f(texcoordwidth, 0);
1890                 glVertex3f(1, -1, 0.0f);
1891                 glTexCoord2f(texcoordwidth, texcoordheight);
1892                 glVertex3f(1, 1, 0.0f);
1893                 glTexCoord2f(0, texcoordheight);
1894                 glVertex3f(-1, 1, 0.0f);
1895                 glEnd();
1896                 glPopMatrix();
1897                 glPushMatrix();
1898                 glTranslatef(-.01, 0, 0);
1899                 glBegin(GL_QUADS);
1900                 glTexCoord2f(0, 0);
1901                 glVertex3f(-1, -1, 0.0f);
1902                 glTexCoord2f(texcoordwidth, 0);
1903                 glVertex3f(1, -1, 0.0f);
1904                 glTexCoord2f(texcoordwidth, texcoordheight);
1905                 glVertex3f(1, 1, 0.0f);
1906                 glTexCoord2f(0, texcoordheight);
1907                 glVertex3f(-1, 1, 0.0f);
1908                 glEnd();
1909                 glPopMatrix();
1910                 glPushMatrix();
1911                 glTranslatef(.0, .01, 0);
1912                 glBegin(GL_QUADS);
1913                 glTexCoord2f(0, 0);
1914                 glVertex3f(-1, -1, 0.0f);
1915                 glTexCoord2f(texcoordwidth, 0);
1916                 glVertex3f(1, -1, 0.0f);
1917                 glTexCoord2f(texcoordwidth, texcoordheight);
1918                 glVertex3f(1, 1, 0.0f);
1919                 glTexCoord2f(0, texcoordheight);
1920                 glVertex3f(-1, 1, 0.0f);
1921                 glEnd();
1922                 glPopMatrix();
1923                 glPushMatrix();
1924                 glTranslatef(0, -.01, 0);
1925                 glBegin(GL_QUADS);
1926                 glTexCoord2f(0, 0);
1927                 glVertex3f(-1, -1, 0.0f);
1928                 glTexCoord2f(texcoordwidth, 0);
1929                 glVertex3f(1, -1, 0.0f);
1930                 glTexCoord2f(texcoordwidth, texcoordheight);
1931                 glVertex3f(1, 1, 0.0f);
1932                 glTexCoord2f(0, texcoordheight);
1933                 glVertex3f(-1, 1, 0.0f);
1934                 glEnd();
1935                 glPopMatrix();
1936             }
1937             if (drawmode == radialzoommode) {
1938                 for (int i = 0; i < 3; i++) {
1939                     glColor4f(1, 1, 1, 1 / ((float)i + 1));
1940                     glPushMatrix();
1941                     glScalef(1 + (float)i * .01, 1 + (float)i * .01, 1);
1942                     glBegin(GL_QUADS);
1943                     glTexCoord2f(0, 0);
1944                     glVertex3f(-1, -1, 0.0f);
1945                     glTexCoord2f(texcoordwidth, 0);
1946                     glVertex3f(1, -1, 0.0f);
1947                     glTexCoord2f(texcoordwidth, texcoordheight);
1948                     glVertex3f(1, 1, 0.0f);
1949                     glTexCoord2f(0, texcoordheight);
1950                     glVertex3f(-1, 1, 0.0f);
1951                     glEnd();
1952                     glPopMatrix();
1953                 }
1954             }
1955             glDisable(GL_TEXTURE_2D);
1956             glMatrixMode(GL_PROJECTION);
1957             glPopMatrix();
1958             glMatrixMode(GL_MODELVIEW);
1959             glPopMatrix();
1960             glEnable(GL_DEPTH_TEST);
1961             glEnable(GL_CULL_FACE);
1962             glDisable(GL_BLEND);
1963             glDepthMask(1);
1964         }
1965
1966         if (console) {
1967             glEnable(GL_TEXTURE_2D);
1968             glColor4f(1, 1, 1, 1);
1969             int offset = 0;
1970             if (consoleselected >= 60)
1971                 offset = consoleselected - 60;
1972             sprintf (string, " ]");
1973             text->glPrint(10, 30, string, 0, 1, 1024, 768);
1974             if (consoleblink) {
1975                 sprintf (string, "_");
1976                 text->glPrint(30 + (float)(consoleselected) * 10 - offset * 10, 30, string, 0, 1, 1024, 768);
1977             }
1978             for (unsigned i = 0; i < 15; i++)
1979                 for (unsigned j = 0; j < consoletext[i].size(); j++) {
1980                     glColor4f(1, 1, 1, 1 - (float)(i) / 16);
1981                     sprintf (string, "%c", consoletext[i][j]);
1982                     text->glPrint(30 + j * 10 - offset * 10, 30 + i * 20, string, 0, 1, 1024, 768);
1983                 }
1984         }
1985     }
1986
1987     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
1988         multiplier = tempmult;
1989     }
1990
1991     if (mainmenu) {
1992         DrawMenu();
1993     }
1994
1995     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
1996         tempmult = multiplier;
1997         multiplier = 0;
1998     }
1999
2000     if ( side == stereoRight || side == stereoCenter ) {
2001         if (drawmode != motionblurmode || mainmenu) {
2002             swap_gl_buffers();
2003         }
2004     }
2005
2006     glDrawBuffer(GL_BACK);
2007     glReadBuffer(GL_BACK);
2008
2009     weapons.DoStuff();
2010
2011     if (drawtoggle == 2)
2012         drawtoggle = 0;
2013
2014     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
2015         multiplier = tempmult;
2016     }
2017     //Jordan fixed your warning!
2018     return 0;
2019 }
2020
2021 void DrawMenu()
2022 {
2023     // !!! FIXME: hack: clamp framerate in menu so text input works correctly on fast systems.
2024     SDL_Delay(15);
2025
2026     glDrawBuffer(GL_BACK);
2027     glReadBuffer(GL_BACK);
2028     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
2029     Game::ReSizeGLScene(90, .1f);
2030
2031     //draw menu background
2032     glClear(GL_DEPTH_BUFFER_BIT);
2033     glEnable(GL_ALPHA_TEST);
2034     glAlphaFunc(GL_GREATER, 0.001f);
2035     glEnable(GL_TEXTURE_2D);
2036     glDisable(GL_DEPTH_TEST);
2037     glDisable(GL_CULL_FACE);
2038     glDisable(GL_LIGHTING);
2039     glDepthMask(0);
2040     glMatrixMode(GL_PROJECTION);
2041     glPushMatrix();
2042     glLoadIdentity();
2043     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
2044     glMatrixMode(GL_MODELVIEW);
2045     glPushMatrix();
2046     glLoadIdentity();
2047     glTranslatef(screenwidth / 2, screenheight / 2, 0);
2048     glPushMatrix();
2049     glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
2050     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2051     glDisable(GL_BLEND);
2052     glColor4f(0, 0, 0, 1.0);
2053     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2054     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2055     glDisable(GL_TEXTURE_2D);
2056     glBegin(GL_QUADS);
2057     glVertex3f(-1, -1, 0);
2058     glVertex3f(+1, -1, 0);
2059     glVertex3f(+1, +1, 0);
2060     glVertex3f(-1, +1, 0);
2061     glEnd();
2062     glEnable(GL_BLEND);
2063     glColor4f(0.4, 0.4, 0.4, 1.0);
2064     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2065     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2066     glEnable(GL_TEXTURE_2D);
2067     Game::Mainmenuitems[4].bind();
2068     glBegin(GL_QUADS);
2069     glTexCoord2f(0, 0);
2070     glVertex3f(-1, -1, 0);
2071     glTexCoord2f(1, 0);
2072     glVertex3f(+1, -1, 0);
2073     glTexCoord2f(1, 1);
2074     glVertex3f(+1, +1, 0);
2075     glTexCoord2f(0, 1);
2076     glVertex3f(-1, +1, 0);
2077     glEnd();
2078     glPopMatrix();
2079     glPopMatrix();
2080     glMatrixMode(GL_PROJECTION);
2081     glPopMatrix();
2082     glMatrixMode(GL_MODELVIEW);
2083
2084
2085
2086     glMatrixMode(GL_PROJECTION);
2087     glPushMatrix();
2088     glLoadIdentity();
2089     glOrtho(0, 640, 0, 480, -100, 100);
2090     glMatrixMode(GL_MODELVIEW);
2091     glPushMatrix();
2092     glLoadIdentity();
2093     glEnable(GL_TEXTURE_2D);
2094
2095     Menu::drawItems();
2096
2097     //draw mouse cursor
2098     glMatrixMode(GL_PROJECTION);
2099     glPopMatrix();
2100     glMatrixMode(GL_MODELVIEW);
2101     glPopMatrix();
2102
2103     glMatrixMode(GL_PROJECTION);
2104     glPushMatrix();
2105     glLoadIdentity();
2106     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
2107     glMatrixMode(GL_MODELVIEW);
2108     glPushMatrix();
2109     glLoadIdentity();
2110     glTranslatef(screenwidth / 2, screenheight / 2, 0);
2111     glPushMatrix();
2112     glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
2113     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2114     glEnable(GL_BLEND);
2115     glEnable(GL_TEXTURE_2D);
2116     glColor4f(1, 1, 1, 1);
2117     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2118     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2119     glPopMatrix();
2120     if (!Game::waiting) { // hide the cursor while waiting for a key
2121         glPushMatrix();
2122         glTranslatef(Game::mousecoordh - screenwidth / 2, Game::mousecoordv * -1 + screenheight / 2, 0);
2123         glScalef((float)screenwidth / 64, (float)screenwidth / 64, 1);
2124         glTranslatef(1, -1, 0);
2125         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2126         glColor4f(1, 1, 1, 1);
2127         Game::cursortexture.bind();
2128         glPushMatrix();
2129         glBegin(GL_QUADS);
2130         glTexCoord2f(0, 0);
2131         glVertex3f(-1, -1, 0.0f);
2132         glTexCoord2f(1, 0);
2133         glVertex3f(1, -1, 0.0f);
2134         glTexCoord2f(1, 1);
2135         glVertex3f(1, 1, 0.0f);
2136         glTexCoord2f(0, 1);
2137         glVertex3f(-1, 1, 0.0f);
2138         glEnd();
2139         glPopMatrix();
2140         glPopMatrix();
2141     }
2142     glPopMatrix();
2143     glMatrixMode(GL_PROJECTION);
2144     glPopMatrix();
2145
2146
2147     //draw screen flash
2148     if (flashamount > 0) {
2149         if (flashamount > 1)
2150             flashamount = 1;
2151         if (flashdelay <= 0)
2152             flashamount -= multiplier;
2153         flashdelay--;
2154         if (flashamount < 0)
2155             flashamount = 0;
2156         glDisable(GL_DEPTH_TEST);
2157         glDisable(GL_CULL_FACE);
2158         glDisable(GL_LIGHTING);
2159         glDisable(GL_TEXTURE_2D);
2160         glDepthMask(0);
2161         glMatrixMode(GL_PROJECTION);
2162         glPushMatrix();
2163         glLoadIdentity();
2164         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
2165         glMatrixMode(GL_MODELVIEW);
2166         glPushMatrix();
2167         glLoadIdentity();
2168         glScalef(screenwidth, screenheight, 1);
2169         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2170         glEnable(GL_BLEND);
2171         glColor4f(flashr, flashg, flashb, flashamount);
2172         glBegin(GL_QUADS);
2173         glVertex3f(0, 0, 0.0f);
2174         glVertex3f(256, 0, 0.0f);
2175         glVertex3f(256, 256, 0.0f);
2176         glVertex3f(0, 256, 0.0f);
2177         glEnd();
2178         glMatrixMode(GL_PROJECTION);
2179         glPopMatrix();
2180         glMatrixMode(GL_MODELVIEW);
2181         glPopMatrix();
2182         glEnable(GL_DEPTH_TEST);
2183         glEnable(GL_CULL_FACE);
2184         glDisable(GL_BLEND);
2185         glDepthMask(1);
2186     }
2187 }