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