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