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