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