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