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