]> git.jsancho.org Git - lugaru.git/blob - Source/GameDraw.cpp
Rename all C++ headers with .hpp extension
[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 (int 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 (int 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[abs(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[abs(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 (int 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                 if (Dialog::currentScene().location == 2)
989                     starty = screenheight * 1 / 5 - screenheight / 16;
990
991                 char tempname[264];
992                 int tempnum = 0;
993                 for (int i = 0; i < 264; i++) {
994                     tempname[i] = '\0';
995                 }
996
997                 for (int i = 0; i < Dialog::currentScene().name.size(); i++) {
998                     tempname[tempnum] = Dialog::currentScene().name[i];
999                     if (tempname[tempnum] == '#' || tempname[tempnum] == '\0')
1000                         tempname[tempnum] = '\0';
1001                     else
1002                         tempnum++;
1003                 }
1004
1005                 sprintf (string, "%s: ", tempname);
1006
1007                 if (Dialog::currentScene().color[0] + Dialog::currentScene().color[1] + Dialog::currentScene().color[2] < 1.5) {
1008                     glColor4f(0, 0, 0, tutorialopac);
1009                     text->glPrintOutline(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
1010                     glColor4f(0.7, 0.7, 0.7, tutorialopac);
1011                     text->glPrint(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024, starty, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
1012                 } else {
1013                     glColor4f(0, 0, 0, tutorialopac);
1014                     text->glPrintOutline(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
1015                 }
1016
1017                 tempnum = 0;
1018                 for (int i = 0; i < Dialog::currentScene().text.size() + 1; i++) {
1019                     tempname[tempnum] = Dialog::currentScene().text[i];
1020                     if (Dialog::currentScene().text[i] != '#')
1021                         tempnum++;
1022                 }
1023
1024                 sprintf (string, "%s", tempname);
1025
1026                 int lastline = 0;
1027                 int line = 0;
1028                 bool done = false;
1029                 int i = 0;
1030                 while (!done) {
1031                     if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') {
1032                         if (Dialog::currentScene().color[0] + Dialog::currentScene().color[1] + Dialog::currentScene().color[2] < 1.5) {
1033                             glColor4f(0, 0, 0, tutorialopac);
1034                             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);
1035                             glColor4f(1, 1, 1, tutorialopac);
1036                             text->glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
1037                         } else {
1038                             glColor4f(0, 0, 0, tutorialopac);
1039                             text->glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
1040                         }
1041                         lastline = i + 1;
1042                         line++;
1043                         if (string[i] == '\0')
1044                             done = 1;
1045                     }
1046                     if (i >= 255)
1047                         done = 1;
1048                     i++;
1049                 }
1050             }
1051
1052             if (!tutoriallevel && !winfreeze && !Dialog::inDialog() && !mainmenu) {
1053                 if (campaign) {
1054                     if (scoreadded)
1055                         sprintf (string, "Score: %d", (int)Account::active().getCampaignScore());
1056                     else
1057                         sprintf (string, "Score: %d", (int)Account::active().getCampaignScore() + (int)bonustotal);
1058                 }
1059                 if (!campaign)
1060                     sprintf (string, "Score: %d", (int)bonustotal);
1061                 glColor4f(0, 0, 0, 1);
1062                 text->glPrintOutline(1024 / 40 - 4, 768 / 16 - 4 + 768 * 14 / 16, string, 1, 1.5 * 1.25, 1024, 768);
1063                 glColor4f(1, 0, 0, 1);
1064                 text->glPrint(1024 / 40, 768 / 16 + 768 * 14 / 16, string, 1, 1.5, 1024, 768);
1065                 if (showdamagebar) {
1066                     glDisable(GL_DEPTH_TEST);
1067                     glDisable(GL_CULL_FACE);
1068                     glDisable(GL_LIGHTING);
1069                     glDisable(GL_TEXTURE_2D);
1070                     glDepthMask(0);
1071                     glMatrixMode(GL_PROJECTION);
1072                     glPushMatrix();
1073                     glLoadIdentity();
1074                     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1075                     glMatrixMode(GL_MODELVIEW);
1076                     glPushMatrix();
1077                     glLoadIdentity();
1078                     glTranslatef(15, screenheight * 17.5 / 20, 0);
1079                     glScalef(screenwidth / 3 + 20, screenheight / 20, 1);
1080                     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1081                     glEnable(GL_BLEND);
1082                     glColor4f(0.0, 0.4, 0.0, 0.7);
1083                     float bar = ((float)Person::players[0]->damage) / Person::players[0]->damagetolerance;
1084                     glBegin(GL_QUADS);
1085                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1086                     glVertex3f(1, 0, 0.0f);
1087                     glVertex3f(1, 1, 0.0f);
1088                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1089                     glEnd();
1090                     glColor4f(0.1, 0.0, 0.0, 1);
1091                     bar = ((float)Person::players[0]->bloodloss) / Person::players[0]->damagetolerance;
1092                     glBegin(GL_QUADS);
1093                     glVertex3f(0, 0, 0.0f);
1094                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1095                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1096                     glVertex3f(0, 1, 0.0f);
1097                     glEnd();
1098                     glColor4f(0.4, 0.0, 0.0, 0.7);
1099                     bar = ((float)Person::players[0]->damage) / Person::players[0]->damagetolerance;
1100                     glBegin(GL_QUADS);
1101                     glVertex3f(0, 0, 0.0f);
1102                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1103                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1104                     glVertex3f(0, 1, 0.0f);
1105                     glEnd();
1106                     glColor4f(0.4, 0.0, 0.0, 0.7);
1107                     bar = ((float)Person::players[0]->permanentdamage) / Person::players[0]->damagetolerance;
1108                     glBegin(GL_QUADS);
1109                     glVertex3f(0, 0, 0.0f);
1110                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1111                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1112                     glVertex3f(0, 1, 0.0f);
1113                     glEnd();
1114                     glColor4f(0.4, 0.0, 0.0, 0.7);
1115                     bar = ((float)Person::players[0]->superpermanentdamage) / Person::players[0]->damagetolerance;
1116                     glBegin(GL_QUADS);
1117                     glVertex3f(0, 0, 0.0f);
1118                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1119                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1120                     glVertex3f(0, 1, 0.0f);
1121                     glEnd();
1122                     glColor4f(0.0, 0.0, 0.0, 0.7);
1123                     glLineWidth(2.0);
1124                     glBegin(GL_LINE_STRIP);
1125                     glVertex3f(0, 0, 0.0f);
1126                     glVertex3f(1, 0, 0.0f);
1127                     glVertex3f(1, 1, 0.0f);
1128                     glVertex3f(0, 1, 0.0f);
1129                     glVertex3f(0, 0, 0.0f);
1130                     glEnd();
1131
1132                     glMatrixMode(GL_PROJECTION);
1133                     glPopMatrix();
1134                     glMatrixMode(GL_MODELVIEW);
1135                     glPopMatrix();
1136                     glEnable(GL_DEPTH_TEST);
1137                     glEnable(GL_CULL_FACE);
1138                     glDisable(GL_BLEND);
1139                     glDepthMask(1);
1140                     glEnable(GL_TEXTURE_2D);
1141
1142                     // writing the numbers :
1143                     sprintf (string, "Damages : %d/%d (%d)", (int)(Person::players[0]->damage), (int)(Person::players[0]->damagetolerance), (int)(Person::players[0]->bloodloss));
1144                     glColor4f(0, 0, 0, 1);
1145                     text->glPrintOutline(1024 / 40 - 4, 768 / 16 - 4 + 768 * 14 / 16 - 40, string, 1, 1.5 * 1.25, 1024, 768);
1146                     glColor4f(1, 0, 0, 1);
1147                     text->glPrint(1024 / 40, 768 / 16 + 768 * 14 / 16 - 40, string, 1, 1.5, 1024, 768);
1148                 }
1149             }
1150
1151             glColor4f(.5, .5, .5, 1);
1152
1153
1154             if ((texttoggle || editorenabled) && devtools && !mainmenu) {
1155                 sprintf (string, "The framespersecond is %d.", (int)(fps));
1156                 text->glPrint(10, 30, string, 0, .8, 1024, 768);
1157
1158                 if (editorenabled)
1159                     sprintf (string, "Map editor enabled.");
1160                 else
1161                     sprintf (string, "Map editor disabled.");
1162                 text->glPrint(10, 60, string, 0, .8, 1024, 768);
1163                 if (editorenabled) {
1164                     sprintf (string, "Object size: %f", editorsize);
1165                     text->glPrint(10, 75, string, 0, .8, 1024, 768);
1166                     if (editoryaw >= 0)
1167                         sprintf (string, "Object yaw: %f", editoryaw);
1168                     else
1169                         sprintf (string, "Object yaw: Random");
1170                     text->glPrint(10, 90, string, 0, .8, 1024, 768);
1171                     if (editorpitch >= 0)
1172                         sprintf (string, "Object pitch: %f", editorpitch);
1173                     else
1174                         sprintf (string, "Object pitch: Random");
1175                     text->glPrint(10, 105, string, 0, .8, 1024, 768);
1176                     sprintf (string, "Object type: %d", editortype);
1177                     text->glPrint(10, 120, string, 0, .8, 1024, 768);
1178                     switch (editortype) {
1179                     case boxtype:
1180                         sprintf (string, "(box)");
1181                         break;
1182                     case treetrunktype:
1183                         sprintf (string, "(tree)");
1184                         break;
1185                     case walltype:
1186                         sprintf (string, "(wall)");
1187                         break;
1188                     case weirdtype:
1189                         sprintf (string, "(weird)");
1190                         break;
1191                     case spiketype:
1192                         sprintf (string, "(spike)");
1193                         break;
1194                     case rocktype:
1195                         sprintf (string, "(rock)");
1196                         break;
1197                     case bushtype:
1198                         sprintf (string, "(bush)");
1199                         break;
1200                     case tunneltype:
1201                         sprintf (string, "(tunnel)");
1202                         break;
1203                     case chimneytype:
1204                         sprintf (string, "(chimney)");
1205                         break;
1206                     case platformtype:
1207                         sprintf (string, "(platform)");
1208                         break;
1209                     case cooltype:
1210                         sprintf (string, "(cool)");
1211                         break;
1212                     case firetype:
1213                         sprintf (string, "(fire)");
1214                         break;
1215                     }
1216                     text->glPrint(130, 120, string, 0, .8, 1024, 768);
1217
1218                     sprintf (string, "Numplayers: %lu", Person::players.size());
1219                     text->glPrint(10, 155, string, 0, .8, 1024, 768);
1220                     sprintf (string, "Player %d: numwaypoints: %d", (int(Person::players.size()) - 1), Person::players.back()->numwaypoints);
1221                     text->glPrint(10, 140, string, 0, .8, 1024, 768);
1222                 }
1223                 sprintf (string, "Difficulty: %d", difficulty);
1224                 text->glPrint(10, 240, string, 0, .8, 1024, 768);
1225
1226             }
1227         }
1228
1229         if (drawmode == glowmode) {
1230             glDisable(GL_DEPTH_TEST);
1231             glDisable(GL_CULL_FACE);
1232             glDisable(GL_LIGHTING);
1233             glDisable(GL_TEXTURE_2D);
1234             glDepthMask(0);
1235             glMatrixMode(GL_PROJECTION);
1236             glPushMatrix();
1237             glLoadIdentity();
1238             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1239             glMatrixMode(GL_MODELVIEW);
1240             glPushMatrix();
1241             glLoadIdentity();
1242             glScalef(screenwidth, screenheight, 1);
1243             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1244             glEnable(GL_BLEND);
1245             glColor4f(0, 0, 0, .5);
1246             glBegin(GL_QUADS);
1247             glVertex3f(0, 0,  0.0f);
1248             glVertex3f(256, 0, 0.0f);
1249             glVertex3f(256, 256, 0.0f);
1250             glVertex3f(0, 256, 0.0f);
1251             glEnd();
1252             glMatrixMode(GL_PROJECTION);
1253             glPopMatrix();
1254             glMatrixMode(GL_MODELVIEW);
1255             glPopMatrix();
1256             glEnable(GL_DEPTH_TEST);
1257             glEnable(GL_CULL_FACE);
1258             glDisable(GL_BLEND);
1259             glDepthMask(1);
1260         }
1261
1262         if ((((blackout && damageeffects) || (Person::players[0]->bloodloss > 0 && damageeffects && Person::players[0]->blooddimamount > 0) || Person::players[0]->dead) && !cameramode) || console) {
1263             glDisable(GL_DEPTH_TEST);
1264             glDisable(GL_CULL_FACE);
1265             glDisable(GL_LIGHTING);
1266             glDisable(GL_TEXTURE_2D);
1267             glDepthMask(0);
1268             glMatrixMode(GL_PROJECTION);
1269             glPushMatrix();
1270             glLoadIdentity();
1271             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1272             glMatrixMode(GL_MODELVIEW);
1273             glPushMatrix();
1274             glLoadIdentity();
1275             glScalef(screenwidth, screenheight, 1);
1276             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1277             glEnable(GL_BLEND);
1278             if (Person::players[0]->dead)
1279                 blackout += multiplier * 3;
1280             if (Person::players[0]->dead == 1)
1281                 blackout = .4f;
1282             if (Person::players[0]->dead == 2 && blackout > .6)
1283                 blackout = .6;
1284             glColor4f(0, 0, 0, blackout);
1285             if (!Person::players[0]->dead) {
1286                 if ((Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5))*.3 < .3) {
1287                     glColor4f(0, 0, 0, Person::players[0]->blooddimamount * Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5)*.3);
1288                     blackout = Person::players[0]->blooddimamount * Person::players[0]->bloodloss / Person::players[0]->damagetolerance * (sin(woozy) / 4 + .5) * .3;
1289                 } else {
1290                     glColor4f(0, 0, 0, Person::players[0]->blooddimamount * .3);
1291                     blackout = Person::players[0]->blooddimamount * .3;
1292                 }
1293             }
1294             if (console)
1295                 glColor4f(.7, 0, 0, .2);
1296             glBegin(GL_QUADS);
1297             glVertex3f(0, 0,  0.0f);
1298             glVertex3f(256, 0,  0.0f);
1299             glVertex3f(256, 256, 0.0f);
1300             glVertex3f(0, 256, 0.0f);
1301             glEnd();
1302             glMatrixMode(GL_PROJECTION);
1303             glPopMatrix();
1304             glMatrixMode(GL_MODELVIEW);
1305             glPopMatrix();
1306             glEnable(GL_DEPTH_TEST);
1307             glEnable(GL_CULL_FACE);
1308             glDisable(GL_BLEND);
1309             glDepthMask(1);
1310         }
1311
1312         if (flashamount > 0 && damageeffects) {
1313             if (flashamount > 1)
1314                 flashamount = 1;
1315             if (flashdelay <= 0)
1316                 flashamount -= multiplier;
1317             flashdelay--;
1318             if (flashamount < 0)
1319                 flashamount = 0;
1320             glDisable(GL_DEPTH_TEST);
1321             glDisable(GL_CULL_FACE);
1322             glDisable(GL_LIGHTING);
1323             glDepthMask(0);
1324             glMatrixMode(GL_PROJECTION);
1325             glPushMatrix();
1326             glLoadIdentity();
1327             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1328             glMatrixMode(GL_MODELVIEW);
1329             glPushMatrix();
1330             glLoadIdentity();
1331             glScalef(screenwidth, screenheight, 1);
1332             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1333             glEnable(GL_BLEND);
1334             glColor4f(flashr, flashg, flashb, flashamount);
1335             glBegin(GL_QUADS);
1336             glVertex3f(0, 0,  0.0f);
1337             glVertex3f(256, 0, 0.0f);
1338             glVertex3f(256, 256, 0.0f);
1339             glVertex3f(0, 256, 0.0f);
1340             glEnd();
1341             glMatrixMode(GL_PROJECTION);
1342             glPopMatrix();
1343             glMatrixMode(GL_MODELVIEW);
1344             glPopMatrix();
1345             glEnable(GL_DEPTH_TEST);
1346             glEnable(GL_CULL_FACE);
1347             glDisable(GL_BLEND);
1348             glDepthMask(1);
1349         }
1350
1351         if (!console) {
1352             displaytime[0] = 0;
1353             glEnable(GL_TEXTURE_2D);
1354             glColor4f(1, 1, 1, 1);
1355             for (unsigned i = 1; i < 15; i++)
1356                 if (displaytime[i] < 4)
1357                     for (unsigned j = 0; j < displaytext[i].size(); j++) {
1358                         glColor4f(1, 1, 1, 4 - displaytime[i]);
1359                         sprintf (string, "%c", displaytext[i][j]);
1360                         text->glPrint(30 + j * 10, 30 + i * 20 + (screenheight - 330), string, 0, 1, screenwidth, screenheight);
1361                     }
1362         }
1363
1364         if (difficulty < 2 && !Dialog::inDialog()) { // minimap
1365             float mapviewdist = 20000;
1366
1367             glDisable(GL_DEPTH_TEST);
1368             glColor3f (1.0, 1.0, 1.0); // no coloring
1369
1370             glEnable(GL_TEXTURE_2D);
1371             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1372             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1373             glDisable(GL_DEPTH_TEST);
1374             glDisable(GL_CULL_FACE);
1375             glDisable(GL_LIGHTING);
1376             glDepthMask(0);
1377             glMatrixMode(GL_PROJECTION);
1378             glPushMatrix();
1379             glLoadIdentity();
1380             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1381             glMatrixMode(GL_MODELVIEW);
1382             glPushMatrix();
1383             glLoadIdentity();
1384             glScalef((float)screenwidth / 2, (float)screenwidth / 2, 1);
1385             glTranslatef(1.75, .25, 0);
1386             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1387             glEnable(GL_BLEND);
1388             glColor4f(1, 1, 1, 1);
1389             glPushMatrix();
1390             float opac = .7;
1391             XYZ center;
1392             float radius;
1393             float distcheck;
1394
1395             center = Person::players[0]->coords;
1396
1397             radius = 110;
1398
1399             glScalef(.25 / radius * 256 * terrain.scale * .4, .25 / radius * 256 * terrain.scale * .4, 1);
1400             glPushMatrix();
1401             glScalef(1 / (1 / radius * 256 * terrain.scale * .4), 1 / (1 / radius * 256 * terrain.scale * .4), 1);
1402             glPopMatrix();
1403             glRotatef(Person::players[0]->lookyaw * -1 + 180, 0, 0, 1);
1404             glTranslatef(-(center.x / terrain.scale / 256 * -2 + 1), (center.z / terrain.scale / 256 * -2 + 1), 0);
1405             for (int i = 0; i < objects.numobjects; i++) {
1406                 if (objects.type[i] == treetrunktype) {
1407                     distcheck = distsq(&Person::players[0]->coords, &objects.position[i]);
1408                     if (distcheck < mapviewdist) {
1409                         Mapcircletexture.bind();
1410                         glColor4f(0, .3, 0, opac * (1 - distcheck / mapviewdist));
1411                         glPushMatrix();
1412                         glTranslatef(objects.position[i].x / terrain.scale / 256 * -2 + 1, objects.position[i].z / terrain.scale / 256 * 2 - 1, 0);
1413                         glRotatef(objects.yaw[i], 0, 0, 1);
1414                         glScalef(.003, .003, .003);
1415                         glBegin(GL_QUADS);
1416                         glTexCoord2f(0, 0);
1417                         glVertex3f(-1, -1, 0.0f);
1418                         glTexCoord2f(1, 0);
1419                         glVertex3f(1, -1, 0.0f);
1420                         glTexCoord2f(1, 1);
1421                         glVertex3f(1, 1, 0.0f);
1422                         glTexCoord2f(0, 1);
1423                         glVertex3f(-1, 1, 0.0f);
1424                         glEnd();
1425                         glPopMatrix();
1426                     }
1427                 }
1428                 if (objects.type[i] == boxtype) {
1429                     distcheck = distsq(&Person::players[0]->coords, &objects.position[i]);
1430                     if (distcheck < mapviewdist) {
1431                         Mapboxtexture.bind();
1432                         glColor4f(.4, .4, .4, opac * (1 - distcheck / mapviewdist));
1433                         glPushMatrix();
1434                         glTranslatef(objects.position[i].x / terrain.scale / 256 * -2 + 1, objects.position[i].z / terrain.scale / 256 * 2 - 1, 0);
1435                         glRotatef(objects.yaw[i], 0, 0, 1);
1436                         glScalef(.01 * objects.scale[i], .01 * objects.scale[i], .01 * objects.scale[i]);
1437                         glBegin(GL_QUADS);
1438                         glTexCoord2f(0, 0);
1439                         glVertex3f(-1, -1, 0.0f);
1440                         glTexCoord2f(1, 0);
1441                         glVertex3f(1, -1, 0.0f);
1442                         glTexCoord2f(1, 1);
1443                         glVertex3f(1, 1, 0.0f);
1444                         glTexCoord2f(0, 1);
1445                         glVertex3f(-1, 1, 0.0f);
1446                         glEnd();
1447                         glPopMatrix();
1448                     }
1449                 }
1450             }
1451             if (editorenabled) {
1452                 Mapcircletexture.bind();
1453                 for (int i = 0; i < numboundaries; i++) {
1454                     glColor4f(0, 0, 0, opac / 3);
1455                     glPushMatrix();
1456                     glTranslatef(boundary[i].x / terrain.scale / 256 * -2 + 1, boundary[i].z / terrain.scale / 256 * 2 - 1, 0);
1457                     glScalef(.002, .002, .002);
1458                     glBegin(GL_QUADS);
1459                     glTexCoord2f(0, 0);
1460                     glVertex3f(-1, -1, 0.0f);
1461                     glTexCoord2f(1, 0);
1462                     glVertex3f(1, -1, 0.0f);
1463                     glTexCoord2f(1, 1);
1464                     glVertex3f(1, 1, 0.0f);
1465                     glTexCoord2f(0, 1);
1466                     glVertex3f(-1, 1, 0.0f);
1467                     glEnd();
1468                     glPopMatrix();
1469                 }
1470             }
1471             for (unsigned i = 0; i < Person::players.size(); i++) {
1472                 distcheck = distsq(&Person::players[0]->coords, &Person::players[i]->coords);
1473                 if (distcheck < mapviewdist) {
1474                     glPushMatrix();
1475                     Maparrowtexture.bind();
1476                     if (i == 0)
1477                         glColor4f(1, 1, 1, opac);
1478                     else if (Person::players[i]->dead == 2 || Person::players[i]->howactive > typesleeping)
1479                         glColor4f(0, 0, 0, opac * (1 - distcheck / mapviewdist));
1480                     else if (Person::players[i]->dead)
1481                         glColor4f(.3, .3, .3, opac * (1 - distcheck / mapviewdist));
1482                     else if (Person::players[i]->aitype == attacktypecutoff)
1483                         glColor4f(1, 0, 0, opac * (1 - distcheck / mapviewdist));
1484                     else if (Person::players[i]->aitype == passivetype)
1485                         glColor4f(0, 1, 0, opac * (1 - distcheck / mapviewdist));
1486                     else
1487                         glColor4f(1, 1, 0, 1);
1488                     glTranslatef(Person::players[i]->coords.x / terrain.scale / 256 * -2 + 1, Person::players[i]->coords.z / terrain.scale / 256 * 2 - 1, 0);
1489                     glRotatef(Person::players[i]->yaw + 180, 0, 0, 1);
1490                     glScalef(.005, .005, .005);
1491                     glBegin(GL_QUADS);
1492                     glTexCoord2f(0, 0);
1493                     glVertex3f(-1, -1, 0.0f);
1494                     glTexCoord2f(1, 0);
1495                     glVertex3f(1, -1, 0.0f);
1496                     glTexCoord2f(1, 1);
1497                     glVertex3f(1, 1, 0.0f);
1498                     glTexCoord2f(0, 1);
1499                     glVertex3f(-1, 1, 0.0f);
1500                     glEnd();
1501                     glPopMatrix();
1502                 }
1503             }
1504             glPopMatrix();
1505             glDisable(GL_TEXTURE_2D);
1506             glMatrixMode(GL_PROJECTION);
1507             glPopMatrix();
1508             glMatrixMode(GL_MODELVIEW);
1509             glPopMatrix();
1510             glEnable(GL_DEPTH_TEST);
1511             glEnable(GL_CULL_FACE);
1512             glDisable(GL_BLEND);
1513             glDepthMask(1);
1514         }
1515
1516         if (loading && !stealthloading && (!campaign || Person::players[0]->dead)) {
1517             glDisable(GL_DEPTH_TEST);
1518             glDisable(GL_CULL_FACE);
1519             glDisable(GL_LIGHTING);
1520             glDisable(GL_TEXTURE_2D);
1521             glDepthMask(0);
1522             glMatrixMode(GL_PROJECTION);
1523             glPushMatrix();
1524             glLoadIdentity();
1525             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1526             glMatrixMode(GL_MODELVIEW);
1527             glPushMatrix();
1528             glLoadIdentity();
1529             glScalef(screenwidth, screenheight, 1);
1530             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1531             glEnable(GL_BLEND);
1532             glColor4f(0, 0, 0, .7);
1533             glBegin(GL_QUADS);
1534             glVertex3f(0, 0, 0.0f);
1535             glVertex3f(256, 0, 0.0f);
1536             glVertex3f(256, 256, 0.0f);
1537             glVertex3f(0, 256, 0.0f);
1538             glEnd();
1539             glMatrixMode(GL_PROJECTION);
1540             glPopMatrix();
1541             glMatrixMode(GL_MODELVIEW);
1542             glPopMatrix();
1543             glEnable(GL_DEPTH_TEST);
1544             glEnable(GL_CULL_FACE);
1545             glDisable(GL_BLEND);
1546             glDepthMask(1);
1547
1548             //logo
1549             glDisable(GL_DEPTH_TEST);
1550             glColor3f (1.0, 1.0, 1.0); // no coloring
1551
1552             glEnable(GL_TEXTURE_2D);
1553
1554             //Minimap
1555
1556             if (loading != 4) {
1557                 glEnable(GL_TEXTURE_2D);
1558                 glColor4f(1, 1, 1, 1);
1559                 sprintf (string, "Loading...");
1560                 text->glPrint(1024 / 2 - 90, 768 / 2, string, 1, 2, 1024, 768);
1561             }
1562             loading = 2;
1563             drawmode = normalmode;
1564         }
1565
1566         if (winfreeze && !campaign) {
1567             glDisable(GL_DEPTH_TEST);
1568             glDisable(GL_CULL_FACE);
1569             glDisable(GL_LIGHTING);
1570             glDisable(GL_TEXTURE_2D);
1571             glDepthMask(0);
1572             glMatrixMode(GL_PROJECTION);
1573             glPushMatrix();
1574             glLoadIdentity();
1575             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1576             glMatrixMode(GL_MODELVIEW);
1577             glPushMatrix();
1578             glLoadIdentity();
1579             glScalef(screenwidth, screenheight, 1);
1580             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1581             glEnable(GL_BLEND);
1582             glColor4f(0, 0, 0, .4);
1583             glBegin(GL_QUADS);
1584             glVertex3f(0, 0, 0.0f);
1585             glVertex3f(256, 0, 0.0f);
1586             glVertex3f(256, 256, 0.0f);
1587             glVertex3f(0, 256, 0.0f);
1588             glEnd();
1589             glMatrixMode(GL_PROJECTION);
1590             glPopMatrix();
1591             glMatrixMode(GL_MODELVIEW);
1592             glPopMatrix();
1593             glEnable(GL_DEPTH_TEST);
1594             glEnable(GL_CULL_FACE);
1595             glDisable(GL_BLEND);
1596             glDepthMask(1);
1597
1598             //logo
1599             glDisable(GL_DEPTH_TEST);
1600             glColor3f (1.0, 1.0, 1.0); // no coloring
1601
1602             glEnable(GL_TEXTURE_2D);
1603
1604             //Win Screen Won Victory
1605
1606             glEnable(GL_TEXTURE_2D);
1607             glColor4f(1, 1, 1, 1);
1608             sprintf (string, "Level Cleared!");
1609             text->glPrintOutlined(1024 / 2 - strlen(string) * 10, 768 * 7 / 8, string, 1, 2, 1024, 768);
1610
1611             sprintf (string, "Score:     %d", (int)(bonustotal - startbonustotal));
1612             text->glPrintOutlined(1024 / 30, 768 * 6 / 8, string, 1, 2, 1024, 768);
1613
1614             sprintf (string, "Press Escape to return to menu or Space to continue");
1615             text->glPrintOutlined(640 / 2 - strlen(string) * 5, 480 * 1 / 16, string, 1, 1, 640, 480);
1616
1617             char temp[255];
1618
1619             for (int i = 0; i < 255; i++)
1620                 string[i] = '\0';
1621             int wontime = (int)round(wonleveltime);
1622             sprintf (temp, "Time:      %d:", int((wontime - wontime % 60) / 60));
1623             strcat(string, temp);
1624             if (wontime % 60 < 10)
1625                 strcat(string, "0");
1626             sprintf (temp, "%d", wontime % 60);
1627             strcat(string, temp);
1628             text->glPrintOutlined(1024 / 30, 768 * 6 / 8 - 40, string, 1, 2, 1024, 768);
1629
1630             //Awards
1631             int awards[award_count];
1632             int numawards = award_awards(awards);
1633
1634             for (int i = 0; i < numawards && i < 6; i++)
1635                 text->glPrintOutlined(1024 / 30, 768 * 6 / 8 - 90 - 40 * i, award_names[awards[i]], 1, 2, 1024, 768);
1636         }
1637
1638         if (drawmode != normalmode) {
1639             glEnable(GL_TEXTURE_2D);
1640             glFinish();
1641             if (!drawtoggle || drawmode != realmotionblurmode || (drawtoggle == 2 || change == 1)) {
1642                 if (screentexture) {
1643
1644                     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
1645                     GLfloat subtractColor[4] = { 0.5, 0.5, 0.5, 0.0 };
1646                     glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, subtractColor);
1647                     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
1648                     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_CONSTANT_EXT);
1649                     glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
1650
1651                     glBindTexture( GL_TEXTURE_2D, screentexture);
1652                     glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);
1653                 }
1654             }
1655             if ((drawtoggle || change == 1) && drawmode == realmotionblurmode) {
1656                 if (screentexture2) {
1657                     glBindTexture( GL_TEXTURE_2D, screentexture2);
1658                     glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);
1659                 }
1660                 if (!screentexture2) {
1661                     glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1662
1663                     glGenTextures( 1, &screentexture2 );
1664                     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1665
1666                     glEnable(GL_TEXTURE_2D);
1667                     glBindTexture( GL_TEXTURE_2D, screentexture2);
1668                     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1669                     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1670
1671                     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1672                 }
1673             }
1674         }
1675
1676         glClear(GL_DEPTH_BUFFER_BIT);
1677         Game::ReSizeGLScene(90, .1f);
1678         glViewport(0, 0, screenwidth, screenheight);
1679
1680         if (drawmode != normalmode) {
1681             glDisable(GL_DEPTH_TEST);
1682             if (drawmode == motionblurmode) {
1683                 glDrawBuffer(GL_FRONT);
1684                 glReadBuffer(GL_BACK);
1685             }
1686             glColor3f (1.0, 1.0, 1.0); // no coloring
1687
1688             glEnable(GL_TEXTURE_2D);
1689             glBindTexture( GL_TEXTURE_2D, screentexture);
1690             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1691             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1692             glDisable(GL_DEPTH_TEST);
1693             glDisable(GL_CULL_FACE);
1694             glDisable(GL_LIGHTING);
1695             glDepthMask(0);
1696             glMatrixMode(GL_PROJECTION);
1697             glPushMatrix();
1698             glLoadIdentity();
1699             glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1700             glMatrixMode(GL_MODELVIEW);
1701             glPushMatrix();
1702             glLoadIdentity();
1703             glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
1704             glTranslatef(1, 1, 0);
1705             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1706             glEnable(GL_BLEND);
1707             if (drawmode == motionblurmode) {
1708                 if (motionbluramount < .2)
1709                     motionbluramount = .2;
1710                 glColor4f(1, 1, 1, motionbluramount);
1711                 glPushMatrix();
1712                 glBegin(GL_QUADS);
1713                 glTexCoord2f(0, 0);
1714                 glVertex3f(-1, -1, 0.0f);
1715                 glTexCoord2f(texcoordwidth, 0);
1716                 glVertex3f(1, -1, 0.0f);
1717                 glTexCoord2f(texcoordwidth, texcoordheight);
1718                 glVertex3f(1, 1, 0.0f);
1719                 glTexCoord2f(0, texcoordheight);
1720                 glVertex3f(-1, 1, 0.0f);
1721                 glEnd();
1722                 glPopMatrix();
1723             }
1724             if (drawmode == realmotionblurmode) {
1725                 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1726                 glClear(GL_COLOR_BUFFER_BIT);
1727                 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
1728                 glBindTexture( GL_TEXTURE_2D, screentexture);
1729                 glColor4f(1, 1, 1, .5);
1730                 glPushMatrix();
1731                 glBegin(GL_QUADS);
1732                 glTexCoord2f(0, 0);
1733                 glVertex3f(-1, -1, 0.0f);
1734                 glTexCoord2f(texcoordwidth, 0);
1735                 glVertex3f(1, -1, 0.0f);
1736                 glTexCoord2f(texcoordwidth, texcoordheight);
1737                 glVertex3f(1, 1, 0.0f);
1738                 glTexCoord2f(0, texcoordheight);
1739                 glVertex3f(-1, 1, 0.0f);
1740                 glEnd();
1741                 glPopMatrix();
1742                 glBindTexture( GL_TEXTURE_2D, screentexture2);
1743                 glColor4f(1, 1, 1, .5);
1744                 glPushMatrix();
1745                 glBegin(GL_QUADS);
1746                 glTexCoord2f(0, 0);
1747                 glVertex3f(-1, -1, 0.0f);
1748                 glTexCoord2f(texcoordwidth, 0);
1749                 glVertex3f(1, -1, 0.0f);
1750                 glTexCoord2f(texcoordwidth, texcoordheight);
1751                 glVertex3f(1, 1, 0.0f);
1752                 glTexCoord2f(0, texcoordheight);
1753                 glVertex3f(-1, 1, 0.0f);
1754                 glEnd();
1755                 glPopMatrix();
1756                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1757             }
1758             if (drawmode == doublevisionmode) {
1759                 static float crosseyedness;
1760                 crosseyedness = abs(Person::players[0]->damage - Person::players[0]->superpermanentdamage - (Person::players[0]->damagetolerance - Person::players[0]->superpermanentdamage) * 1 / 2) / 30;
1761                 if (crosseyedness > 1)
1762                     crosseyedness = 1;
1763                 if (crosseyedness < 0)
1764                     crosseyedness = 0;
1765                 glColor4f(1, 1, 1, 1);
1766                 glDisable(GL_BLEND);
1767                 glPushMatrix();
1768                 glScalef(1, 1, 1);
1769                 glBegin(GL_QUADS);
1770                 glTexCoord2f(0, 0);
1771                 glVertex3f(-1, -1, 0.0f);
1772                 glTexCoord2f(texcoordwidth, 0);
1773                 glVertex3f(1, -1, 0.0f);
1774                 glTexCoord2f(texcoordwidth, texcoordheight);
1775                 glVertex3f(1, 1, 0.0f);
1776                 glTexCoord2f(0, texcoordheight);
1777                 glVertex3f(-1, 1, 0.0f);
1778                 glEnd();
1779                 glPopMatrix();
1780                 if (crosseyedness) {
1781                     glColor4f(1, 1, 1, .5);
1782                     glEnable(GL_BLEND);
1783                     glPushMatrix();
1784                     glTranslatef(.015 * crosseyedness, 0, 0);
1785                     glScalef(1, 1, 1);
1786                     glBegin(GL_QUADS);
1787                     glTexCoord2f(0, 0);
1788                     glVertex3f(-1, -1, 0.0f);
1789                     glTexCoord2f(texcoordwidth, 0);
1790                     glVertex3f(1, -1, 0.0f);
1791                     glTexCoord2f(texcoordwidth, texcoordheight);
1792                     glVertex3f(1, 1, 0.0f);
1793                     glTexCoord2f(0, texcoordheight);
1794                     glVertex3f(-1, 1, 0.0f);
1795                     glEnd();
1796                     glPopMatrix();
1797                 }
1798             }
1799             if (drawmode == glowmode) {
1800                 glColor4f(.5, .5, .5, .5);
1801                 glEnable(GL_BLEND);
1802                 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
1803                 glPushMatrix();
1804                 glTranslatef(.01, 0, 0);
1805                 glBegin(GL_QUADS);
1806                 glTexCoord2f(0, 0);
1807                 glVertex3f(-1, -1, 0.0f);
1808                 glTexCoord2f(texcoordwidth, 0);
1809                 glVertex3f(1, -1, 0.0f);
1810                 glTexCoord2f(texcoordwidth, texcoordheight);
1811                 glVertex3f(1, 1, 0.0f);
1812                 glTexCoord2f(0, texcoordheight);
1813                 glVertex3f(-1, 1, 0.0f);
1814                 glEnd();
1815                 glPopMatrix();
1816                 glPushMatrix();
1817                 glTranslatef(-.01, 0, 0);
1818                 glBegin(GL_QUADS);
1819                 glTexCoord2f(0, 0);
1820                 glVertex3f(-1, -1, 0.0f);
1821                 glTexCoord2f(texcoordwidth, 0);
1822                 glVertex3f(1, -1, 0.0f);
1823                 glTexCoord2f(texcoordwidth, texcoordheight);
1824                 glVertex3f(1, 1, 0.0f);
1825                 glTexCoord2f(0, texcoordheight);
1826                 glVertex3f(-1, 1, 0.0f);
1827                 glEnd();
1828                 glPopMatrix();
1829                 glPushMatrix();
1830                 glTranslatef(.0, .01, 0);
1831                 glBegin(GL_QUADS);
1832                 glTexCoord2f(0, 0);
1833                 glVertex3f(-1, -1, 0.0f);
1834                 glTexCoord2f(texcoordwidth, 0);
1835                 glVertex3f(1, -1, 0.0f);
1836                 glTexCoord2f(texcoordwidth, texcoordheight);
1837                 glVertex3f(1, 1, 0.0f);
1838                 glTexCoord2f(0, texcoordheight);
1839                 glVertex3f(-1, 1, 0.0f);
1840                 glEnd();
1841                 glPopMatrix();
1842                 glPushMatrix();
1843                 glTranslatef(0, -.01, 0);
1844                 glBegin(GL_QUADS);
1845                 glTexCoord2f(0, 0);
1846                 glVertex3f(-1, -1, 0.0f);
1847                 glTexCoord2f(texcoordwidth, 0);
1848                 glVertex3f(1, -1, 0.0f);
1849                 glTexCoord2f(texcoordwidth, texcoordheight);
1850                 glVertex3f(1, 1, 0.0f);
1851                 glTexCoord2f(0, texcoordheight);
1852                 glVertex3f(-1, 1, 0.0f);
1853                 glEnd();
1854                 glPopMatrix();
1855             }
1856             if (drawmode == radialzoommode) {
1857                 for (int i = 0; i < 3; i++) {
1858                     glColor4f(1, 1, 1, 1 / ((float)i + 1));
1859                     glPushMatrix();
1860                     glScalef(1 + (float)i * .01, 1 + (float)i * .01, 1);
1861                     glBegin(GL_QUADS);
1862                     glTexCoord2f(0, 0);
1863                     glVertex3f(-1, -1, 0.0f);
1864                     glTexCoord2f(texcoordwidth, 0);
1865                     glVertex3f(1, -1, 0.0f);
1866                     glTexCoord2f(texcoordwidth, texcoordheight);
1867                     glVertex3f(1, 1, 0.0f);
1868                     glTexCoord2f(0, texcoordheight);
1869                     glVertex3f(-1, 1, 0.0f);
1870                     glEnd();
1871                     glPopMatrix();
1872                 }
1873             }
1874             glDisable(GL_TEXTURE_2D);
1875             glMatrixMode(GL_PROJECTION);
1876             glPopMatrix();
1877             glMatrixMode(GL_MODELVIEW);
1878             glPopMatrix();
1879             glEnable(GL_DEPTH_TEST);
1880             glEnable(GL_CULL_FACE);
1881             glDisable(GL_BLEND);
1882             glDepthMask(1);
1883         }
1884
1885         if (console) {
1886             glEnable(GL_TEXTURE_2D);
1887             glColor4f(1, 1, 1, 1);
1888             int offset = 0;
1889             if (consoleselected >= 60)
1890                 offset = consoleselected - 60;
1891             sprintf (string, " ]");
1892             text->glPrint(10, 30, string, 0, 1, 1024, 768);
1893             if (consoleblink) {
1894                 sprintf (string, "_");
1895                 text->glPrint(30 + (float)(consoleselected) * 10 - offset * 10, 30, string, 0, 1, 1024, 768);
1896             }
1897             for (unsigned i = 0; i < 15; i++)
1898                 for (unsigned j = 0; j < consoletext[i].size(); j++) {
1899                     glColor4f(1, 1, 1, 1 - (float)(i) / 16);
1900                     sprintf (string, "%c", consoletext[i][j]);
1901                     text->glPrint(30 + j * 10 - offset * 10, 30 + i * 20, string, 0, 1, 1024, 768);
1902                 }
1903         }
1904     }
1905
1906     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
1907         multiplier = tempmult;
1908     }
1909
1910     if (mainmenu) {
1911         DrawMenu();
1912     }
1913
1914     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
1915         tempmult = multiplier;
1916         multiplier = 0;
1917     }
1918
1919     if ( side == stereoRight || side == stereoCenter ) {
1920         if (drawmode != motionblurmode || mainmenu) {
1921             swap_gl_buffers();
1922         }
1923     }
1924
1925     glDrawBuffer(GL_BACK);
1926     glReadBuffer(GL_BACK);
1927
1928     weapons.DoStuff();
1929
1930     if (drawtoggle == 2)
1931         drawtoggle = 0;
1932
1933     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
1934         multiplier = tempmult;
1935     }
1936     //Jordan fixed your warning!
1937     return 0;
1938 }
1939
1940 void DrawMenu()
1941 {
1942     // !!! FIXME: hack: clamp framerate in menu so text input works correctly on fast systems.
1943     SDL_Delay(15);
1944
1945     glDrawBuffer(GL_BACK);
1946     glReadBuffer(GL_BACK);
1947     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1948     Game::ReSizeGLScene(90, .1f);
1949
1950     //draw menu background
1951     glClear(GL_DEPTH_BUFFER_BIT);
1952     glEnable(GL_ALPHA_TEST);
1953     glAlphaFunc(GL_GREATER, 0.001f);
1954     glEnable(GL_TEXTURE_2D);
1955     glDisable(GL_DEPTH_TEST);
1956     glDisable(GL_CULL_FACE);
1957     glDisable(GL_LIGHTING);
1958     glDepthMask(0);
1959     glMatrixMode(GL_PROJECTION);
1960     glPushMatrix();
1961     glLoadIdentity();
1962     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
1963     glMatrixMode(GL_MODELVIEW);
1964     glPushMatrix();
1965     glLoadIdentity();
1966     glTranslatef(screenwidth / 2, screenheight / 2, 0);
1967     glPushMatrix();
1968     glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
1969     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1970     glDisable(GL_BLEND);
1971     glColor4f(0, 0, 0, 1.0);
1972     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1973     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1974     glDisable(GL_TEXTURE_2D);
1975     glBegin(GL_QUADS);
1976     glVertex3f(-1, -1, 0);
1977     glVertex3f(+1, -1, 0);
1978     glVertex3f(+1, +1, 0);
1979     glVertex3f(-1, +1, 0);
1980     glEnd();
1981     glEnable(GL_BLEND);
1982     glColor4f(0.4, 0.4, 0.4, 1.0);
1983     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1984     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1985     glEnable(GL_TEXTURE_2D);
1986     Game::Mainmenuitems[4].bind();
1987     glBegin(GL_QUADS);
1988     glTexCoord2f(0, 0);
1989     glVertex3f(-1, -1, 0);
1990     glTexCoord2f(1, 0);
1991     glVertex3f(+1, -1, 0);
1992     glTexCoord2f(1, 1);
1993     glVertex3f(+1, +1, 0);
1994     glTexCoord2f(0, 1);
1995     glVertex3f(-1, +1, 0);
1996     glEnd();
1997     glPopMatrix();
1998     glPopMatrix();
1999     glMatrixMode(GL_PROJECTION);
2000     glPopMatrix();
2001     glMatrixMode(GL_MODELVIEW);
2002
2003
2004
2005     glMatrixMode(GL_PROJECTION);
2006     glPushMatrix();
2007     glLoadIdentity();
2008     glOrtho(0, 640, 0, 480, -100, 100);
2009     glMatrixMode(GL_MODELVIEW);
2010     glPushMatrix();
2011     glLoadIdentity();
2012     glEnable(GL_TEXTURE_2D);
2013
2014     Menu::drawItems();
2015
2016     //draw mouse cursor
2017     glMatrixMode(GL_PROJECTION);
2018     glPopMatrix();
2019     glMatrixMode(GL_MODELVIEW);
2020     glPopMatrix();
2021
2022     glMatrixMode(GL_PROJECTION);
2023     glPushMatrix();
2024     glLoadIdentity();
2025     glOrtho(0, screenwidth, 0, screenheight, -100, 100);
2026     glMatrixMode(GL_MODELVIEW);
2027     glPushMatrix();
2028     glLoadIdentity();
2029     glTranslatef(screenwidth / 2, screenheight / 2, 0);
2030     glPushMatrix();
2031     glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
2032     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2033     glEnable(GL_BLEND);
2034     glEnable(GL_TEXTURE_2D);
2035     glColor4f(1, 1, 1, 1);
2036     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2037     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2038     glPopMatrix();
2039     if (!Game::waiting) { // hide the cursor while waiting for a key
2040         glPushMatrix();
2041         glTranslatef(Game::mousecoordh - screenwidth / 2, Game::mousecoordv * -1 + screenheight / 2, 0);
2042         glScalef((float)screenwidth / 64, (float)screenwidth / 64, 1);
2043         glTranslatef(1, -1, 0);
2044         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2045         glColor4f(1, 1, 1, 1);
2046         Game::cursortexture.bind();
2047         glPushMatrix();
2048         glBegin(GL_QUADS);
2049         glTexCoord2f(0, 0);
2050         glVertex3f(-1, -1, 0.0f);
2051         glTexCoord2f(1, 0);
2052         glVertex3f(1, -1, 0.0f);
2053         glTexCoord2f(1, 1);
2054         glVertex3f(1, 1, 0.0f);
2055         glTexCoord2f(0, 1);
2056         glVertex3f(-1, 1, 0.0f);
2057         glEnd();
2058         glPopMatrix();
2059         glPopMatrix();
2060     }
2061     glPopMatrix();
2062     glMatrixMode(GL_PROJECTION);
2063     glPopMatrix();
2064
2065
2066     //draw screen flash
2067     if (flashamount > 0) {
2068         if (flashamount > 1)
2069             flashamount = 1;
2070         if (flashdelay <= 0)
2071             flashamount -= multiplier;
2072         flashdelay--;
2073         if (flashamount < 0)
2074             flashamount = 0;
2075         glDisable(GL_DEPTH_TEST);
2076         glDisable(GL_CULL_FACE);
2077         glDisable(GL_LIGHTING);
2078         glDisable(GL_TEXTURE_2D);
2079         glDepthMask(0);
2080         glMatrixMode(GL_PROJECTION);
2081         glPushMatrix();
2082         glLoadIdentity();
2083         glOrtho(0, screenwidth, 0, screenheight, -100, 100);
2084         glMatrixMode(GL_MODELVIEW);
2085         glPushMatrix();
2086         glLoadIdentity();
2087         glScalef(screenwidth, screenheight, 1);
2088         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2089         glEnable(GL_BLEND);
2090         glColor4f(flashr, flashg, flashb, flashamount);
2091         glBegin(GL_QUADS);
2092         glVertex3f(0, 0, 0.0f);
2093         glVertex3f(256, 0, 0.0f);
2094         glVertex3f(256, 256, 0.0f);
2095         glVertex3f(0, 256, 0.0f);
2096         glEnd();
2097         glMatrixMode(GL_PROJECTION);
2098         glPopMatrix();
2099         glMatrixMode(GL_MODELVIEW);
2100         glPopMatrix();
2101         glEnable(GL_DEPTH_TEST);
2102         glEnable(GL_CULL_FACE);
2103         glDisable(GL_BLEND);
2104         glDepthMask(1);
2105     }
2106 }