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