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