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