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