]> git.jsancho.org Git - lugaru.git/blob - Source/GameDraw.cpp
abs() -> fabs()
[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     static char string[256] = "";
126     static char string2[256] = "";
127     static char string3[256] = "";
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_EXT, GL_TEXTURE_LOD_BIAS_EXT, 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_EXT, GL_TEXTURE_LOD_BIAS_EXT, 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                     sprintf (string, "%d", (int)bonusvalue);
576                     glColor4f(0, 0, 0, 1 - bonustime);
577                     text->glPrintOutline(1024 / 2 - 10 * strlen(string) - 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 * strlen(string), 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                 sprintf (string, " ");
591                 sprintf (string2, " ");
592                 sprintf (string3, " ");
593                 if (tutorialstage == 0) {
594                     sprintf (string, " ");
595                     sprintf (string2, " ");
596                     sprintf (string3, " ");
597                 }
598                 if (tutorialstage == 1) {
599                     sprintf (string, "Welcome to the Lugaru training level!");
600                     sprintf (string2, " ");
601                     sprintf (string3, " ");
602                 }
603                 if (tutorialstage == 2) {
604                     sprintf (string, "BASIC MOVEMENT:");
605                     sprintf (string2, " ");
606                     sprintf (string3, " ");
607                 }
608                 if (tutorialstage == 3) {
609                     sprintf (string, "You can move the mouse to rotate the camera.");
610                     sprintf (string2, " ");
611                     sprintf (string3, " ");
612                 }
613                 if (tutorialstage == 4) {
614                     sprintf (string, "Try using the %s, %s, %s and %s keys to move around.", Input::keyToChar(forwardkey), Input::keyToChar(leftkey), Input::keyToChar(backkey), Input::keyToChar(rightkey));
615                     sprintf (string2, "All movement is relative to the camera.");
616                     sprintf (string3, " ");
617                 }
618                 if (tutorialstage == 5) {
619                     sprintf (string, "Please press %s to jump.", Input::keyToChar(jumpkey));
620                     sprintf (string2, "You can hold it longer to jump higher.");
621                     sprintf (string3, " ");
622                 }
623                 if (tutorialstage == 6) {
624                     sprintf (string, "You can press %s to crouch.", Input::keyToChar(crouchkey));
625                     sprintf (string2, "You can jump higher from a crouching position.");
626                     sprintf (string3, " ");
627                 }
628                 if (tutorialstage == 7) {
629                     sprintf (string, "While running, you can press %s to roll.", Input::keyToChar(crouchkey));
630                     sprintf (string2, " ");
631                     sprintf (string3, " ");
632                 }
633                 if (tutorialstage == 8) {
634                     sprintf (string, "While crouching, you can sneak around silently");
635                     sprintf (string2, "using the movement keys.");
636                     sprintf (string3, " ");
637                 }
638                 if (tutorialstage == 9) {
639                     sprintf (string, "Release the crouch key while sneaking and hold the movement keys");
640                     sprintf (string2, "to run animal-style.");
641                     sprintf (string3, " ");
642                 }
643                 if (tutorialstage == 10) {
644                     sprintf (string, "ADVANCED MOVEMENT:");
645                     sprintf (string2, " ");
646                     sprintf (string3, " ");
647                 }
648                 if (tutorialstage == 11) {
649                     sprintf (string, "When you jump at a wall, you can hold %s again", Input::keyToChar(jumpkey));
650                     sprintf (string2, "during impact to perform a walljump.");
651                     sprintf (string3, "Be sure to use the movement keys to press against the wall");
652                 }
653                 if (tutorialstage == 12) {
654                     sprintf (string, "While in the air, you can press crouch to flip.");
655                     sprintf (string2, "Walljumps and flips confuse enemies and give you more control.");
656                     sprintf (string3, " ");
657                 }
658                 if (tutorialstage == 13) {
659                     sprintf (string, "BASIC COMBAT:");
660                     sprintf (string2, " ");
661                     sprintf (string3, " ");
662                 }
663                 if (tutorialstage == 14) {
664                     sprintf (string, "There is now an imaginary enemy");
665                     sprintf (string2, "in the middle of the training area.");
666                     sprintf (string3, " ");
667                 }
668                 if (tutorialstage == 15) {
669                     if (attackkey == MOUSEBUTTON1)
670                         sprintf (string, "Click to attack when you are near an enemy.");
671                     else
672                         sprintf (string, "Press %s to attack when you are near an enemy.", Input::keyToChar(attackkey));
673                     sprintf (string2, "You can punch by standing still near an enemy and attacking.");
674                     sprintf (string3, " ");
675                 }
676                 if (tutorialstage == 16) {
677                     sprintf (string, "If you are close, you will perform a weak punch.");
678                     sprintf (string2, "The weak punch is excellent for starting attack combinations.");
679                     sprintf (string3, " ");
680                 }
681                 if (tutorialstage == 17) {
682                     sprintf (string, "Attacking while running results in a spin kick.");
683                     sprintf (string2, "This is one of your most powerful ground attacks.");
684                     sprintf (string3, " ");
685                 }
686                 if (tutorialstage == 18) {
687                     sprintf (string, "Sweep the enemy's legs out by attacking while crouched.");
688                     sprintf (string2, "This is a very fast attack, and easy to follow up.");
689                     sprintf (string3, " ");
690                 }
691                 if (tutorialstage == 19) {
692                     sprintf (string, "When an enemy is on the ground, you can deal some extra");
693                     sprintf (string2, "damage by running up and drop-kicking him.");
694                     sprintf (string3, "(Try knocking them down with a sweep first)");
695                 }
696                 if (tutorialstage == 20) {
697                     sprintf (string, "Your most powerful individual attack is the rabbit kick.");
698                     if (attackkey == MOUSEBUTTON1)
699                         sprintf (string2, "Run at the enemy while holding the mouse button, and press");
700                     else
701                         sprintf (string2, "Run at the enemy while holding %s, and press", Input::keyToChar(attackkey));
702                     sprintf (string3, "the jump key (%s) to attack.", Input::keyToChar(jumpkey));
703                 }
704                 if (tutorialstage == 21) {
705                     sprintf (string, "This attack is devastating if timed correctly.");
706                     sprintf (string2, "Even if timed incorrectly, it will knock the enemy over.");
707                     if (againbonus)
708                         sprintf (string3, "Try rabbit-kicking the imaginary enemy again.");
709                     else
710                         sprintf (string3, "Try rabbit-kicking the imaginary enemy.");
711                 }
712                 if (tutorialstage == 22) {
713                     sprintf (string, "If you sneak behind an enemy unnoticed, you can kill");
714                     sprintf (string2, "him instantly. Move close behind this enemy");
715                     sprintf (string3, "and attack.");
716                 }
717                 if (tutorialstage == 23) {
718                     sprintf (string, "Another important attack is the wall kick. When an enemy");
719                     sprintf (string2, "is near a wall, perform a walljump nearby and hold");
720                     sprintf (string3, "the attack key during impact with the wall.");
721                 }
722                 if (tutorialstage == 24) {
723                     sprintf (string, "You can tackle enemies by running at them animal-style");
724                     if (attackkey == MOUSEBUTTON1)
725                         sprintf (string2, "and pressing jump (%s) or attack(mouse button).", Input::keyToChar(jumpkey));
726                     else
727                         sprintf (string2, "and pressing jump (%s) or attack(%s).", Input::keyToChar(jumpkey), Input::keyToChar(attackkey));
728                     sprintf (string3, "This is especially useful when they are running away.");
729                 }
730                 if (tutorialstage == 25) {
731                     sprintf (string, "Dodge by pressing back and attack. Dodging is essential");
732                     sprintf (string2, "against enemies with swords or other long weapons.");
733                     sprintf (string3, " ");
734                 }
735                 if (tutorialstage == 26) {
736                     sprintf (string, "REVERSALS AND COUNTER-REVERSALS");
737                     sprintf (string2, " ");
738                     sprintf (string3, " ");
739                 }
740                 if (tutorialstage == 27) {
741                     sprintf (string, "The enemy can now reverse your attacks.");
742                     sprintf (string2, " ");
743                     sprintf (string3, " ");
744                 }
745                 if (tutorialstage == 28) {
746                     sprintf (string, "If you attack, you will notice that the enemy now sometimes");
747                     sprintf (string2, "catches your attack and uses it against you. Hold");
748                     sprintf (string3, "crouch (%s) after attacking to escape from reversals.", Input::keyToChar(crouchkey));
749                 }
750                 if (tutorialstage == 29) {
751                     sprintf (string, "Try escaping from two more reversals in a row.");
752                     sprintf (string2, " ");
753                     sprintf (string3, " ");
754                 }
755                 if (tutorialstage == 30) {
756                     sprintf (string, "Good!");
757                     sprintf (string2, " ");
758                     sprintf (string3, " ");
759                 }
760                 if (tutorialstage == 31) {
761                     sprintf (string, "To reverse an attack, you must tap crouch (%s) during the", Input::keyToChar(crouchkey));
762                     sprintf (string2, "enemy's attack. You must also be close to the enemy;");
763                     sprintf (string3, "this is especially important against armed opponents.");
764                 }
765                 if (tutorialstage == 32) {
766                     sprintf (string, "The enemy can attack in %d seconds.", (int)(tutorialmaxtime - tutorialstagetime));
767                     sprintf (string2, "This imaginary opponents attacks will be highlighted");
768                     sprintf (string3, "to make this easier.");
769                 }
770                 if (tutorialstage == 33) {
771                     sprintf (string, "Reverse three enemy attacks!");
772                     sprintf (string2, " ");
773                     sprintf (string3, " ");
774                 }
775                 if (tutorialstage == 34) {
776                     sprintf (string, "Reverse two more enemy attacks!");
777                     sprintf (string2, " ");
778                     sprintf (string3, " ");
779                 }
780                 if (tutorialstage == 35) {
781                     sprintf (string, "Reverse one more enemy attack!");
782                     sprintf (string2, " ");
783                     sprintf (string3, " ");
784                 }
785                 if (tutorialstage == 36) {
786                     sprintf (string, "Excellent!");
787                     sprintf (string2, " ");
788                     sprintf (string3, " ");
789                 }
790                 if (tutorialstage == 37) {
791                     sprintf (string, "Now spar with the enemy for %d more seconds.", (int)(tutorialmaxtime - tutorialstagetime));
792                     sprintf (string2, "Damage dealt: %d", (int)damagedealt);
793                     sprintf (string3, "Damage taken: %d.", (int)damagetaken);
794                 }
795                 if (tutorialstage == 38) {
796                     sprintf (string, "WEAPONS:");
797                     sprintf (string2, " ");
798                     sprintf (string3, " ");
799                 }
800                 if (tutorialstage == 39) {
801                     sprintf (string, "There is now an imaginary knife");
802                     sprintf (string2, "in the center of the training area.");
803                     sprintf (string3, " ");
804                 }
805                 if (tutorialstage == 40) {
806                     sprintf (string, "Stand, roll or handspring over the knife");
807                     sprintf (string2, "while pressing %s to pick it up.", Input::keyToChar(throwkey));
808                     sprintf (string3, "You can crouch and press the same key to drop it again.");
809                 }
810                 if (tutorialstage == 41) {
811                     sprintf (string, "You can equip and unequip weapons using the %s key.", Input::keyToChar(drawkey));
812                     sprintf (string2, "Sometimes it is best to keep them unequipped to");
813                     sprintf (string3, "prevent enemies from taking them. ");
814                 }
815                 if (tutorialstage == 42) {
816                     sprintf (string, "The knife is the smallest weapon and the least encumbering.");
817                     sprintf (string2, "You can equip or unequip it while standing, crouching,");
818                     sprintf (string3, "running or flipping.");
819                 }
820                 if (tutorialstage == 43) {
821                     sprintf (string, "You perform weapon attacks the same way as unarmed attacks,");
822                     sprintf (string2, "but sharp weapons cause permanent damage, instead of the");
823                     sprintf (string3, "temporary trauma from blunt weapons, fists and feet.");
824                 }
825                 if (tutorialstage == 44) {
826                     sprintf (string, "The enemy now has your knife!");
827                     sprintf (string2, "Please reverse two of his knife attacks.");
828                     sprintf (string3, " ");
829                 }
830                 if (tutorialstage == 45) {
831                     sprintf (string, "Please reverse one more of his knife attacks.");
832                     sprintf (string2, " ");
833                     sprintf (string3, " ");
834                 }
835                 if (tutorialstage == 46) {
836                     sprintf (string, "Now he has a sword!");
837                     sprintf (string2, "The sword has longer reach than your arms, so you");
838                     sprintf (string3, "must move close to reverse the sword slash.");
839                 }
840                 if (tutorialstage == 47) {
841                     sprintf (string, "Long weapons like the sword and staff are also useful for defense;");
842                     sprintf (string2, "you can parry enemy weapon attacks by pressing the attack key");
843                     sprintf (string3, "at the right time. Please try parrying the enemy's attacks!");
844                 }
845                 if (tutorialstage == 48) {
846                     sprintf (string, "The staff is like the sword, but has two main attacks.");
847                     sprintf (string2, "The standing smash is fast and effective, and the running");
848                     sprintf (string3, "spin smash is slower and more powerful.");
849                 }
850                 if (tutorialstage == 49) {
851                     sprintf (string, "When facing an enemy, you can throw the knife with %s.", Input::keyToChar(throwkey));
852                     sprintf (string2, "It is possible to throw the knife while flipping,");
853                     sprintf (string3, "but it is very inaccurate.");
854                 }
855                 if (tutorialstage == 50) {
856                     sprintf (string, "You now know everything you can learn from training.");
857                     sprintf (string2, "Everything else you must learn from experience!");
858                     sprintf (string3, " ");
859                 }
860                 if (tutorialstage == 51) {
861                     sprintf (string, "Walk out of the training area to return to the main menu.");
862                     sprintf (string2, " ");
863                     sprintf (string3, " ");
864                 }
865
866                 glColor4f(0, 0, 0, tutorialopac);
867                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string)*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
868                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5 - 20 * screenwidth / 1024, string2, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
869                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5 - 40 * screenwidth / 1024, string3, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
870                 glColor4f(1, 1, 1, tutorialopac);
871                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
872                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
873                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 40 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
874
875                 sprintf (string, "Press 'tab' to skip to the next item.");
876                 sprintf (string2, "Press escape at any time to");
877                 sprintf (string3, "pause or exit the tutorial.");
878
879                 glColor4f(0, 0, 0, 1);
880                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string)*screenwidth / 1024 * .8 - 4, 0 - 4 + screenheight * 1 / 10, string, 1, 1.5 * 1.25 * screenwidth / 1024 * .8, screenwidth, screenheight);
881                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024 * .8 - 4, 0 - 4 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * 1.25 * screenwidth / 1024 * .8, screenwidth, screenheight);
882                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024 * .8 - 4, 0 - 4 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * 1.25 * screenwidth / 1024 * .8, screenwidth, screenheight);
883                 glColor4f(0.5, 0.5, 0.5, 1);
884                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string)*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10, string, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
885                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
886                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
887             }
888
889             //Hot spots
890             if (Hotspot::hotspots.size() && (bonustime >= 1 || bonus <= 0 || bonustime < 0) && !tutoriallevel) {
891                 float closestdist = -1;
892                 float distance = 0;
893                 int closest = Hotspot::current;
894                 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
895                     distance = distsq(&Person::players[0]->coords, &Hotspot::hotspots[i].position);
896                     if (closestdist == -1 || distance < closestdist) {
897                         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))) {
898                             closestdist = distance;
899                             closest = i;
900                         }
901                     }
902                 }
903                 if (closest != -1) {
904                     Hotspot::current = closest;
905                     if (Hotspot::hotspots[closest].type <= 10) {
906                         if (distsq(&Person::players[0]->coords, &Hotspot::hotspots[closest].position) < Hotspot::hotspots[closest].size)
907                             tutorialstagetime = 0;
908                         tutorialmaxtime = 1;
909                         tutorialopac = tutorialmaxtime - tutorialstagetime;
910                         if (tutorialopac > 1)
911                             tutorialopac = 1;
912                         if (tutorialopac < 0)
913                             tutorialopac = 0;
914
915                         sprintf (string, "%s", Hotspot::hotspots[closest].text);
916
917                         int lastline = 0;
918                         int line = 0;
919                         bool done = false;
920                         int i = 0;
921                         while (!done) {
922                             if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') {
923                                 glColor4f(0, 0, 0, tutorialopac);
924                                 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);
925                                 glColor4f(1, 1, 1, tutorialopac);
926                                 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);
927                                 lastline = i + 1;
928                                 line++;
929                                 if (string[i] == '\0')
930                                     done = 1;
931                             }
932                             if (i >= 255)
933                                 done = 1;
934                             i++;
935                         }
936                     } else if ((Hotspot::hotspots[closest].type >= 20) && (Dialog::dialogs[Hotspot::hotspots[closest].type - 20].gonethrough == 0)) {
937                         Dialog::whichdialogue = Hotspot::hotspots[closest].type - 20;
938                         Dialog::currentDialog().play();
939                         Dialog::currentDialog().gonethrough++;
940                     }
941                 }
942             }
943
944             if (Dialog::inDialog() && !mainmenu) {
945                 glDisable(GL_DEPTH_TEST);
946                 glDisable(GL_CULL_FACE);
947                 glDisable(GL_LIGHTING);
948                 glDisable(GL_TEXTURE_2D);
949                 glDepthMask(0);
950                 glMatrixMode(GL_PROJECTION);
951                 glPushMatrix();
952                 glLoadIdentity();
953                 glOrtho(0, screenwidth, 0, screenheight, -100, 100);
954                 glMatrixMode(GL_MODELVIEW);
955                 glPushMatrix();
956                 glLoadIdentity();
957                 if (Dialog::currentScene().location == 1)
958                     glTranslatef(0, screenheight * 3 / 4, 0);
959                 glScalef(screenwidth, screenheight / 4, 1);
960                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
961                 glEnable(GL_BLEND);
962
963                 glColor4f(Dialog::currentScene().color[0], Dialog::currentScene().color[1], Dialog::currentScene().color[2], 0.7);
964                 glBegin(GL_QUADS);
965                 glVertex3f(0, 0, 0.0f);
966                 glVertex3f(1, 0, 0.0f);
967                 glVertex3f(1, 1, 0.0f);
968                 glVertex3f(0, 1, 0.0f);
969                 glEnd();
970                 glMatrixMode(GL_PROJECTION);
971                 glPopMatrix();
972                 glMatrixMode(GL_MODELVIEW);
973                 glPopMatrix();
974                 glEnable(GL_DEPTH_TEST);
975                 glEnable(GL_CULL_FACE);
976                 glDisable(GL_BLEND);
977                 glDepthMask(1);
978                 glEnable(GL_TEXTURE_2D);
979
980                 tutorialopac = 1;
981
982                 float startx;
983                 float starty;
984
985                 startx = screenwidth * 1 / 5;
986                 if (Dialog::currentScene().location == 1) {
987                     starty = screenheight / 16 + screenheight * 4 / 5;
988                 } else {
989                     starty = screenheight * 1 / 5 - screenheight / 16;
990                 }
991
992                 // FIXME - What is that char[] building for?
993                 char tempname[264];
994                 int tempnum = 0;
995                 for (int i = 0; i < 264; i++) {
996                     tempname[i] = '\0';
997                 }
998
999                 for (unsigned i = 0; i < Dialog::currentScene().name.size(); i++) {
1000                     tempname[tempnum] = Dialog::currentScene().name[i];
1001                     if (tempname[tempnum] == '#' || tempname[tempnum] == '\0')
1002                         tempname[tempnum] = '\0';
1003                     else
1004                         tempnum++;
1005                 }
1006
1007                 sprintf (string, "%s: ", tempname);
1008
1009                 if (Dialog::currentScene().color[0] + Dialog::currentScene().color[1] + Dialog::currentScene().color[2] < 1.5) {
1010                     glColor4f(0, 0, 0, tutorialopac);
1011                     text->glPrintOutline(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
1012                     glColor4f(0.7, 0.7, 0.7, tutorialopac);
1013                     text->glPrint(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024, starty, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
1014                 } else {
1015                     glColor4f(0, 0, 0, tutorialopac);
1016                     text->glPrintOutline(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
1017                 }
1018
1019                 tempnum = 0;
1020                 for (unsigned i = 0; i < Dialog::currentScene().text.size() + 1; i++) {
1021                     tempname[tempnum] = Dialog::currentScene().text[i];
1022                     if (Dialog::currentScene().text[i] != '#')
1023                         tempnum++;
1024                 }
1025
1026                 sprintf (string, "%s", tempname);
1027
1028                 int lastline = 0;
1029                 int line = 0;
1030                 bool done = false;
1031                 int i = 0;
1032                 while (!done) {
1033                     if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') {
1034                         if (Dialog::currentScene().color[0] + Dialog::currentScene().color[1] + Dialog::currentScene().color[2] < 1.5) {
1035                             glColor4f(0, 0, 0, tutorialopac);
1036                             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);
1037                             glColor4f(1, 1, 1, tutorialopac);
1038                             text->glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
1039                         } else {
1040                             glColor4f(0, 0, 0, tutorialopac);
1041                             text->glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
1042                         }
1043                         lastline = i + 1;
1044                         line++;
1045                         if (string[i] == '\0')
1046                             done = 1;
1047                     }
1048                     if (i >= 255)
1049                         done = 1;
1050                     i++;
1051                 }
1052             }
1053
1054             if (!tutoriallevel && !winfreeze && !Dialog::inDialog() && !mainmenu) {
1055                 if (campaign) {
1056                     if (scoreadded)
1057                         sprintf (string, "Score: %d", (int)Account::active().getCampaignScore());
1058                     else
1059                         sprintf (string, "Score: %d", (int)Account::active().getCampaignScore() + (int)bonustotal);
1060                 }
1061                 if (!campaign)
1062                     sprintf (string, "Score: %d", (int)bonustotal);
1063                 glColor4f(0, 0, 0, 1);
1064                 text->glPrintOutline(1024 / 40 - 4, 768 / 16 - 4 + 768 * 14 / 16, string, 1, 1.5 * 1.25, 1024, 768);
1065                 glColor4f(1, 0, 0, 1);
1066                 text->glPrint(1024 / 40, 768 / 16 + 768 * 14 / 16, string, 1, 1.5, 1024, 768);
1067                 if (showdamagebar) {
1068                     glDisable(GL_DEPTH_TEST);
1069                     glDisable(GL_CULL_FACE);
1070                     glDisable(GL_LIGHTING);
1071                     glDisable(GL_TEXTURE_2D);
1072                     glDepthMask(0);
1073                     glMatrixMode(GL_PROJECTION);
1074                     glPushMatrix();
1075                     glLoadIdentity();
1076                     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1077                     glMatrixMode(GL_MODELVIEW);
1078                     glPushMatrix();
1079                     glLoadIdentity();
1080                     glTranslatef(15, screenheight * 17.5 / 20, 0);
1081                     glScalef(screenwidth / 3 + 20, screenheight / 20, 1);
1082                     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1083                     glEnable(GL_BLEND);
1084                     glColor4f(0.0, 0.4, 0.0, 0.7);
1085                     float bar = ((float)Person::players[0]->damage) / Person::players[0]->damagetolerance;
1086                     glBegin(GL_QUADS);
1087                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1088                     glVertex3f(1, 0, 0.0f);
1089                     glVertex3f(1, 1, 0.0f);
1090                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1091                     glEnd();
1092                     glColor4f(0.1, 0.0, 0.0, 1);
1093                     bar = ((float)Person::players[0]->bloodloss) / Person::players[0]->damagetolerance;
1094                     glBegin(GL_QUADS);
1095                     glVertex3f(0, 0, 0.0f);
1096                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1097                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1098                     glVertex3f(0, 1, 0.0f);
1099                     glEnd();
1100                     glColor4f(0.4, 0.0, 0.0, 0.7);
1101                     bar = ((float)Person::players[0]->damage) / 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]->permanentdamage) / 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]->superpermanentdamage) / 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.0, 0.0, 0.0, 0.7);
1125                     glLineWidth(2.0);
1126                     glBegin(GL_LINE_STRIP);
1127                     glVertex3f(0, 0, 0.0f);
1128                     glVertex3f(1, 0, 0.0f);
1129                     glVertex3f(1, 1, 0.0f);
1130                     glVertex3f(0, 1, 0.0f);
1131                     glVertex3f(0, 0, 0.0f);
1132                     glEnd();
1133
1134                     glMatrixMode(GL_PROJECTION);
1135                     glPopMatrix();
1136                     glMatrixMode(GL_MODELVIEW);
1137                     glPopMatrix();
1138                     glEnable(GL_DEPTH_TEST);
1139                     glEnable(GL_CULL_FACE);
1140                     glDisable(GL_BLEND);
1141                     glDepthMask(1);
1142                     glEnable(GL_TEXTURE_2D);
1143
1144                     // writing the numbers :
1145                     sprintf (string, "Damages : %d/%d (%d)", (int)(Person::players[0]->damage), (int)(Person::players[0]->damagetolerance), (int)(Person::players[0]->bloodloss));
1146                     glColor4f(0, 0, 0, 1);
1147                     text->glPrintOutline(1024 / 40 - 4, 768 / 16 - 4 + 768 * 14 / 16 - 40, string, 1, 1.5 * 1.25, 1024, 768);
1148                     glColor4f(1, 0, 0, 1);
1149                     text->glPrint(1024 / 40, 768 / 16 + 768 * 14 / 16 - 40, string, 1, 1.5, 1024, 768);
1150                 }
1151             }
1152
1153             glColor4f(.5, .5, .5, 1);
1154
1155
1156             if ((texttoggle || editorenabled) && devtools && !mainmenu) {
1157                 sprintf (string, "The framespersecond is %d.", (int)(fps));
1158                 text->glPrint(10, 30, string, 0, .8, 1024, 768);
1159
1160                 if (editorenabled)
1161                     sprintf (string, "Map editor enabled.");
1162                 else
1163                     sprintf (string, "Map editor disabled.");
1164                 text->glPrint(10, 60, string, 0, .8, 1024, 768);
1165                 if (editorenabled) {
1166                     sprintf (string, "Object size: %f", editorsize);
1167                     text->glPrint(10, 75, string, 0, .8, 1024, 768);
1168                     if (editoryaw >= 0)
1169                         sprintf (string, "Object yaw: %f", editoryaw);
1170                     else
1171                         sprintf (string, "Object yaw: Random");
1172                     text->glPrint(10, 90, string, 0, .8, 1024, 768);
1173                     if (editorpitch >= 0)
1174                         sprintf (string, "Object pitch: %f", editorpitch);
1175                     else
1176                         sprintf (string, "Object pitch: Random");
1177                     text->glPrint(10, 105, string, 0, .8, 1024, 768);
1178                     sprintf (string, "Object type: %d", editortype);
1179                     text->glPrint(10, 120, string, 0, .8, 1024, 768);
1180                     switch (editortype) {
1181                     case boxtype:
1182                         sprintf (string, "(box)");
1183                         break;
1184                     case treetrunktype:
1185                         sprintf (string, "(tree)");
1186                         break;
1187                     case walltype:
1188                         sprintf (string, "(wall)");
1189                         break;
1190                     case weirdtype:
1191                         sprintf (string, "(weird)");
1192                         break;
1193                     case spiketype:
1194                         sprintf (string, "(spike)");
1195                         break;
1196                     case rocktype:
1197                         sprintf (string, "(rock)");
1198                         break;
1199                     case bushtype:
1200                         sprintf (string, "(bush)");
1201                         break;
1202                     case tunneltype:
1203                         sprintf (string, "(tunnel)");
1204                         break;
1205                     case chimneytype:
1206                         sprintf (string, "(chimney)");
1207                         break;
1208                     case platformtype:
1209                         sprintf (string, "(platform)");
1210                         break;
1211                     case cooltype:
1212                         sprintf (string, "(cool)");
1213                         break;
1214                     case firetype:
1215                         sprintf (string, "(fire)");
1216                         break;
1217                     }
1218                     text->glPrint(130, 120, string, 0, .8, 1024, 768);
1219
1220                     sprintf (string, "Numplayers: %lu", Person::players.size());
1221                     text->glPrint(10, 155, string, 0, .8, 1024, 768);
1222                     sprintf (string, "Player %d: numwaypoints: %d", (int(Person::players.size()) - 1), Person::players.back()->numwaypoints);
1223                     text->glPrint(10, 140, string, 0, .8, 1024, 768);
1224                 }
1225                 sprintf (string, "Difficulty: %d", difficulty);
1226                 text->glPrint(10, 240, string, 0, .8, 1024, 768);
1227
1228             }
1229         }
1230
1231         if (drawmode == glowmode) {
1232             glDisable(GL_DEPTH_TEST);
1233             glDisable(GL_CULL_FACE);
1234             glDisable(GL_LIGHTING);
1235             glDisable(GL_TEXTURE_2D);
1236             glDepthMask(0);
1237             glMatrixMode(GL_PROJECTION);
1238             glPushMatrix();
1239             glLoadIdentity();
1240             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1241             glMatrixMode(GL_MODELVIEW);
1242             glPushMatrix();
1243             glLoadIdentity();
1244             glScalef(screenwidth, screenheight, 1);
1245             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1246             glEnable(GL_BLEND);
1247             glColor4f(0, 0, 0, .5);
1248             glBegin(GL_QUADS);
1249             glVertex3f(0, 0,  0.0f);
1250             glVertex3f(256, 0, 0.0f);
1251             glVertex3f(256, 256, 0.0f);
1252             glVertex3f(0, 256, 0.0f);
1253             glEnd();
1254             glMatrixMode(GL_PROJECTION);
1255             glPopMatrix();
1256             glMatrixMode(GL_MODELVIEW);
1257             glPopMatrix();
1258             glEnable(GL_DEPTH_TEST);
1259             glEnable(GL_CULL_FACE);
1260             glDisable(GL_BLEND);
1261             glDepthMask(1);
1262         }
1263
1264         if ((((blackout && damageeffects) || (Person::players[0]->bloodloss > 0 && damageeffects && Person::players[0]->blooddimamount > 0) || Person::players[0]->dead) && !cameramode) || console) {
1265             glDisable(GL_DEPTH_TEST);
1266             glDisable(GL_CULL_FACE);
1267             glDisable(GL_LIGHTING);
1268             glDisable(GL_TEXTURE_2D);
1269             glDepthMask(0);
1270             glMatrixMode(GL_PROJECTION);
1271             glPushMatrix();
1272             glLoadIdentity();
1273             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1274             glMatrixMode(GL_MODELVIEW);
1275             glPushMatrix();
1276             glLoadIdentity();
1277             glScalef(screenwidth, screenheight, 1);
1278             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1279             glEnable(GL_BLEND);
1280             if (Person::players[0]->dead)
1281                 blackout += multiplier * 3;
1282             if (Person::players[0]->dead == 1)
1283                 blackout = .4f;
1284             if (Person::players[0]->dead == 2 && blackout > .6)
1285                 blackout = .6;
1286             glColor4f(0, 0, 0, blackout);
1287             if (!Person::players[0]->dead) {
1288                 if ((Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5))*.3 < .3) {
1289                     glColor4f(0, 0, 0, Person::players[0]->blooddimamount * Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5)*.3);
1290                     blackout = Person::players[0]->blooddimamount * Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5) * .3;
1291                 } else {
1292                     glColor4f(0, 0, 0, Person::players[0]->blooddimamount * .3);
1293                     blackout = Person::players[0]->blooddimamount * .3;
1294                 }
1295             }
1296             if (console)
1297                 glColor4f(.7, 0, 0, .2);
1298             glBegin(GL_QUADS);
1299             glVertex3f(0, 0,  0.0f);
1300             glVertex3f(256, 0,  0.0f);
1301             glVertex3f(256, 256, 0.0f);
1302             glVertex3f(0, 256, 0.0f);
1303             glEnd();
1304             glMatrixMode(GL_PROJECTION);
1305             glPopMatrix();
1306             glMatrixMode(GL_MODELVIEW);
1307             glPopMatrix();
1308             glEnable(GL_DEPTH_TEST);
1309             glEnable(GL_CULL_FACE);
1310             glDisable(GL_BLEND);
1311             glDepthMask(1);
1312         }
1313
1314         if (flashamount > 0 && damageeffects) {
1315             if (flashamount > 1)
1316                 flashamount = 1;
1317             if (flashdelay <= 0)
1318                 flashamount -= multiplier;
1319             flashdelay--;
1320             if (flashamount < 0)
1321                 flashamount = 0;
1322             glDisable(GL_DEPTH_TEST);
1323             glDisable(GL_CULL_FACE);
1324             glDisable(GL_LIGHTING);
1325             glDepthMask(0);
1326             glMatrixMode(GL_PROJECTION);
1327             glPushMatrix();
1328             glLoadIdentity();
1329             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1330             glMatrixMode(GL_MODELVIEW);
1331             glPushMatrix();
1332             glLoadIdentity();
1333             glScalef(screenwidth, screenheight, 1);
1334             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1335             glEnable(GL_BLEND);
1336             glColor4f(flashr, flashg, flashb, flashamount);
1337             glBegin(GL_QUADS);
1338             glVertex3f(0, 0,  0.0f);
1339             glVertex3f(256, 0, 0.0f);
1340             glVertex3f(256, 256, 0.0f);
1341             glVertex3f(0, 256, 0.0f);
1342             glEnd();
1343             glMatrixMode(GL_PROJECTION);
1344             glPopMatrix();
1345             glMatrixMode(GL_MODELVIEW);
1346             glPopMatrix();
1347             glEnable(GL_DEPTH_TEST);
1348             glEnable(GL_CULL_FACE);
1349             glDisable(GL_BLEND);
1350             glDepthMask(1);
1351         }
1352
1353         if (!console) {
1354             displaytime[0] = 0;
1355             glEnable(GL_TEXTURE_2D);
1356             glColor4f(1, 1, 1, 1);
1357             for (unsigned i = 1; i < 15; i++)
1358                 if (displaytime[i] < 4)
1359                     for (unsigned j = 0; j < displaytext[i].size(); j++) {
1360                         glColor4f(1, 1, 1, 4 - displaytime[i]);
1361                         sprintf (string, "%c", displaytext[i][j]);
1362                         text->glPrint(30 + j * 10, 30 + i * 20 + (screenheight - 330), string, 0, 1, screenwidth, screenheight);
1363                     }
1364         }
1365
1366         if (difficulty < 2 && !Dialog::inDialog()) { // minimap
1367             float mapviewdist = 20000;
1368
1369             glDisable(GL_DEPTH_TEST);
1370             glColor3f (1.0, 1.0, 1.0); // no coloring
1371
1372             glEnable(GL_TEXTURE_2D);
1373             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1374             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1375             glDisable(GL_DEPTH_TEST);
1376             glDisable(GL_CULL_FACE);
1377             glDisable(GL_LIGHTING);
1378             glDepthMask(0);
1379             glMatrixMode(GL_PROJECTION);
1380             glPushMatrix();
1381             glLoadIdentity();
1382             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1383             glMatrixMode(GL_MODELVIEW);
1384             glPushMatrix();
1385             glLoadIdentity();
1386             glScalef((float)screenwidth / 2, (float)screenwidth / 2, 1);
1387             glTranslatef(1.75, .25, 0);
1388             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1389             glEnable(GL_BLEND);
1390             glColor4f(1, 1, 1, 1);
1391             glPushMatrix();
1392             float opac = .7;
1393             XYZ center;
1394             float radius;
1395             float distcheck;
1396
1397             center = Person::players[0]->coords;
1398
1399             radius = 110;
1400
1401             glScalef(.25 / radius * 256 * terrain.scale * .4, .25 / radius * 256 * terrain.scale * .4, 1);
1402             glPushMatrix();
1403             glScalef(1 / (1 / radius * 256 * terrain.scale * .4), 1 / (1 / radius * 256 * terrain.scale * .4), 1);
1404             glPopMatrix();
1405             glRotatef(Person::players[0]->lookyaw * -1 + 180, 0, 0, 1);
1406             glTranslatef(-(center.x / terrain.scale / 256 * -2 + 1), (center.z / terrain.scale / 256 * -2 + 1), 0);
1407             for (int i = 0; i < objects.numobjects; i++) {
1408                 if (objects.type[i] == treetrunktype) {
1409                     distcheck = distsq(&Person::players[0]->coords, &objects.position[i]);
1410                     if (distcheck < mapviewdist) {
1411                         Mapcircletexture.bind();
1412                         glColor4f(0, .3, 0, opac * (1 - distcheck / mapviewdist));
1413                         glPushMatrix();
1414                         glTranslatef(objects.position[i].x / terrain.scale / 256 * -2 + 1, objects.position[i].z / terrain.scale / 256 * 2 - 1, 0);
1415                         glRotatef(objects.yaw[i], 0, 0, 1);
1416                         glScalef(.003, .003, .003);
1417                         glBegin(GL_QUADS);
1418                         glTexCoord2f(0, 0);
1419                         glVertex3f(-1, -1, 0.0f);
1420                         glTexCoord2f(1, 0);
1421                         glVertex3f(1, -1, 0.0f);
1422                         glTexCoord2f(1, 1);
1423                         glVertex3f(1, 1, 0.0f);
1424                         glTexCoord2f(0, 1);
1425                         glVertex3f(-1, 1, 0.0f);
1426                         glEnd();
1427                         glPopMatrix();
1428                     }
1429                 }
1430                 if (objects.type[i] == boxtype) {
1431                     distcheck = distsq(&Person::players[0]->coords, &objects.position[i]);
1432                     if (distcheck < mapviewdist) {
1433                         Mapboxtexture.bind();
1434                         glColor4f(.4, .4, .4, opac * (1 - distcheck / mapviewdist));
1435                         glPushMatrix();
1436                         glTranslatef(objects.position[i].x / terrain.scale / 256 * -2 + 1, objects.position[i].z / terrain.scale / 256 * 2 - 1, 0);
1437                         glRotatef(objects.yaw[i], 0, 0, 1);
1438                         glScalef(.01 * objects.scale[i], .01 * objects.scale[i], .01 * objects.scale[i]);
1439                         glBegin(GL_QUADS);
1440                         glTexCoord2f(0, 0);
1441                         glVertex3f(-1, -1, 0.0f);
1442                         glTexCoord2f(1, 0);
1443                         glVertex3f(1, -1, 0.0f);
1444                         glTexCoord2f(1, 1);
1445                         glVertex3f(1, 1, 0.0f);
1446                         glTexCoord2f(0, 1);
1447                         glVertex3f(-1, 1, 0.0f);
1448                         glEnd();
1449                         glPopMatrix();
1450                     }
1451                 }
1452             }
1453             if (editorenabled) {
1454                 Mapcircletexture.bind();
1455                 for (int i = 0; i < numboundaries; i++) {
1456                     glColor4f(0, 0, 0, opac / 3);
1457                     glPushMatrix();
1458                     glTranslatef(boundary[i].x / terrain.scale / 256 * -2 + 1, boundary[i].z / terrain.scale / 256 * 2 - 1, 0);
1459                     glScalef(.002, .002, .002);
1460                     glBegin(GL_QUADS);
1461                     glTexCoord2f(0, 0);
1462                     glVertex3f(-1, -1, 0.0f);
1463                     glTexCoord2f(1, 0);
1464                     glVertex3f(1, -1, 0.0f);
1465                     glTexCoord2f(1, 1);
1466                     glVertex3f(1, 1, 0.0f);
1467                     glTexCoord2f(0, 1);
1468                     glVertex3f(-1, 1, 0.0f);
1469                     glEnd();
1470                     glPopMatrix();
1471                 }
1472             }
1473             for (unsigned i = 0; i < Person::players.size(); i++) {
1474                 distcheck = distsq(&Person::players[0]->coords, &Person::players[i]->coords);
1475                 if (distcheck < mapviewdist) {
1476                     glPushMatrix();
1477                     Maparrowtexture.bind();
1478                     if (i == 0)
1479                         glColor4f(1, 1, 1, opac);
1480                     else if (Person::players[i]->dead == 2 || Person::players[i]->howactive > typesleeping)
1481                         glColor4f(0, 0, 0, opac * (1 - distcheck / mapviewdist));
1482                     else if (Person::players[i]->dead)
1483                         glColor4f(.3, .3, .3, opac * (1 - distcheck / mapviewdist));
1484                     else if (Person::players[i]->aitype == attacktypecutoff)
1485                         glColor4f(1, 0, 0, opac * (1 - distcheck / mapviewdist));
1486                     else if (Person::players[i]->aitype == passivetype)
1487                         glColor4f(0, 1, 0, opac * (1 - distcheck / mapviewdist));
1488                     else
1489                         glColor4f(1, 1, 0, 1);
1490                     glTranslatef(Person::players[i]->coords.x / terrain.scale / 256 * -2 + 1, Person::players[i]->coords.z / terrain.scale / 256 * 2 - 1, 0);
1491                     glRotatef(Person::players[i]->yaw + 180, 0, 0, 1);
1492                     glScalef(.005, .005, .005);
1493                     glBegin(GL_QUADS);
1494                     glTexCoord2f(0, 0);
1495                     glVertex3f(-1, -1, 0.0f);
1496                     glTexCoord2f(1, 0);
1497                     glVertex3f(1, -1, 0.0f);
1498                     glTexCoord2f(1, 1);
1499                     glVertex3f(1, 1, 0.0f);
1500                     glTexCoord2f(0, 1);
1501                     glVertex3f(-1, 1, 0.0f);
1502                     glEnd();
1503                     glPopMatrix();
1504                 }
1505             }
1506             glPopMatrix();
1507             glDisable(GL_TEXTURE_2D);
1508             glMatrixMode(GL_PROJECTION);
1509             glPopMatrix();
1510             glMatrixMode(GL_MODELVIEW);
1511             glPopMatrix();
1512             glEnable(GL_DEPTH_TEST);
1513             glEnable(GL_CULL_FACE);
1514             glDisable(GL_BLEND);
1515             glDepthMask(1);
1516         }
1517
1518         if (loading && !stealthloading && (!campaign || Person::players[0]->dead)) {
1519             glDisable(GL_DEPTH_TEST);
1520             glDisable(GL_CULL_FACE);
1521             glDisable(GL_LIGHTING);
1522             glDisable(GL_TEXTURE_2D);
1523             glDepthMask(0);
1524             glMatrixMode(GL_PROJECTION);
1525             glPushMatrix();
1526             glLoadIdentity();
1527             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1528             glMatrixMode(GL_MODELVIEW);
1529             glPushMatrix();
1530             glLoadIdentity();
1531             glScalef(screenwidth, screenheight, 1);
1532             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1533             glEnable(GL_BLEND);
1534             glColor4f(0, 0, 0, .7);
1535             glBegin(GL_QUADS);
1536             glVertex3f(0, 0, 0.0f);
1537             glVertex3f(256, 0, 0.0f);
1538             glVertex3f(256, 256, 0.0f);
1539             glVertex3f(0, 256, 0.0f);
1540             glEnd();
1541             glMatrixMode(GL_PROJECTION);
1542             glPopMatrix();
1543             glMatrixMode(GL_MODELVIEW);
1544             glPopMatrix();
1545             glEnable(GL_DEPTH_TEST);
1546             glEnable(GL_CULL_FACE);
1547             glDisable(GL_BLEND);
1548             glDepthMask(1);
1549
1550             //logo
1551             glDisable(GL_DEPTH_TEST);
1552             glColor3f (1.0, 1.0, 1.0); // no coloring
1553
1554             glEnable(GL_TEXTURE_2D);
1555
1556             //Minimap
1557
1558             if (loading != 4) {
1559                 glEnable(GL_TEXTURE_2D);
1560                 glColor4f(1, 1, 1, 1);
1561                 sprintf (string, "Loading...");
1562                 text->glPrint(1024 / 2 - 90, 768 / 2, string, 1, 2, 1024, 768);
1563             }
1564             loading = 2;
1565             drawmode = normalmode;
1566         }
1567
1568         if (winfreeze && !campaign) {
1569             glDisable(GL_DEPTH_TEST);
1570             glDisable(GL_CULL_FACE);
1571             glDisable(GL_LIGHTING);
1572             glDisable(GL_TEXTURE_2D);
1573             glDepthMask(0);
1574             glMatrixMode(GL_PROJECTION);
1575             glPushMatrix();
1576             glLoadIdentity();
1577             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1578             glMatrixMode(GL_MODELVIEW);
1579             glPushMatrix();
1580             glLoadIdentity();
1581             glScalef(screenwidth, screenheight, 1);
1582             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1583             glEnable(GL_BLEND);
1584             glColor4f(0, 0, 0, .4);
1585             glBegin(GL_QUADS);
1586             glVertex3f(0, 0, 0.0f);
1587             glVertex3f(256, 0, 0.0f);
1588             glVertex3f(256, 256, 0.0f);
1589             glVertex3f(0, 256, 0.0f);
1590             glEnd();
1591             glMatrixMode(GL_PROJECTION);
1592             glPopMatrix();
1593             glMatrixMode(GL_MODELVIEW);
1594             glPopMatrix();
1595             glEnable(GL_DEPTH_TEST);
1596             glEnable(GL_CULL_FACE);
1597             glDisable(GL_BLEND);
1598             glDepthMask(1);
1599
1600             //logo
1601             glDisable(GL_DEPTH_TEST);
1602             glColor3f (1.0, 1.0, 1.0); // no coloring
1603
1604             glEnable(GL_TEXTURE_2D);
1605
1606             //Win Screen Won Victory
1607
1608             glEnable(GL_TEXTURE_2D);
1609             glColor4f(1, 1, 1, 1);
1610             sprintf (string, "Level Cleared!");
1611             text->glPrintOutlined(1024 / 2 - strlen(string) * 10, 768 * 7 / 8, string, 1, 2, 1024, 768);
1612
1613             sprintf (string, "Score:     %d", (int)(bonustotal - startbonustotal));
1614             text->glPrintOutlined(1024 / 30, 768 * 6 / 8, string, 1, 2, 1024, 768);
1615
1616             sprintf (string, "Press Escape to return to menu or Space to continue");
1617             text->glPrintOutlined(640 / 2 - strlen(string) * 5, 480 * 1 / 16, string, 1, 1, 640, 480);
1618
1619             char temp[255];
1620
1621             for (int i = 0; i < 255; i++)
1622                 string[i] = '\0';
1623             int wontime = (int)round(wonleveltime);
1624             sprintf (temp, "Time:      %d:", int((wontime - wontime % 60) / 60));
1625             strcat(string, temp);
1626             if (wontime % 60 < 10)
1627                 strcat(string, "0");
1628             sprintf (temp, "%d", wontime % 60);
1629             strcat(string, temp);
1630             text->glPrintOutlined(1024 / 30, 768 * 6 / 8 - 40, string, 1, 2, 1024, 768);
1631
1632             //Awards
1633             int awards[award_count];
1634             int numawards = award_awards(awards);
1635
1636             for (int i = 0; i < numawards && i < 6; i++)
1637                 text->glPrintOutlined(1024 / 30, 768 * 6 / 8 - 90 - 40 * i, award_names[awards[i]], 1, 2, 1024, 768);
1638         }
1639
1640         if (drawmode != normalmode) {
1641             glEnable(GL_TEXTURE_2D);
1642             glFinish();
1643             if (!drawtoggle || drawmode != realmotionblurmode || (drawtoggle == 2 || change == 1)) {
1644                 if (screentexture) {
1645
1646                     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
1647                     GLfloat subtractColor[4] = { 0.5, 0.5, 0.5, 0.0 };
1648                     glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, subtractColor);
1649                     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
1650                     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_CONSTANT_EXT);
1651                     glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
1652
1653                     glBindTexture( GL_TEXTURE_2D, screentexture);
1654                     glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);
1655                 }
1656             }
1657             if ((drawtoggle || change == 1) && drawmode == realmotionblurmode) {
1658                 if (screentexture2) {
1659                     glBindTexture( GL_TEXTURE_2D, screentexture2);
1660                     glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);
1661                 }
1662                 if (!screentexture2) {
1663                     glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1664
1665                     glGenTextures( 1, &screentexture2 );
1666                     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1667
1668                     glEnable(GL_TEXTURE_2D);
1669                     glBindTexture( GL_TEXTURE_2D, screentexture2);
1670                     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1671                     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1672
1673                     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1674                 }
1675             }
1676         }
1677
1678         glClear(GL_DEPTH_BUFFER_BIT);
1679         Game::ReSizeGLScene(90, .1f);
1680         glViewport(0, 0, screenwidth, screenheight);
1681
1682         if (drawmode != normalmode) {
1683             glDisable(GL_DEPTH_TEST);
1684             if (drawmode == motionblurmode) {
1685                 glDrawBuffer(GL_FRONT);
1686                 glReadBuffer(GL_BACK);
1687             }
1688             glColor3f (1.0, 1.0, 1.0); // no coloring
1689
1690             glEnable(GL_TEXTURE_2D);
1691             glBindTexture( GL_TEXTURE_2D, screentexture);
1692             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1693             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1694             glDisable(GL_DEPTH_TEST);
1695             glDisable(GL_CULL_FACE);
1696             glDisable(GL_LIGHTING);
1697             glDepthMask(0);
1698             glMatrixMode(GL_PROJECTION);
1699             glPushMatrix();
1700             glLoadIdentity();
1701             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1702             glMatrixMode(GL_MODELVIEW);
1703             glPushMatrix();
1704             glLoadIdentity();
1705             glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
1706             glTranslatef(1, 1, 0);
1707             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1708             glEnable(GL_BLEND);
1709             if (drawmode == motionblurmode) {
1710                 if (motionbluramount < .2)
1711                     motionbluramount = .2;
1712                 glColor4f(1, 1, 1, motionbluramount);
1713                 glPushMatrix();
1714                 glBegin(GL_QUADS);
1715                 glTexCoord2f(0, 0);
1716                 glVertex3f(-1, -1, 0.0f);
1717                 glTexCoord2f(texcoordwidth, 0);
1718                 glVertex3f(1, -1, 0.0f);
1719                 glTexCoord2f(texcoordwidth, texcoordheight);
1720                 glVertex3f(1, 1, 0.0f);
1721                 glTexCoord2f(0, texcoordheight);
1722                 glVertex3f(-1, 1, 0.0f);
1723                 glEnd();
1724                 glPopMatrix();
1725             }
1726             if (drawmode == realmotionblurmode) {
1727                 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1728                 glClear(GL_COLOR_BUFFER_BIT);
1729                 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
1730                 glBindTexture( GL_TEXTURE_2D, screentexture);
1731                 glColor4f(1, 1, 1, .5);
1732                 glPushMatrix();
1733                 glBegin(GL_QUADS);
1734                 glTexCoord2f(0, 0);
1735                 glVertex3f(-1, -1, 0.0f);
1736                 glTexCoord2f(texcoordwidth, 0);
1737                 glVertex3f(1, -1, 0.0f);
1738                 glTexCoord2f(texcoordwidth, texcoordheight);
1739                 glVertex3f(1, 1, 0.0f);
1740                 glTexCoord2f(0, texcoordheight);
1741                 glVertex3f(-1, 1, 0.0f);
1742                 glEnd();
1743                 glPopMatrix();
1744                 glBindTexture( GL_TEXTURE_2D, screentexture2);
1745                 glColor4f(1, 1, 1, .5);
1746                 glPushMatrix();
1747                 glBegin(GL_QUADS);
1748                 glTexCoord2f(0, 0);
1749                 glVertex3f(-1, -1, 0.0f);
1750                 glTexCoord2f(texcoordwidth, 0);
1751                 glVertex3f(1, -1, 0.0f);
1752                 glTexCoord2f(texcoordwidth, texcoordheight);
1753                 glVertex3f(1, 1, 0.0f);
1754                 glTexCoord2f(0, texcoordheight);
1755                 glVertex3f(-1, 1, 0.0f);
1756                 glEnd();
1757                 glPopMatrix();
1758                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1759             }
1760             if (drawmode == doublevisionmode) {
1761                 static float crosseyedness;
1762                 crosseyedness = abs(Person::players[0]->damage - Person::players[0]->superpermanentdamage - (Person::players[0]->damagetolerance - Person::players[0]->superpermanentdamage) * 1 / 2) / 30;
1763                 if (crosseyedness > 1)
1764                     crosseyedness = 1;
1765                 if (crosseyedness < 0)
1766                     crosseyedness = 0;
1767                 glColor4f(1, 1, 1, 1);
1768                 glDisable(GL_BLEND);
1769                 glPushMatrix();
1770                 glScalef(1, 1, 1);
1771                 glBegin(GL_QUADS);
1772                 glTexCoord2f(0, 0);
1773                 glVertex3f(-1, -1, 0.0f);
1774                 glTexCoord2f(texcoordwidth, 0);
1775                 glVertex3f(1, -1, 0.0f);
1776                 glTexCoord2f(texcoordwidth, texcoordheight);
1777                 glVertex3f(1, 1, 0.0f);
1778                 glTexCoord2f(0, texcoordheight);
1779                 glVertex3f(-1, 1, 0.0f);
1780                 glEnd();
1781                 glPopMatrix();
1782                 if (crosseyedness) {
1783                     glColor4f(1, 1, 1, .5);
1784                     glEnable(GL_BLEND);
1785                     glPushMatrix();
1786                     glTranslatef(.015 * crosseyedness, 0, 0);
1787                     glScalef(1, 1, 1);
1788                     glBegin(GL_QUADS);
1789                     glTexCoord2f(0, 0);
1790                     glVertex3f(-1, -1, 0.0f);
1791                     glTexCoord2f(texcoordwidth, 0);
1792                     glVertex3f(1, -1, 0.0f);
1793                     glTexCoord2f(texcoordwidth, texcoordheight);
1794                     glVertex3f(1, 1, 0.0f);
1795                     glTexCoord2f(0, texcoordheight);
1796                     glVertex3f(-1, 1, 0.0f);
1797                     glEnd();
1798                     glPopMatrix();
1799                 }
1800             }
1801             if (drawmode == glowmode) {
1802                 glColor4f(.5, .5, .5, .5);
1803                 glEnable(GL_BLEND);
1804                 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
1805                 glPushMatrix();
1806                 glTranslatef(.01, 0, 0);
1807                 glBegin(GL_QUADS);
1808                 glTexCoord2f(0, 0);
1809                 glVertex3f(-1, -1, 0.0f);
1810                 glTexCoord2f(texcoordwidth, 0);
1811                 glVertex3f(1, -1, 0.0f);
1812                 glTexCoord2f(texcoordwidth, texcoordheight);
1813                 glVertex3f(1, 1, 0.0f);
1814                 glTexCoord2f(0, texcoordheight);
1815                 glVertex3f(-1, 1, 0.0f);
1816                 glEnd();
1817                 glPopMatrix();
1818                 glPushMatrix();
1819                 glTranslatef(-.01, 0, 0);
1820                 glBegin(GL_QUADS);
1821                 glTexCoord2f(0, 0);
1822                 glVertex3f(-1, -1, 0.0f);
1823                 glTexCoord2f(texcoordwidth, 0);
1824                 glVertex3f(1, -1, 0.0f);
1825                 glTexCoord2f(texcoordwidth, texcoordheight);
1826                 glVertex3f(1, 1, 0.0f);
1827                 glTexCoord2f(0, texcoordheight);
1828                 glVertex3f(-1, 1, 0.0f);
1829                 glEnd();
1830                 glPopMatrix();
1831                 glPushMatrix();
1832                 glTranslatef(.0, .01, 0);
1833                 glBegin(GL_QUADS);
1834                 glTexCoord2f(0, 0);
1835                 glVertex3f(-1, -1, 0.0f);
1836                 glTexCoord2f(texcoordwidth, 0);
1837                 glVertex3f(1, -1, 0.0f);
1838                 glTexCoord2f(texcoordwidth, texcoordheight);
1839                 glVertex3f(1, 1, 0.0f);
1840                 glTexCoord2f(0, texcoordheight);
1841                 glVertex3f(-1, 1, 0.0f);
1842                 glEnd();
1843                 glPopMatrix();
1844                 glPushMatrix();
1845                 glTranslatef(0, -.01, 0);
1846                 glBegin(GL_QUADS);
1847                 glTexCoord2f(0, 0);
1848                 glVertex3f(-1, -1, 0.0f);
1849                 glTexCoord2f(texcoordwidth, 0);
1850                 glVertex3f(1, -1, 0.0f);
1851                 glTexCoord2f(texcoordwidth, texcoordheight);
1852                 glVertex3f(1, 1, 0.0f);
1853                 glTexCoord2f(0, texcoordheight);
1854                 glVertex3f(-1, 1, 0.0f);
1855                 glEnd();
1856                 glPopMatrix();
1857             }
1858             if (drawmode == radialzoommode) {
1859                 for (int i = 0; i < 3; i++) {
1860                     glColor4f(1, 1, 1, 1 / ((float)i + 1));
1861                     glPushMatrix();
1862                     glScalef(1 + (float)i * .01, 1 + (float)i * .01, 1);
1863                     glBegin(GL_QUADS);
1864                     glTexCoord2f(0, 0);
1865                     glVertex3f(-1, -1, 0.0f);
1866                     glTexCoord2f(texcoordwidth, 0);
1867                     glVertex3f(1, -1, 0.0f);
1868                     glTexCoord2f(texcoordwidth, texcoordheight);
1869                     glVertex3f(1, 1, 0.0f);
1870                     glTexCoord2f(0, texcoordheight);
1871                     glVertex3f(-1, 1, 0.0f);
1872                     glEnd();
1873                     glPopMatrix();
1874                 }
1875             }
1876             glDisable(GL_TEXTURE_2D);
1877             glMatrixMode(GL_PROJECTION);
1878             glPopMatrix();
1879             glMatrixMode(GL_MODELVIEW);
1880             glPopMatrix();
1881             glEnable(GL_DEPTH_TEST);
1882             glEnable(GL_CULL_FACE);
1883             glDisable(GL_BLEND);
1884             glDepthMask(1);
1885         }
1886
1887         if (console) {
1888             glEnable(GL_TEXTURE_2D);
1889             glColor4f(1, 1, 1, 1);
1890             int offset = 0;
1891             if (consoleselected >= 60)
1892                 offset = consoleselected - 60;
1893             sprintf (string, " ]");
1894             text->glPrint(10, 30, string, 0, 1, 1024, 768);
1895             if (consoleblink) {
1896                 sprintf (string, "_");
1897                 text->glPrint(30 + (float)(consoleselected) * 10 - offset * 10, 30, string, 0, 1, 1024, 768);
1898             }
1899             for (unsigned i = 0; i < 15; i++)
1900                 for (unsigned j = 0; j < consoletext[i].size(); j++) {
1901                     glColor4f(1, 1, 1, 1 - (float)(i) / 16);
1902                     sprintf (string, "%c", consoletext[i][j]);
1903                     text->glPrint(30 + j * 10 - offset * 10, 30 + i * 20, string, 0, 1, 1024, 768);
1904                 }
1905         }
1906     }
1907
1908     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
1909         multiplier = tempmult;
1910     }
1911
1912     if (mainmenu) {
1913         DrawMenu();
1914     }
1915
1916     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
1917         tempmult = multiplier;
1918         multiplier = 0;
1919     }
1920
1921     if ( side == stereoRight || side == stereoCenter ) {
1922         if (drawmode != motionblurmode || mainmenu) {
1923             swap_gl_buffers();
1924         }
1925     }
1926
1927     glDrawBuffer(GL_BACK);
1928     glReadBuffer(GL_BACK);
1929
1930     weapons.DoStuff();
1931
1932     if (drawtoggle == 2)
1933         drawtoggle = 0;
1934
1935     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
1936         multiplier = tempmult;
1937     }
1938     //Jordan fixed your warning!
1939     return 0;
1940 }
1941
1942 void DrawMenu()
1943 {
1944     // !!! FIXME: hack: clamp framerate in menu so text input works correctly on fast systems.
1945     SDL_Delay(15);
1946
1947     glDrawBuffer(GL_BACK);
1948     glReadBuffer(GL_BACK);
1949     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1950     Game::ReSizeGLScene(90, .1f);
1951
1952     //draw menu background
1953     glClear(GL_DEPTH_BUFFER_BIT);
1954     glEnable(GL_ALPHA_TEST);
1955     glAlphaFunc(GL_GREATER, 0.001f);
1956     glEnable(GL_TEXTURE_2D);
1957     glDisable(GL_DEPTH_TEST);
1958     glDisable(GL_CULL_FACE);
1959     glDisable(GL_LIGHTING);
1960     glDepthMask(0);
1961     glMatrixMode(GL_PROJECTION);
1962     glPushMatrix();
1963     glLoadIdentity();
1964     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1965     glMatrixMode(GL_MODELVIEW);
1966     glPushMatrix();
1967     glLoadIdentity();
1968     glTranslatef(screenwidth / 2, screenheight / 2, 0);
1969     glPushMatrix();
1970     glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
1971     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1972     glDisable(GL_BLEND);
1973     glColor4f(0, 0, 0, 1.0);
1974     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1975     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1976     glDisable(GL_TEXTURE_2D);
1977     glBegin(GL_QUADS);
1978     glVertex3f(-1, -1, 0);
1979     glVertex3f(+1, -1, 0);
1980     glVertex3f(+1, +1, 0);
1981     glVertex3f(-1, +1, 0);
1982     glEnd();
1983     glEnable(GL_BLEND);
1984     glColor4f(0.4, 0.4, 0.4, 1.0);
1985     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1986     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1987     glEnable(GL_TEXTURE_2D);
1988     Game::Mainmenuitems[4].bind();
1989     glBegin(GL_QUADS);
1990     glTexCoord2f(0, 0);
1991     glVertex3f(-1, -1, 0);
1992     glTexCoord2f(1, 0);
1993     glVertex3f(+1, -1, 0);
1994     glTexCoord2f(1, 1);
1995     glVertex3f(+1, +1, 0);
1996     glTexCoord2f(0, 1);
1997     glVertex3f(-1, +1, 0);
1998     glEnd();
1999     glPopMatrix();
2000     glPopMatrix();
2001     glMatrixMode(GL_PROJECTION);
2002     glPopMatrix();
2003     glMatrixMode(GL_MODELVIEW);
2004
2005
2006
2007     glMatrixMode(GL_PROJECTION);
2008     glPushMatrix();
2009     glLoadIdentity();
2010     glOrtho(0, 640, 0, 480, -100, 100);
2011     glMatrixMode(GL_MODELVIEW);
2012     glPushMatrix();
2013     glLoadIdentity();
2014     glEnable(GL_TEXTURE_2D);
2015
2016     Menu::drawItems();
2017
2018     //draw mouse cursor
2019     glMatrixMode(GL_PROJECTION);
2020     glPopMatrix();
2021     glMatrixMode(GL_MODELVIEW);
2022     glPopMatrix();
2023
2024     glMatrixMode(GL_PROJECTION);
2025     glPushMatrix();
2026     glLoadIdentity();
2027     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
2028     glMatrixMode(GL_MODELVIEW);
2029     glPushMatrix();
2030     glLoadIdentity();
2031     glTranslatef(screenwidth / 2, screenheight / 2, 0);
2032     glPushMatrix();
2033     glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
2034     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2035     glEnable(GL_BLEND);
2036     glEnable(GL_TEXTURE_2D);
2037     glColor4f(1, 1, 1, 1);
2038     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2039     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2040     glPopMatrix();
2041     if (!Game::waiting) { // hide the cursor while waiting for a key
2042         glPushMatrix();
2043         glTranslatef(Game::mousecoordh - screenwidth / 2, Game::mousecoordv * -1 + screenheight / 2, 0);
2044         glScalef((float)screenwidth / 64, (float)screenwidth / 64, 1);
2045         glTranslatef(1, -1, 0);
2046         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2047         glColor4f(1, 1, 1, 1);
2048         Game::cursortexture.bind();
2049         glPushMatrix();
2050         glBegin(GL_QUADS);
2051         glTexCoord2f(0, 0);
2052         glVertex3f(-1, -1, 0.0f);
2053         glTexCoord2f(1, 0);
2054         glVertex3f(1, -1, 0.0f);
2055         glTexCoord2f(1, 1);
2056         glVertex3f(1, 1, 0.0f);
2057         glTexCoord2f(0, 1);
2058         glVertex3f(-1, 1, 0.0f);
2059         glEnd();
2060         glPopMatrix();
2061         glPopMatrix();
2062     }
2063     glPopMatrix();
2064     glMatrixMode(GL_PROJECTION);
2065     glPopMatrix();
2066
2067
2068     //draw screen flash
2069     if (flashamount > 0) {
2070         if (flashamount > 1)
2071             flashamount = 1;
2072         if (flashdelay <= 0)
2073             flashamount -= multiplier;
2074         flashdelay--;
2075         if (flashamount < 0)
2076             flashamount = 0;
2077         glDisable(GL_DEPTH_TEST);
2078         glDisable(GL_CULL_FACE);
2079         glDisable(GL_LIGHTING);
2080         glDisable(GL_TEXTURE_2D);
2081         glDepthMask(0);
2082         glMatrixMode(GL_PROJECTION);
2083         glPushMatrix();
2084         glLoadIdentity();
2085         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
2086         glMatrixMode(GL_MODELVIEW);
2087         glPushMatrix();
2088         glLoadIdentity();
2089         glScalef(screenwidth, screenheight, 1);
2090         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2091         glEnable(GL_BLEND);
2092         glColor4f(flashr, flashg, flashb, flashamount);
2093         glBegin(GL_QUADS);
2094         glVertex3f(0, 0, 0.0f);
2095         glVertex3f(256, 0, 0.0f);
2096         glVertex3f(256, 256, 0.0f);
2097         glVertex3f(0, 256, 0.0f);
2098         glEnd();
2099         glMatrixMode(GL_PROJECTION);
2100         glPopMatrix();
2101         glMatrixMode(GL_MODELVIEW);
2102         glPopMatrix();
2103         glEnable(GL_DEPTH_TEST);
2104         glEnable(GL_CULL_FACE);
2105         glDisable(GL_BLEND);
2106         glDepthMask(1);
2107     }
2108 }