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