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