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