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