]> git.jsancho.org Git - lugaru.git/blob - Source/GameDraw.cpp
FORMATTED IF STATEMENTS
[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         }
159     } else {
160         glColorMask( 1.0, 1.0, 1.0, 1.0 );
161
162         if ( stereomode == stereoHorizontalInterlaced || stereomode == stereoVerticalInterlaced ) {
163             glStencilFunc(side == stereoLeft ? GL_NOTEQUAL : GL_EQUAL, 0x01, 0x01);
164         }
165     }
166
167     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
168         tempmult = multiplier;
169         multiplier = 0;
170     }
171
172     if (!mainmenu) {
173         if (editorenabled) {
174             numboundaries = mapradius * 2;
175             if (numboundaries > 360)
176                 numboundaries = 360;
177             for (i = 0; i < numboundaries; i++) {
178                 boundary[i] = 0;
179                 boundary[i].z = 1;
180                 boundary[i] = mapcenter + DoRotation(boundary[i] * mapradius, 0, i * (360 / ((float)(numboundaries))), 0);
181             }
182         }
183
184         SetUpLighting();
185
186         static int changed;
187         changed = 0;
188
189         int olddrawmode = drawmode;
190         if (ismotionblur && !loading) {
191             if ((findLengthfast(&player[0].velocity) > 200) && velocityblur && !cameramode) {
192                 drawmode = motionblurmode;
193                 motionbluramount = 200 / (findLengthfast(&player[0].velocity));
194                 changed = 1;
195             }
196             if (player[0].damage - player[0].superpermanentdamage > (player[0].damagetolerance - player[0].superpermanentdamage) * 1 / 2 && damageeffects && !cameramode) {
197                 drawmode = doublevisionmode;
198                 changed = 1;
199             }
200         }
201
202         if (slomo && !loading) {
203             if (ismotionblur)
204                 drawmode = motionblurmode;
205             motionbluramount = .2;
206             slomodelay -= multiplier;
207             if (slomodelay < 0)
208                 slomo = 0;
209             camerashake = 0;
210             changed = 1;
211         }
212         if ((!changed && !slomo) || loading) {
213             drawmode = normalmode;
214             if (ismotionblur && (/*fps>100||*/alwaysblur)) {
215                 if (olddrawmode != realmotionblurmode)
216                     change = 1;
217                 else
218                     change = 0;
219                 drawmode = realmotionblurmode;
220             } else if (olddrawmode == realmotionblurmode)
221                 change = 2;
222             else
223                 change = 0;
224         }
225
226         if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted))
227             drawmode = normalmode;
228         if ((freeze || winfreeze) && ismotionblur && !mainmenu)
229             drawmode = radialzoommode;
230
231         if (winfreeze || mainmenu)
232             drawmode = normalmode;
233
234 #if PLATFORM_MACOSX
235         if (drawmode == glowmode) {
236             RGBColor color2;
237             color2.red = 0;
238             color2.green = 0;
239             color2.blue = 0;
240             DSpContext_FadeGamma(NULL, 200, &color2);
241         }
242 #endif
243
244         if (drawtoggle != 2)
245             drawtoggle = 1 - drawtoggle;
246
247         if (!texcoordwidth) {
248             texviewwidth = kTextureSize;
249             if (texviewwidth > screenwidth)
250                 texviewwidth = screenwidth;
251             texviewheight = kTextureSize;
252             if (texviewheight > screenheight)
253                 texviewheight = screenheight;
254
255             texcoordwidth = screenwidth / kTextureSize;
256             texcoordheight = screenheight / kTextureSize;
257             if (texcoordwidth > 1)
258                 texcoordwidth = 1;
259             if (texcoordheight > 1)
260                 texcoordheight = 1;
261         }
262
263         glDrawBuffer(GL_BACK);
264         glReadBuffer(GL_BACK);
265
266         //glFinish();
267         static XYZ terrainlight;
268         static float distance;
269         if (drawmode == normalmode)
270             Game::ReSizeGLScene(90, .1f);
271         if (drawmode != normalmode)
272             glViewport(0, 0, texviewwidth, texviewheight);
273         glDepthFunc(GL_LEQUAL);
274         glDepthMask(1);
275         glAlphaFunc(GL_GREATER, 0.0001f);
276         glEnable(GL_ALPHA_TEST);
277         glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
278         glClear(GL_DEPTH_BUFFER_BIT);
279
280         glMatrixMode (GL_MODELVIEW);
281         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
282         glLoadIdentity ();
283
284         // Move the camera for the current eye's point of view.
285         // Reverse the movement if we're reversing stereo
286         glTranslatef((stereoseparation / 2) * side * (stereoreverse  ? -1 : 1), 0, 0);
287
288         //camera effects
289         if (!cameramode && !freeze && !winfreeze) {
290             //shake
291             glRotatef(float(Random() % 100) / 10 * camerashake/*+(woozy*woozy)/10*/, 0, 0, 1);
292             //sway
293             glRotatef(pitch + sin(woozy / 2) * (player[0].damage / player[0].damagetolerance) * 5, 1, 0, 0);
294             glRotatef(yaw + sin(woozy) * (player[0].damage / player[0].damagetolerance) * 5, 0, 1, 0);
295         }
296         if (cameramode || freeze || winfreeze) {
297             glRotatef(pitch, 1, 0, 0);
298             glRotatef(yaw, 0, 1, 0);
299         }
300
301         if (environment == desertenvironment) {
302             glRotatef((float)(abs(Random() % 100)) / 3000 - 1, 1, 0, 0);
303             glRotatef((float)(abs(Random() % 100)) / 3000 - 1, 0, 1, 0);
304         }
305         SetUpLight(&light, 0);
306         glPushMatrix();
307
308         //heat blur effect in desert
309         if (abs(blurness - targetblurness) < multiplier * 10 || abs(blurness - targetblurness) > 2) {
310             blurness = targetblurness;
311             targetblurness = (float)(abs(Random() % 100)) / 40;
312         }
313         if (blurness < targetblurness)
314             blurness += multiplier * 5;
315         else
316             blurness -= multiplier * 5;
317
318         if (environment == desertenvironment && detail == 2)
319             glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness + .4 );
320         if (environment == desertenvironment) {
321             glRotatef((float)(abs(Random() % 100)) / 1000, 1, 0, 0);
322             glRotatef((float)(abs(Random() % 100)) / 1000, 0, 1, 0);
323         }
324         skybox->draw();
325         glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
326         glPopMatrix();
327         glTranslatef(-viewer.x, -viewer.y, -viewer.z);
328         frustum.GetFrustum();
329
330         //make shadow decals on terrain and objects
331         static XYZ point;
332         static float size, opacity, rotation;
333         rotation = 0;
334         for (k = 0; k < numplayers; k++) {
335             if (!player[k].skeleton.free && player[k].playerdetail && player[k].howactive < typesleeping)
336                 if (frustum.SphereInFrustum(player[k].coords.x, player[k].coords.y + player[k].scale * 3, player[k].coords.z, player[k].scale * 7) && player[k].occluded < 25)
337                     for (i = 0; i < player[k].skeleton.num_joints; i++) {
338                         if (player[k].skeleton.joints[i].label == leftknee || player[k].skeleton.joints[i].label == rightknee || player[k].skeleton.joints[i].label == groin) {
339                             point = DoRotation(player[k].skeleton.joints[i].position, 0, player[k].yaw, 0) * player[k].scale + player[k].coords;
340                             size = .4f;
341                             opacity = .4 - player[k].skeleton.joints[i].position.y * player[k].scale / 5 - (player[k].coords.y - terrain.getHeight(player[k].coords.x, player[k].coords.z)) / 10;
342                             if (k != 0 && tutoriallevel == 1) {
343                                 opacity = .2 + .2 * sin(smoketex * 6 + i) - player[k].skeleton.joints[i].position.y * player[k].scale / 5 - (player[k].coords.y - terrain.getHeight(player[k].coords.x, player[k].coords.z)) / 10;
344                             }
345                             terrain.MakeDecal(shadowdecal, point, size, opacity, rotation);
346                             for (l = 0; l < terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]; l++) {
347                                 j = terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
348                                 if (objects.position[j].y < player[k].coords.y || objects.type[j] == tunneltype || objects.type[j] == weirdtype) {
349                                     point = DoRotation(DoRotation(player[k].skeleton.joints[i].position, 0, player[k].yaw, 0) * player[k].scale + player[k].coords - objects.position[j], 0, -objects.yaw[j], 0);
350                                     size = .4f;
351                                     opacity = .4f;
352                                     if (k != 0 && tutoriallevel == 1) {
353                                         opacity = .2 + .2 * sin(smoketex * 6 + i);
354                                     }
355                                     objects.model[j].MakeDecal(shadowdecal, &point, &size, &opacity, &rotation);
356                                 }
357                             }
358                         }
359                     }
360             if ((player[k].skeleton.free || player[k].howactive >= typesleeping) && player[k].playerdetail)
361                 if (frustum.SphereInFrustum(player[k].coords.x, player[k].coords.y, player[k].coords.z, player[k].scale * 5) && player[k].occluded < 25)
362                     for (i = 0; i < player[k].skeleton.num_joints; i++) {
363                         if (player[k].skeleton.joints[i].label == leftknee || player[k].skeleton.joints[i].label == rightknee || player[k].skeleton.joints[i].label == groin || player[k].skeleton.joints[i].label == leftelbow || player[k].skeleton.joints[i].label == rightelbow || player[k].skeleton.joints[i].label == neck) {
364                             if (player[k].skeleton.free)
365                                 point = player[k].skeleton.joints[i].position * player[k].scale + player[k].coords;
366                             else
367                                 point = DoRotation(player[k].skeleton.joints[i].position, 0, player[k].yaw, 0) * player[k].scale + player[k].coords;
368                             size = .4f;
369                             opacity = .4 - player[k].skeleton.joints[i].position.y * player[k].scale / 5 - (player[k].coords.y - terrain.getHeight(player[k].coords.x, player[k].coords.z)) / 5;
370                             if (k != 0 && tutoriallevel == 1) {
371                                 opacity = .2 + .2 * sin(smoketex * 6 + i) - player[k].skeleton.joints[i].position.y * player[k].scale / 5 - (player[k].coords.y - terrain.getHeight(player[k].coords.x, player[k].coords.z)) / 10;
372                             }
373                             terrain.MakeDecal(shadowdecal, point, size, opacity * .7, rotation);
374                             for (l = 0; l < terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]; l++) {
375                                 j = terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
376                                 if (objects.position[j].y < player[k].coords.y || objects.type[j] == tunneltype || objects.type[j] == weirdtype) {
377                                     if (player[k].skeleton.free)
378                                         point = DoRotation(player[k].skeleton.joints[i].position * player[k].scale + player[k].coords - objects.position[j], 0, -objects.yaw[j], 0);
379                                     else
380                                         point = DoRotation(DoRotation(player[k].skeleton.joints[i].position, 0, player[k].yaw, 0) * player[k].scale + player[k].coords - objects.position[j], 0, -objects.yaw[j], 0);
381                                     size = .4f;
382                                     opacity = .4f;
383                                     if (k != 0 && tutoriallevel == 1) {
384                                         opacity = .2 + .2 * sin(smoketex * 6 + i);
385                                     }
386                                     objects.model[j].MakeDecal(shadowdecal, &point, &size, &opacity, &rotation);
387                                 }
388                             }
389                         }
390                     }
391
392             if (!player[k].playerdetail)
393                 if (frustum.SphereInFrustum(player[k].coords.x, player[k].coords.y, player[k].coords.z, player[k].scale * 5)) {
394                     point = player[k].coords;
395                     size = .7;
396                     opacity = .4 - (player[k].coords.y - terrain.getHeight(player[k].coords.x, player[k].coords.z)) / 5;
397                     terrain.MakeDecal(shadowdecal, point, size, opacity * .7, rotation);
398                     for (l = 0; l < terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]; l++) {
399                         j = terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
400                         point = DoRotation(player[k].coords - objects.position[j], 0, -objects.yaw[j], 0);
401                         size = .7;
402                         opacity = .4f;
403                         objects.model[j].MakeDecal(shadowdecal, &point, &size, &opacity, &rotation);
404                     }
405                 }
406         }
407
408         //Terrain
409         glEnable(GL_TEXTURE_2D);
410         glDepthMask(1);
411         glEnable(GL_DEPTH_TEST);
412         glEnable(GL_CULL_FACE);
413         glDisable(GL_BLEND);
414         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
415         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
416         terraintexture.bind();
417         terrain.draw(0);
418         terraintexture2.bind();
419         terrain.draw(1);
420         //glBindTexture( GL_TEXTURE_2D, terraintexture3);
421         //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
422         //terrain.draw(2);
423
424         terrain.drawdecals();
425
426         //Model
427         glEnable(GL_CULL_FACE);
428         glEnable(GL_LIGHTING);
429         glDisable(GL_BLEND);
430         glEnable(GL_TEXTURE_2D);
431         glDepthMask(1);
432
433         glEnable(GL_COLOR_MATERIAL);
434
435         test = 2;
436         tilt2weird = 0;
437         tiltweird = 0;
438         midweird = 0;
439         proportionweird = 0;
440         vertexweird[0] = 0;
441         vertexweird[1] = 0;
442         vertexweird[2] = 0;
443         vertexweird[3] = 0;
444         vertexweird[4] = 0;
445         vertexweird[5] = 0;
446
447         if (!cellophane) {
448             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
449             glEnable(GL_CULL_FACE);
450             glCullFace(GL_FRONT);
451             glDepthMask(1);
452             for (k = 0; k < numplayers; k++) {
453                 if (k == 0 || tutoriallevel != 1) {
454                     glEnable(GL_BLEND);
455                     glEnable(GL_LIGHTING);
456                     terrainlight = terrain.getLighting(player[k].coords.x, player[k].coords.z);
457                     distance = distsq(&viewer, &player[k].coords);
458                     distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
459                     glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
460                     if (distance >= 1)
461                         glDisable(GL_BLEND);
462                     if (distance >= .5) {
463                         checkpoint = DoRotation(player[k].skeleton.joints[abs(Random() % player[k].skeleton.num_joints)].position, 0, player[k].yaw, 0) * player[k].scale + player[k].coords;
464                         checkpoint.y += 1;
465                         if (!player[k].occluded == 0)
466                             i = checkcollide(viewer, checkpoint, player[k].lastoccluded);
467                         if (i == -1 || player[k].occluded == 0)
468                             i = checkcollide(viewer, checkpoint);
469                         if (i != -1) {
470                             player[k].occluded += 1;
471                             player[k].lastoccluded = i;
472                         } else {
473                             player[k].occluded = 0;
474                         }
475                         if (player[k].occluded < 25)
476                             player[k].DrawSkeleton();
477                     }
478                 }
479             }
480         }
481
482         if (!cameramode && musictype == stream_fighttheme)
483             playerdist = distsqflat(&player[0].coords, &viewer);
484         else
485             playerdist = -100;
486         glPushMatrix();
487         glCullFace(GL_BACK);
488         glEnable(GL_TEXTURE_2D);
489         objects.Draw();
490         glPopMatrix();
491
492         //draw hawk
493         glPushMatrix();
494         if (frustum.SphereInFrustum(realhawkcoords.x + hawk.boundingspherecenter.x, realhawkcoords.y + hawk.boundingspherecenter.y, realhawkcoords.z + hawk.boundingspherecenter.z, 2)) {
495             glAlphaFunc(GL_GREATER, 0.0001f);
496             glDepthMask(1);
497             glDisable(GL_CULL_FACE);
498             glDisable(GL_LIGHTING);
499             glEnable(GL_BLEND);
500             glTranslatef(hawkcoords.x, hawkcoords.y, hawkcoords.z);
501             glRotatef(hawkyaw, 0, 1, 0);
502             glTranslatef(25, 0, 0);
503             distance = distsq(&viewer, &realhawkcoords) * 1.2;
504             glColor4f(light.color[0], light.color[1], light.color[2], (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance);
505             if ((viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance > 1)
506                 glColor4f(light.color[0], light.color[1], light.color[2], 1);
507             if ((viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance > 0)
508                 hawk.drawdifftex(hawktexture);
509         }
510         glPopMatrix();
511
512         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
513         glEnable(GL_CULL_FACE);
514         glCullFace(GL_FRONT);
515         glDepthMask(1);
516         for (k = 0; k < numplayers; k++) {
517             if (!(k == 0 || tutoriallevel != 1)) {
518                 glEnable(GL_BLEND);
519                 glEnable(GL_LIGHTING);
520                 terrainlight = terrain.getLighting(player[k].coords.x, player[k].coords.z);
521                 distance = distsq(&viewer, &player[k].coords);
522                 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
523                 glColor4f(terrainlight.x, terrainlight.y, terrainlight.z, distance);
524                 if (distance >= 1)
525                     glDisable(GL_BLEND);
526                 if (distance >= .5) {
527                     checkpoint = DoRotation(player[k].skeleton.joints[abs(Random() % player[k].skeleton.num_joints)].position, 0, player[k].yaw, 0) * player[k].scale + player[k].coords;
528                     checkpoint.y += 1;
529                     if (!player[k].occluded == 0)
530                         i = checkcollide(viewer, checkpoint, player[k].lastoccluded);
531                     if (i == -1 || player[k].occluded == 0)
532                         i = checkcollide(viewer, checkpoint);
533                     if (i != -1) {
534                         player[k].occluded += 1;
535                         player[k].lastoccluded = i;
536                     } else {
537                         player[k].occluded = 0;
538                     }
539                     if (player[k].occluded < 25)
540                         player[k].DrawSkeleton();
541                 }
542             }
543         }
544
545         glPushMatrix();
546         glEnable(GL_TEXTURE_2D);
547         weapons.Draw();
548         glPopMatrix();
549         glCullFace(GL_BACK);
550
551         glDisable(GL_COLOR_MATERIAL);
552
553         glDisable(GL_LIGHTING);
554         glDisable(GL_TEXTURE_2D);
555
556         glDepthMask(0);
557
558         Sprite::Draw();
559
560         //waypoints, pathpoints in editor
561         if (editorenabled) {
562             glEnable(GL_BLEND);
563             glDisable(GL_LIGHTING);
564             glDisable(GL_TEXTURE_2D);
565             glDisable(GL_COLOR_MATERIAL);
566             glColor4f(1, 1, 0, 1);
567
568             for (k = 0; k < numplayers; k++) {
569                 if (player[k].numwaypoints > 1) {
570                     glBegin(GL_LINE_LOOP);
571                     for (i = 0; i < player[k].numwaypoints; i++) {
572                         glVertex3f(player[k].waypoints[i].x, player[k].waypoints[i].y + .5, player[k].waypoints[i].z);
573                     }
574                     glEnd();
575                 }
576             }
577
578
579             if (numpathpoints > 1) {
580                 glColor4f(0, 1, 0, 1);
581                 for (k = 0; k < numpathpoints; k++) {
582                     if (numpathpointconnect[k]) {
583                         for (i = 0; i < numpathpointconnect[k]; i++) {
584                             glBegin(GL_LINE_LOOP);
585                             glVertex3f(pathpoint[k].x, pathpoint[k].y + .5, pathpoint[k].z);
586                             glVertex3f(pathpoint[pathpointconnect[k][i]].x, pathpoint[pathpointconnect[k][i]].y + .5, pathpoint[pathpointconnect[k][i]].z);
587                             glEnd();
588                         }
589                     }
590                 }
591                 glColor4f(1, 1, 1, 1);
592                 glPointSize(4);
593                 glBegin(GL_POINTS);
594                 glVertex3f(pathpoint[pathpointselected].x, pathpoint[pathpointselected].y + .5, pathpoint[pathpointselected].z);
595                 glEnd();
596             }
597         }
598
599         //Text
600
601         glEnable(GL_TEXTURE_2D);
602         glColor4f(.5, .5, .5, 1);
603         if (!console) {
604             sprintf (string, " ", (int)(fps));
605             text->glPrint(10, 30, string, 0, .8, screenwidth, screenheight);
606
607             if (!tutoriallevel)
608                 if (bonus > 0 && bonustime < 1 && !winfreeze && indialogue == -1/*bonustime<4*/) {
609                     const char *bonus_name;
610                     if (bonus < bonus_count)
611                         bonus_name = bonus_names[bonus];
612                     else
613                         bonus_name = "Excellent!"; // When does this happen?
614
615                     glColor4f(0, 0, 0, 1 - bonustime);
616                     text->glPrintOutline(1024 / 2 - 10 * strlen(bonus_name) - 4, 768 / 16 - 4 + 768 * 4 / 5, bonus_name, 1, 2.5, 1024, 768);
617                     glColor4f(1, 0, 0, 1 - bonustime);
618                     text->glPrint(1024 / 2 - 10 * strlen(bonus_name), 768 / 16 + 768 * 4 / 5, bonus_name, 1, 2, 1024, 768);
619
620                     sprintf (string, "%d", (int)bonusvalue);
621                     glColor4f(0, 0, 0, 1 - bonustime);
622                     text->glPrintOutline(1024 / 2 - 10 * strlen(string) - 4, 768 / 16 - 4 - 20 + 768 * 4 / 5, string, 1, 2.5 * .8, 1024, 768);
623                     glColor4f(1, 0, 0, 1 - bonustime);
624                     text->glPrint(1024 / 2 - 10 * strlen(string), 768 / 16 - 20 + 768 * 4 / 5, string, 1, 2 * .8, 1024, 768);
625                     glColor4f(.5, .5, .5, 1);
626                 }
627
628             if (tutoriallevel == 1) {
629                 tutorialopac = tutorialmaxtime - tutorialstagetime;
630                 if (tutorialopac > 1)
631                     tutorialopac = 1;
632                 if (tutorialopac < 0)
633                     tutorialopac = 0;
634
635                 sprintf (string, " ");
636                 sprintf (string2, " ");
637                 sprintf (string3, " ");
638                 if (tutorialstage == 0) {
639                     sprintf (string, " ");
640                     sprintf (string2, " ");
641                     sprintf (string3, " ");
642                 }
643                 if (tutorialstage == 1) {
644                     sprintf (string, "Welcome to the Lugaru training level!");
645                     sprintf (string2, " ");
646                     sprintf (string3, " ");
647                 }
648                 if (tutorialstage == 2) {
649                     sprintf (string, "BASIC MOVEMENT:");
650                     sprintf (string2, " ");
651                     sprintf (string3, " ");
652                 }
653                 if (tutorialstage == 3) {
654                     sprintf (string, "You can move the mouse to rotate the camera.");
655                     sprintf (string2, " ");
656                     sprintf (string3, " ");
657                 }
658                 if (tutorialstage == 4) {
659                     sprintf (string, "Try using the %s, %s, %s and %s keys to move around.", Input::keyToChar(forwardkey), Input::keyToChar(leftkey), Input::keyToChar(backkey), Input::keyToChar(rightkey));
660                     sprintf (string2, "All movement is relative to the camera.");
661                     sprintf (string3, " ");
662                 }
663                 if (tutorialstage == 5) {
664                     sprintf (string, "Please press %s to jump.", Input::keyToChar(jumpkey));
665                     sprintf (string2, "You can hold it longer to jump higher.");
666                     sprintf (string3, " ");
667                 }
668                 if (tutorialstage == 6) {
669                     sprintf (string, "You can press %s to crouch.", Input::keyToChar(crouchkey));
670                     sprintf (string2, "You can jump higher from a crouching position.");
671                     sprintf (string3, " ");
672                 }
673                 if (tutorialstage == 7) {
674                     sprintf (string, "While running, you can press %s to roll.", Input::keyToChar(crouchkey));
675                     sprintf (string2, " ");
676                     sprintf (string3, " ");
677                 }
678                 if (tutorialstage == 8) {
679                     sprintf (string, "While crouching, you can sneak around silently");
680                     sprintf (string2, "using the movement keys.");
681                     sprintf (string3, " ");
682                 }
683                 if (tutorialstage == 9) {
684                     sprintf (string, "Release the crouch key while sneaking and hold the movement keys");
685                     sprintf (string2, "to run animal-style.");
686                     sprintf (string3, " ");
687                 }
688                 if (tutorialstage == 10) {
689                     sprintf (string, "ADVANCED MOVEMENT:");
690                     sprintf (string2, " ");
691                     sprintf (string3, " ");
692                 }
693                 if (tutorialstage == 11) {
694                     sprintf (string, "When you jump at a wall, you can hold %s again", Input::keyToChar(jumpkey));
695                     sprintf (string2, "during impact to perform a walljump.");
696                     sprintf (string3, "Be sure to use the movement keys to press against the wall");
697                 }
698                 if (tutorialstage == 12) {
699                     sprintf (string, "While in the air, you can press crouch to flip.", Input::keyToChar(jumpkey));
700                     sprintf (string2, "Walljumps and flips confuse enemies and give you more control.");
701                     sprintf (string3, " ");
702                 }
703                 if (tutorialstage == 13) {
704                     sprintf (string, "BASIC COMBAT:");
705                     sprintf (string2, " ");
706                     sprintf (string3, " ");
707                 }
708                 if (tutorialstage == 14) {
709                     sprintf (string, "There is now an imaginary enemy");
710                     sprintf (string2, "in the middle of the training area.");
711                     sprintf (string3, " ");
712                 }
713                 if (tutorialstage == 15) {
714                     if (attackkey == MOUSEBUTTON1)
715                         sprintf (string, "Click to attack when you are near an enemy.");
716                     else
717                         sprintf (string, "Press %s to attack when you are near an enemy.", Input::keyToChar(attackkey));
718                     sprintf (string2, "You can punch by standing still near an enemy and attacking.");
719                     sprintf (string3, " ");
720                 }
721                 if (tutorialstage == 16) {
722                     sprintf (string, "If you are close, you will perform a weak punch.");
723                     sprintf (string2, "The weak punch is excellent for starting attack combinations.");
724                     sprintf (string3, " ");
725                 }
726                 if (tutorialstage == 17) {
727                     sprintf (string, "Attacking while running results in a spin kick.");
728                     sprintf (string2, "This is one of your most powerful ground attacks.");
729                     sprintf (string3, " ");
730                 }
731                 if (tutorialstage == 18) {
732                     sprintf (string, "Sweep the enemy's legs out by attacking while crouched.");
733                     sprintf (string2, "This is a very fast attack, and easy to follow up.");
734                     sprintf (string3, " ");
735                 }
736                 if (tutorialstage == 19) {
737                     sprintf (string, "When an enemy is on the ground, you can deal some extra");
738                     sprintf (string2, "damage by running up and drop-kicking him.");
739                     sprintf (string3, "(Try knocking them down with a sweep first)");
740                 }
741                 if (tutorialstage == 20) {
742                     sprintf (string, "Your most powerful individual attack is the rabbit kick.");
743                     if (attackkey == MOUSEBUTTON1)
744                         sprintf (string2, "Run at the enemy while holding the mouse button, and press");
745                     else
746                         sprintf (string2, "Run at the enemy while holding %s, and press", Input::keyToChar(attackkey));
747                     sprintf (string3, "the jump key (%s) to attack.", Input::keyToChar(jumpkey));
748                 }
749                 if (tutorialstage == 21) {
750                     sprintf (string, "This attack is devastating if timed correctly.");
751                     sprintf (string2, "Even if timed incorrectly, it will knock the enemy over.");
752                     if (againbonus)
753                         sprintf (string3, "Try rabbit-kicking the imaginary enemy again.");
754                     else
755                         sprintf (string3, "Try rabbit-kicking the imaginary enemy.");
756                 }
757                 if (tutorialstage == 22) {
758                     sprintf (string, "If you sneak behind an enemy unnoticed, you can kill");
759                     sprintf (string2, "him instantly. Move close behind this enemy");
760                     sprintf (string3, "and attack.");
761                 }
762                 if (tutorialstage == 23) {
763                     sprintf (string, "Another important attack is the wall kick. When an enemy");
764                     sprintf (string2, "is near a wall, perform a walljump nearby and hold");
765                     sprintf (string3, "the attack key during impact with the wall.");
766                 }
767                 if (tutorialstage == 24) {
768                     sprintf (string, "You can tackle enemies by running at them animal-style");
769                     if (attackkey == MOUSEBUTTON1)
770                         sprintf (string2, "and pressing jump (%s) or attack(mouse button).", Input::keyToChar(jumpkey));
771                     else
772                         sprintf (string2, "and pressing jump (%s) or attack(%s).", Input::keyToChar(jumpkey), Input::keyToChar(attackkey));
773                     sprintf (string3, "This is especially useful when they are running away.");
774                 }
775                 if (tutorialstage == 25) {
776                     sprintf (string, "Dodge by pressing back and attack. Dodging is essential");
777                     sprintf (string2, "against enemies with swords or other long weapons.");
778                     sprintf (string3, " ");
779                 }
780                 if (tutorialstage == 26) {
781                     sprintf (string, "REVERSALS AND COUNTER-REVERSALS");
782                     sprintf (string2, " ");
783                     sprintf (string3, " ");
784                 }
785                 if (tutorialstage == 27) {
786                     sprintf (string, "The enemy can now reverse your attacks.");
787                     sprintf (string2, " ");
788                     sprintf (string3, " ");
789                 }
790                 if (tutorialstage == 28) {
791                     sprintf (string, "If you attack, you will notice that the enemy now sometimes");
792                     sprintf (string2, "catches your attack and uses it against you. Hold");
793                     sprintf (string3, "crouch (%s) after attacking to escape from reversals.", Input::keyToChar(crouchkey));
794                 }
795                 if (tutorialstage == 29) {
796                     sprintf (string, "Try escaping from two more reversals in a row.");
797                     sprintf (string2, " ");
798                     sprintf (string3, " ");
799                 }
800                 if (tutorialstage == 30) {
801                     sprintf (string, "Good!");
802                     sprintf (string2, " ");
803                     sprintf (string3, " ");
804                 }
805                 if (tutorialstage == 31) {
806                     sprintf (string, "To reverse an attack, you must tap crouch (%s) during the", Input::keyToChar(crouchkey));
807                     sprintf (string2, "enemy's attack. You must also be close to the enemy;");
808                     sprintf (string3, "this is especially important against armed opponents.");
809                 }
810                 if (tutorialstage == 32) {
811                     sprintf (string, "The enemy can attack in %d seconds.", (int)(tutorialmaxtime - tutorialstagetime));
812                     sprintf (string2, "This imaginary opponents attacks will be highlighted");
813                     sprintf (string3, "to make this easier.");
814                 }
815                 if (tutorialstage == 33) {
816                     sprintf (string, "Reverse three enemy attacks!");
817                     sprintf (string2, " ");
818                     sprintf (string3, " ");
819                 }
820                 if (tutorialstage == 34) {
821                     sprintf (string, "Reverse two more enemy attacks!");
822                     sprintf (string2, " ");
823                     sprintf (string3, " ");
824                 }
825                 if (tutorialstage == 35) {
826                     sprintf (string, "Reverse one more enemy attack!");
827                     sprintf (string2, " ");
828                     sprintf (string3, " ");
829                 }
830                 if (tutorialstage == 36) {
831                     sprintf (string, "Excellent!");
832                     sprintf (string2, " ");
833                     sprintf (string3, " ");
834                 }
835                 if (tutorialstage == 37) {
836                     sprintf (string, "Now spar with the enemy for %d more seconds.", (int)(tutorialmaxtime - tutorialstagetime));
837                     sprintf (string2, "Damage dealt: %d", (int)damagedealt);
838                     sprintf (string3, "Damage taken: %d.", (int)damagetaken);
839                 }
840                 if (tutorialstage == 38) {
841                     sprintf (string, "WEAPONS:");
842                     sprintf (string2, " ");
843                     sprintf (string3, " ");
844                 }
845                 if (tutorialstage == 39) {
846                     sprintf (string, "There is now an imaginary knife");
847                     sprintf (string2, "in the center of the training area.");
848                     sprintf (string3, " ");
849                 }
850                 if (tutorialstage == 40) {
851                     sprintf (string, "Stand, roll or handspring over the knife");
852                     sprintf (string2, "while pressing %s to pick it up.", Input::keyToChar(throwkey));
853                     sprintf (string3, "You can crouch and press the same key to drop it again.");
854                 }
855                 if (tutorialstage == 41) {
856                     sprintf (string, "You can equip and unequip weapons using the %s key.", Input::keyToChar(drawkey));
857                     sprintf (string2, "Sometimes it is best to keep them unequipped to");
858                     sprintf (string3, "prevent enemies from taking them. ");
859                 }
860                 if (tutorialstage == 42) {
861                     sprintf (string, "The knife is the smallest weapon and the least encumbering.");
862                     sprintf (string2, "You can equip or unequip it while standing, crouching,");
863                     sprintf (string3, "running or flipping.");
864                 }
865                 if (tutorialstage == 43) {
866                     sprintf (string, "You perform weapon attacks the same way as unarmed attacks,");
867                     sprintf (string2, "but sharp weapons cause permanent damage, instead of the");
868                     sprintf (string3, "temporary trauma from blunt weapons, fists and feet.");
869                 }
870                 if (tutorialstage == 44) {
871                     sprintf (string, "The enemy now has your knife!");
872                     sprintf (string2, "Please reverse two of his knife attacks.");
873                     sprintf (string3, " ");
874                 }
875                 if (tutorialstage == 45) {
876                     sprintf (string, "Please reverse one more of his knife attacks.");
877                     sprintf (string2, " ");
878                     sprintf (string3, " ");
879                 }
880                 if (tutorialstage == 46) {
881                     sprintf (string, "Now he has a sword!");
882                     sprintf (string2, "The sword has longer reach than your arms, so you");
883                     sprintf (string3, "must move close to reverse the sword slash.");
884                 }
885                 if (tutorialstage == 47) {
886                     sprintf (string, "Long weapons like the sword and staff are also useful for defense;");
887                     sprintf (string2, "you can parry enemy weapon attacks by pressing the attack key");
888                     sprintf (string3, "at the right time. Please try parrying the enemy's attacks!");
889                 }
890                 if (tutorialstage == 48) {
891                     sprintf (string, "The staff is like the sword, but has two main attacks.");
892                     sprintf (string2, "The standing smash is fast and effective, and the running");
893                     sprintf (string3, "spin smash is slower and more powerful.");
894                 }
895                 if (tutorialstage == 49) {
896                     sprintf (string, "When facing an enemy, you can throw the knife with %s.", Input::keyToChar(throwkey));
897                     sprintf (string2, "It is possible to throw the knife while flipping,");
898                     sprintf (string3, "but it is very inaccurate.");
899                 }
900                 if (tutorialstage == 50) {
901                     sprintf (string, "You now know everything you can learn from training.");
902                     sprintf (string2, "Everything else you must learn from experience!");
903                     sprintf (string3, " ");
904                 }
905                 if (tutorialstage == 51) {
906                     sprintf (string, "Walk out of the training area to return to the main menu.");
907                     sprintf (string2, " ");
908                     sprintf (string3, " ");
909                 }
910
911                 glColor4f(0, 0, 0, tutorialopac);
912                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string)*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
913                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5 - 20 * screenwidth / 1024, string2, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
914                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5 - 40 * screenwidth / 1024, string3, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
915                 glColor4f(1, 1, 1, tutorialopac);
916                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
917                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
918                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 40 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
919
920                 sprintf (string, "Press 'tab' to skip to the next item.", Input::keyToChar(jumpkey));
921                 sprintf (string2, "Press escape at any time to");
922                 sprintf (string3, "pause or exit the tutorial.");
923
924                 glColor4f(0, 0, 0, 1);
925                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string)*screenwidth / 1024 * .8 - 4, 0 - 4 + screenheight * 1 / 10, string, 1, 1.5 * 1.25 * screenwidth / 1024 * .8, screenwidth, screenheight);
926                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024 * .8 - 4, 0 - 4 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * 1.25 * screenwidth / 1024 * .8, screenwidth, screenheight);
927                 text->glPrintOutline(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024 * .8 - 4, 0 - 4 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * 1.25 * screenwidth / 1024 * .8, screenwidth, screenheight);
928                 glColor4f(0.5, 0.5, 0.5, 1);
929                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string)*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10, string, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
930                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string2)*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
931                 text->glPrint(screenwidth / 2 - 7.6 * strlen(string3)*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
932             }
933             //Hot spots
934
935             if (numhotspots && (bonustime >= 1 || bonus <= 0 || bonustime < 0) && !tutoriallevel) {
936                 int closest = -1;
937                 float closestdist = -1;
938                 float distance = 0;
939                 closest = currenthotspot;
940                 for (i = 0; i < numhotspots; i++) {
941                     distance = distsq(&player[0].coords, &hotspot[i]);
942                     if (closestdist == -1 || distance < closestdist) {
943                         if (distsq(&player[0].coords, &hotspot[i]) < hotspotsize[i] && ((hotspottype[i] <= 10 && hotspottype[i] >= 0) || (hotspottype[i] <= 40 && hotspottype[i] >= 20))) {
944                             closestdist = distance;
945                             closest = i;
946                         }
947                     }
948                 }
949                 if (closest != -1)
950                     currenthotspot = closest;
951                 if (currenthotspot != -1) {
952                     if (hotspottype[closest] <= 10) {
953                         if (distsq(&player[0].coords, &hotspot[closest]) < hotspotsize[closest])
954                             tutorialstagetime = 0;
955                         tutorialmaxtime = 1;
956                         tutorialopac = tutorialmaxtime - tutorialstagetime;
957                         if (tutorialopac > 1)
958                             tutorialopac = 1;
959                         if (tutorialopac < 0)
960                             tutorialopac = 0;
961
962                         sprintf (string, "%s", hotspottext[closest]);
963
964                         int lastline = 0;
965                         int line = 0;
966                         bool done = false;
967                         i = 0;
968                         while (!done) {
969                             if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') {
970                                 glColor4f(0, 0, 0, tutorialopac);
971                                 text->glPrintOutline(screenwidth / 2 - 7.6 * (i - lastline)*screenwidth / 1024 - 4, screenheight / 16 - 4 + screenheight * 4 / 5 - 20 * screenwidth / 1024 * line, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
972                                 glColor4f(1, 1, 1, tutorialopac);
973                                 text->glPrint(screenwidth / 2 - 7.6 * (i - lastline)*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
974                                 lastline = i + 1;
975                                 line++;
976                                 if (string[i] == '\0')
977                                     done = 1;
978                             }
979                             if (i >= 255)
980                                 done = 1;
981                             i++;
982                         }
983                     } else if (hotspottype[closest] >= 20 && dialoguegonethrough[hotspottype[closest] - 20] == 0) {
984                         whichdialogue = hotspottype[closest] - 20;
985                         for (j = 0; j < numdialogueboxes[whichdialogue]; j++) {
986                             player[participantfocus[whichdialogue][j]].coords = participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
987                             player[participantfocus[whichdialogue][j]].yaw = participantyaw[whichdialogue][participantfocus[whichdialogue][j]];
988                             player[participantfocus[whichdialogue][j]].targetyaw = participantyaw[whichdialogue][participantfocus[whichdialogue][j]];
989                             player[participantfocus[whichdialogue][j]].velocity = 0;
990                             player[participantfocus[whichdialogue][j]].animTarget = player[participantfocus[whichdialogue][j]].getIdle();
991                             player[participantfocus[whichdialogue][j]].frameTarget = 0;
992                         }
993                         directing = 0;
994                         indialogue = 0;
995                         dialoguegonethrough[whichdialogue]++;
996                         if (dialogueboxsound[whichdialogue][indialogue] != 0) {
997                             int whichsoundplay;
998                             if (dialogueboxsound[whichdialogue][indialogue] == 1) whichsoundplay = rabbitchitter;
999                             if (dialogueboxsound[whichdialogue][indialogue] == 2) whichsoundplay = rabbitchitter2;
1000                             if (dialogueboxsound[whichdialogue][indialogue] == 3) whichsoundplay = rabbitpainsound;
1001                             if (dialogueboxsound[whichdialogue][indialogue] == 4) whichsoundplay = rabbitpain1sound;
1002                             if (dialogueboxsound[whichdialogue][indialogue] == 5) whichsoundplay = rabbitattacksound;
1003                             if (dialogueboxsound[whichdialogue][indialogue] == 6) whichsoundplay = rabbitattack2sound;
1004                             if (dialogueboxsound[whichdialogue][indialogue] == 7) whichsoundplay = rabbitattack3sound;
1005                             if (dialogueboxsound[whichdialogue][indialogue] == 8) whichsoundplay = rabbitattack4sound;
1006                             if (dialogueboxsound[whichdialogue][indialogue] == 9) whichsoundplay = growlsound;
1007                             if (dialogueboxsound[whichdialogue][indialogue] == 10) whichsoundplay = growl2sound;
1008                             if (dialogueboxsound[whichdialogue][indialogue] == 11) whichsoundplay = snarlsound;
1009                             if (dialogueboxsound[whichdialogue][indialogue] == 12) whichsoundplay = snarl2sound;
1010                             if (dialogueboxsound[whichdialogue][indialogue] == 13) whichsoundplay = barksound;
1011                             if (dialogueboxsound[whichdialogue][indialogue] == 14) whichsoundplay = bark2sound;
1012                             if (dialogueboxsound[whichdialogue][indialogue] == 15) whichsoundplay = bark3sound;
1013                             if (dialogueboxsound[whichdialogue][indialogue] == 16) whichsoundplay = barkgrowlsound;
1014                             if (dialogueboxsound[whichdialogue][indialogue] == -1) whichsoundplay = fireendsound;
1015                             if (dialogueboxsound[whichdialogue][indialogue] == -2) whichsoundplay = firestartsound;
1016                             if (dialogueboxsound[whichdialogue][indialogue] == -3) whichsoundplay = consolesuccesssound;
1017                             if (dialogueboxsound[whichdialogue][indialogue] == -4) whichsoundplay = consolefailsound;
1018                             emit_sound_at(whichsoundplay, player[participantfocus[whichdialogue][indialogue]].coords);
1019                         }
1020                     }
1021                 }
1022             }
1023
1024             if (indialogue != -1 && !mainmenu) {
1025                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1026                 glDisable(GL_CULL_FACE);
1027                 glDisable(GL_LIGHTING);
1028                 glDisable(GL_TEXTURE_2D);
1029                 glDepthMask(0);
1030                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1031                 glPushMatrix();                                                                         // Store The Projection Matrix
1032                 glLoadIdentity();                                                                       // Reset The Projection Matrix
1033                 glOrtho(0, screenwidth, 0, screenheight, -100, 100);                                            // Set Up An Ortho Screen
1034                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1035                 glPushMatrix();                                                                         // Store The Modelview Matrix
1036                 glLoadIdentity();                                                               // Reset The Modelview Matrix
1037                 if (dialogueboxlocation[whichdialogue][indialogue] == 1)
1038                     glTranslatef(0, screenheight * 3 / 4, 0);
1039                 glScalef(screenwidth, screenheight / 4, 1);
1040                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1041                 glEnable(GL_BLEND);
1042
1043                 glColor4f(dialogueboxcolor[whichdialogue][indialogue][0], dialogueboxcolor[whichdialogue][indialogue][1], dialogueboxcolor[whichdialogue][indialogue][2], 0.7);
1044                 glBegin(GL_QUADS);
1045                 glVertex3f(0,           0,       0.0f);
1046                 glVertex3f(1,   0,       0.0f);
1047                 glVertex3f(1,   1, 0.0f);
1048                 glVertex3f(0,   1, 0.0f);
1049                 glEnd();
1050                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1051                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
1052                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1053                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
1054                 glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1055                 glEnable(GL_CULL_FACE);
1056                 glDisable(GL_BLEND);
1057                 glDepthMask(1);
1058                 glEnable(GL_TEXTURE_2D);
1059
1060                 tutorialopac = 1;
1061
1062                 float startx;
1063                 float starty;
1064
1065                 startx = screenwidth * 1 / 5;
1066                 if (dialogueboxlocation[whichdialogue][indialogue] == 1)
1067                     starty = screenheight / 16 + screenheight * 4 / 5;
1068                 if (dialogueboxlocation[whichdialogue][indialogue] == 2)
1069                     starty = screenheight * 1 / 5 - screenheight / 16;
1070
1071                 char tempname[264];
1072                 bool goodchar;
1073                 int tempnum = 0;
1074                 for (i = 0; i < 264; i++) {
1075                     tempname[i] = '\0';
1076                 }
1077
1078                 for (i = 0; i < (int)strlen(dialoguename[whichdialogue][indialogue]); i++) {
1079                     tempname[tempnum] = dialoguename[whichdialogue][indialogue][i];
1080                     goodchar = 1;
1081                     if (dialoguename[whichdialogue][indialogue][i] == '#' || dialoguename[whichdialogue][indialogue][i] == '\0')
1082                         goodchar = 0;
1083                     if (goodchar)
1084                         tempnum++;
1085                     else
1086                         tempname[tempnum] = '\0';
1087                 }
1088
1089                 sprintf (string, "%s: ", tempname);
1090
1091                 if (dialogueboxcolor[whichdialogue][indialogue][0] + dialogueboxcolor[whichdialogue][indialogue][1] + dialogueboxcolor[whichdialogue][indialogue][2] < 1.5) {
1092                     glColor4f(0, 0, 0, tutorialopac);
1093                     text->glPrintOutline(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
1094                     glColor4f(0.7, 0.7, 0.7, tutorialopac);
1095                     text->glPrint(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024, starty, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
1096                 } else {
1097                     glColor4f(0, 0, 0, tutorialopac);
1098                     text->glPrintOutline(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight);
1099                 }
1100
1101                 tempnum = 0;
1102                 for (i = 0; i < (int)strlen(dialoguetext[whichdialogue][indialogue]) + 1; i++) {
1103                     tempname[tempnum] = dialoguetext[whichdialogue][indialogue][i];
1104                     if (dialoguetext[whichdialogue][indialogue][i] != '#')
1105                         tempnum++;
1106                 }
1107
1108                 sprintf (string, "%s", tempname);
1109
1110                 int lastline = 0;
1111                 int line = 0;
1112                 bool done = false;
1113                 i = 0;
1114                 while (!done) {
1115                     if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') {
1116                         if (dialogueboxcolor[whichdialogue][indialogue][0] + dialogueboxcolor[whichdialogue][indialogue][1] + dialogueboxcolor[whichdialogue][indialogue][2] < 1.5) {
1117                             glColor4f(0, 0, 0, tutorialopac);
1118                             text->glPrintOutline(startx/*-7.6*(i-lastline)*screenwidth/1024*/ - 4, starty - 4 - 20 * screenwidth / 1024 * line, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
1119                             glColor4f(1, 1, 1, tutorialopac);
1120                             text->glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
1121                         } else {
1122                             glColor4f(0, 0, 0, tutorialopac);
1123                             text->glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/, starty - 20 * screenwidth / 1024 * line, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight, lastline, i);
1124                         }
1125                         lastline = i + 1;
1126                         line++;
1127                         if (string[i] == '\0')
1128                             done = 1;
1129                     }
1130                     if (i >= 255)
1131                         done = 1;
1132                     i++;
1133                 }
1134             }
1135
1136             if (!tutoriallevel && !winfreeze && indialogue == -1 && !mainmenu) {
1137                 if (campaign) {
1138                     if (scoreadded)
1139                         sprintf (string, "Score: %d", (int)accountactive->getCampaignScore());
1140                     else
1141                         sprintf (string, "Score: %d", (int)accountactive->getCampaignScore() + (int)bonustotal);
1142                 }
1143                 if (!campaign)
1144                     sprintf (string, "Score: %d", (int)bonustotal);
1145                 glColor4f(0, 0, 0, 1);
1146                 text->glPrintOutline(1024 / 40 - 4, 768 / 16 - 4 + 768 * 14 / 16, string, 1, 1.5 * 1.25, 1024, 768);
1147                 glColor4f(1, 0, 0, 1);
1148                 text->glPrint(1024 / 40, 768 / 16 + 768 * 14 / 16, string, 1, 1.5, 1024, 768);
1149                 if (showdamagebar) {
1150                     glDisable(GL_DEPTH_TEST);                                                   // Disables Depth Testing
1151                     glDisable(GL_CULL_FACE);
1152                     glDisable(GL_LIGHTING);
1153                     glDisable(GL_TEXTURE_2D);
1154                     glDepthMask(0);
1155                     glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
1156                     glPushMatrix();                                                                             // Store The Projection Matrix
1157                     glLoadIdentity();                                                                   // Reset The Projection Matrix
1158                     glOrtho(0, screenwidth, 0, screenheight, -100, 100);                // Set Up An Ortho Screen
1159                     glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1160                     glPushMatrix();                                                                             // Store The Modelview Matrix
1161                     glLoadIdentity();                                                                   // Reset The Modelview Matrix
1162                     glTranslatef(15, screenheight * 17.5 / 20, 0);
1163                     glScalef(screenwidth / 3 + 20, screenheight / 20, 1);
1164                     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1165                     glEnable(GL_BLEND);
1166                     glColor4f(0.0, 0.4, 0.0, 0.7);
1167                     float bar = ((float)player[0].damage) / player[0].damagetolerance;
1168                     glBegin(GL_QUADS);
1169                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1170                     glVertex3f(1, 0, 0.0f);
1171                     glVertex3f(1, 1, 0.0f);
1172                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1173                     glEnd();
1174                     glColor4f(0.1, 0.0, 0.0, 1);
1175                     bar = ((float)player[0].bloodloss) / player[0].damagetolerance;
1176                     glBegin(GL_QUADS);
1177                     glVertex3f(0, 0, 0.0f);
1178                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1179                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1180                     glVertex3f(0, 1, 0.0f);
1181                     glEnd();
1182                     glColor4f(0.4, 0.0, 0.0, 0.7);
1183                     bar = ((float)player[0].damage) / player[0].damagetolerance;
1184                     glBegin(GL_QUADS);
1185                     glVertex3f(0, 0, 0.0f);
1186                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1187                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1188                     glVertex3f(0, 1, 0.0f);
1189                     glEnd();
1190                     glColor4f(0.4, 0.0, 0.0, 0.7);
1191                     bar = ((float)player[0].permanentdamage) / player[0].damagetolerance;
1192                     glBegin(GL_QUADS);
1193                     glVertex3f(0, 0, 0.0f);
1194                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1195                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1196                     glVertex3f(0, 1, 0.0f);
1197                     glEnd();
1198                     glColor4f(0.4, 0.0, 0.0, 0.7);
1199                     bar = ((float)player[0].superpermanentdamage) / player[0].damagetolerance;
1200                     glBegin(GL_QUADS);
1201                     glVertex3f(0, 0, 0.0f);
1202                     glVertex3f((bar < 1 ? bar : 1), 0, 0.0f);
1203                     glVertex3f((bar < 1 ? bar : 1), 1, 0.0f);
1204                     glVertex3f(0, 1, 0.0f);
1205                     glEnd();
1206                     glColor4f(0.0, 0.0, 0.0, 0.7);
1207                     glLineWidth(2.0);
1208                     glBegin(GL_LINE_STRIP);
1209                     glVertex3f(0, 0, 0.0f);
1210                     glVertex3f(1, 0, 0.0f);
1211                     glVertex3f(1, 1, 0.0f);
1212                     glVertex3f(0, 1, 0.0f);
1213                     glVertex3f(0, 0, 0.0f);
1214                     glEnd();
1215
1216                     glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
1217                     glPopMatrix();                                                                              // Restore The Old Projection Matrix
1218                     glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1219                     glPopMatrix();                                                                              // Restore The Old Projection Matrix
1220                     glEnable(GL_DEPTH_TEST);                                                    // Enables Depth Testing
1221                     glEnable(GL_CULL_FACE);
1222                     glDisable(GL_BLEND);
1223                     glDepthMask(1);
1224                     glEnable(GL_TEXTURE_2D);
1225
1226                     // writing the numbers :
1227                     sprintf (string, "Damages : %d/%d (%d)", (int)(player[0].damage), (int)(player[0].damagetolerance), (int)(player[0].bloodloss));
1228                     glColor4f(0, 0, 0, 1);
1229                     text->glPrintOutline(1024 / 40 - 4, 768 / 16 - 4 + 768 * 14 / 16 - 40, string, 1, 1.5 * 1.25, 1024, 768);
1230                     glColor4f(1, 0, 0, 1);
1231                     text->glPrint(1024 / 40, 768 / 16 + 768 * 14 / 16 - 40, string, 1, 1.5, 1024, 768);
1232                 }
1233             }
1234
1235             glColor4f(.5, .5, .5, 1);
1236
1237
1238             if ((texttoggle || editorenabled) && debugmode && !mainmenu) {
1239                 sprintf (string, "The framespersecond is %d.", (int)(fps));
1240                 text->glPrint(10, 30, string, 0, .8, 1024, 768);
1241
1242                 if (editorenabled)
1243                     sprintf (string, "Map editor enabled.");
1244                 else
1245                     sprintf (string, "Map editor disabled.");
1246                 text->glPrint(10, 60, string, 0, .8, 1024, 768);
1247                 if (editorenabled) {
1248                     sprintf (string, "Object size: %f", editorsize);
1249                     text->glPrint(10, 75, string, 0, .8, 1024, 768);
1250                     if (editoryaw >= 0)
1251                         sprintf (string, "Object yaw: %f", editoryaw);
1252                     else
1253                         sprintf (string, "Object yaw: Random");
1254                     text->glPrint(10, 90, string, 0, .8, 1024, 768);
1255                     if (editorpitch >= 0)
1256                         sprintf (string, "Object pitch: %f", editorpitch);
1257                     else
1258                         sprintf (string, "Object pitch: Random");
1259                     text->glPrint(10, 105, string, 0, .8, 1024, 768);
1260                     sprintf (string, "Object type: %d", editortype);
1261                     text->glPrint(10, 120, string, 0, .8, 1024, 768);
1262                     switch (editortype) {
1263                     case boxtype:
1264                         sprintf (string, "(box)");
1265                         break;
1266                     case treetrunktype:
1267                         sprintf (string, "(tree)");
1268                         break;
1269                     case walltype:
1270                         sprintf (string, "(wall)");
1271                         break;
1272                     case weirdtype:
1273                         sprintf (string, "(weird)");
1274                         break;
1275                     case spiketype:
1276                         sprintf (string, "(spike)");
1277                         break;
1278                     case rocktype:
1279                         sprintf (string, "(rock)");
1280                         break;
1281                     case bushtype:
1282                         sprintf (string, "(bush)");
1283                         break;
1284                     case tunneltype:
1285                         sprintf (string, "(tunnel)");
1286                         break;
1287                     case chimneytype:
1288                         sprintf (string, "(chimney)");
1289                         break;
1290                     case platformtype:
1291                         sprintf (string, "(platform)");
1292                         break;
1293                     case cooltype:
1294                         sprintf (string, "(cool)");
1295                         break;
1296                     case firetype:
1297                         sprintf (string, "(fire)");
1298                         break;
1299                     }
1300                     text->glPrint(130, 120, string, 0, .8, 1024, 768);
1301
1302                     sprintf (string, "Numplayers: %d", numplayers);
1303                     text->glPrint(10, 155, string, 0, .8, 1024, 768);
1304                     sprintf (string, "Player %d: numwaypoints: %d", numplayers, player[numplayers - 1].numwaypoints);
1305                     text->glPrint(10, 140, string, 0, .8, 1024, 768);
1306                 }
1307                 sprintf (string, "Difficulty: %d", difficulty);
1308                 text->glPrint(10, 240, string, 0, .8, 1024, 768);
1309
1310             }
1311         }
1312
1313         if (drawmode == glowmode) {
1314             glDisable(GL_DEPTH_TEST);                                                   // Disables Depth Testing
1315             glDisable(GL_CULL_FACE);
1316             glDisable(GL_LIGHTING);
1317             glDisable(GL_TEXTURE_2D);
1318             glDepthMask(0);
1319             glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
1320             glPushMatrix();                                                                             // Store The Projection Matrix
1321             glLoadIdentity();                                                                   // Reset The Projection Matrix
1322             glOrtho(0, screenwidth, 0, screenheight, -100, 100);                                                // Set Up An Ortho Screen
1323             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1324             glPushMatrix();                                                                             // Store The Modelview Matrix
1325             glLoadIdentity();                                                           // Reset The Modelview Matrix
1326             glScalef(screenwidth, screenheight, 1);
1327             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1328             glEnable(GL_BLEND);
1329             glColor4f(0, 0, 0, .5);
1330             glBegin(GL_QUADS);
1331             glVertex3f(0,               0,       0.0f);
1332             glVertex3f(256,     0,       0.0f);
1333             glVertex3f(256,     256, 0.0f);
1334             glVertex3f(0,       256, 0.0f);
1335             glEnd();
1336             glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
1337             glPopMatrix();                                                                              // Restore The Old Projection Matrix
1338             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1339             glPopMatrix();                                                                              // Restore The Old Projection Matrix
1340             glEnable(GL_DEPTH_TEST);                                                    // Enables Depth Testing
1341             glEnable(GL_CULL_FACE);
1342             glDisable(GL_BLEND);
1343             glDepthMask(1);
1344         }
1345
1346         if ((((blackout && damageeffects) || (player[0].bloodloss > 0 && damageeffects && player[0].blooddimamount > 0) || player[0].dead) && !cameramode) || console) {
1347             glDisable(GL_DEPTH_TEST);                                                   // Disables Depth Testing
1348             glDisable(GL_CULL_FACE);
1349             glDisable(GL_LIGHTING);
1350             glDisable(GL_TEXTURE_2D);
1351             glDepthMask(0);
1352             glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
1353             glPushMatrix();                                                                             // Store The Projection Matrix
1354             glLoadIdentity();                                                                   // Reset The Projection Matrix
1355             glOrtho(0, screenwidth, 0, screenheight, -100, 100);                                                // Set Up An Ortho Screen
1356             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1357             glPushMatrix();                                                                             // Store The Modelview Matrix
1358             glLoadIdentity();                                                           // Reset The Modelview Matrix
1359             glScalef(screenwidth, screenheight, 1);
1360             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1361             glEnable(GL_BLEND);
1362             if (player[0].dead)
1363                 blackout += multiplier * 3;
1364             if (player[0].dead == 1)
1365                 blackout = .4f;
1366             if (player[0].dead == 2 && blackout > .6)
1367                 blackout = .6;
1368             glColor4f(0, 0, 0, blackout);
1369             if (!player[0].dead) {
1370                 if ((player[0].bloodloss / player[0].damagetolerance * (sin(woozy) / 4 + .5))*.3 < .3) {
1371                     glColor4f(0, 0, 0, player[0].blooddimamount * player[0].bloodloss / player[0].damagetolerance * (sin(woozy) / 4 + .5)*.3);
1372                     blackout = player[0].blooddimamount * player[0].bloodloss / player[0].damagetolerance * (sin(woozy) / 4 + .5) * .3;
1373                 } else {
1374                     glColor4f(0, 0, 0, player[0].blooddimamount * .3);
1375                     blackout = player[0].blooddimamount * .3;
1376                 }
1377             }
1378             if (console)
1379                 glColor4f(.7, 0, 0, .2);
1380             glBegin(GL_QUADS);
1381             glVertex3f(0,               0,       0.0f);
1382             glVertex3f(256,     0,       0.0f);
1383             glVertex3f(256,     256, 0.0f);
1384             glVertex3f(0,       256, 0.0f);
1385             glEnd();
1386             glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
1387             glPopMatrix();                                                                              // Restore The Old Projection Matrix
1388             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1389             glPopMatrix();                                                                              // Restore The Old Projection Matrix
1390             glEnable(GL_DEPTH_TEST);                                                    // Enables Depth Testing
1391             glEnable(GL_CULL_FACE);
1392             glDisable(GL_BLEND);
1393             glDepthMask(1);
1394         }
1395
1396         if (flashamount > 0 && damageeffects) {
1397             if (flashamount > 1)
1398                 flashamount = 1;
1399             if (flashdelay <= 0)
1400                 flashamount -= multiplier;
1401             flashdelay--;
1402             if (flashamount < 0)
1403                 flashamount = 0;
1404             glDisable(GL_DEPTH_TEST);                                                   // Disables Depth Testing
1405             glDisable(GL_CULL_FACE);
1406             glDisable(GL_LIGHTING);
1407             glDepthMask(0);
1408             glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
1409             glPushMatrix();                                                                             // Store The Projection Matrix
1410             glLoadIdentity();                                                                   // Reset The Projection Matrix
1411             glOrtho(0, screenwidth, 0, screenheight, -100, 100);                                                // Set Up An Ortho Screen
1412             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1413             glPushMatrix();                                                                             // Store The Modelview Matrix
1414             glLoadIdentity();                                                           // Reset The Modelview Matrix
1415             glScalef(screenwidth, screenheight, 1);
1416             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1417             glEnable(GL_BLEND);
1418             glColor4f(flashr, flashg, flashb, flashamount);
1419             glBegin(GL_QUADS);
1420             glVertex3f(0,               0,       0.0f);
1421             glVertex3f(256,     0,       0.0f);
1422             glVertex3f(256,     256, 0.0f);
1423             glVertex3f(0,       256, 0.0f);
1424             glEnd();
1425             glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
1426             glPopMatrix();                                                                              // Restore The Old Projection Matrix
1427             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1428             glPopMatrix();                                                                              // Restore The Old Projection Matrix
1429             glEnable(GL_DEPTH_TEST);                                                    // Enables Depth Testing
1430             glEnable(GL_CULL_FACE);
1431             glDisable(GL_BLEND);
1432             glDepthMask(1);
1433         }
1434
1435         if (!console) {
1436             displaytime[0] = 0;
1437             glEnable(GL_TEXTURE_2D);
1438             glColor4f(1, 1, 1, 1);
1439             if (chatting) {
1440                 sprintf (string, " ]");
1441                 text->glPrint(10, 30 + screenheight - 330, string, 0, 1, screenwidth, screenheight);
1442                 if (displayblink) {
1443                     sprintf (string, "_");
1444                     text->glPrint(30 + (float)(displayselected) * 10, 30 + (screenheight - 330), string, 0, 1, screenwidth, screenheight);
1445                 }
1446             }
1447             for (i = 0; i < 15; i++)
1448                 if ((i != 0 || chatting) && displaytime[i] < 4)
1449                     for (j = 0; j < displaychars[i]; j++) {
1450                         glColor4f(1, 1, 1, 4 - displaytime[i]);
1451                         if (j < displaychars[i]) {
1452                             sprintf (string, "%c", displaytext[i][j]);
1453                             text->glPrint(30 + j * 10, 30 + i * 20 + (screenheight - 330), string, 0, 1, screenwidth, screenheight);
1454                         }
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);                                                   // Disables Depth Testing
1468             glDisable(GL_CULL_FACE);
1469             glDisable(GL_LIGHTING);
1470             glDepthMask(0);
1471             glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
1472             glPushMatrix();                                                                             // Store The Projection Matrix
1473             glLoadIdentity();                                                                   // Reset The Projection Matrix
1474             glOrtho(0, screenwidth, 0, screenheight, -100, 100);                                                // Set Up An Ortho Screen
1475             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1476             glPushMatrix();                                                                             // Store The Modelview Matrix
1477             glLoadIdentity();                                                           // Reset The Modelview Matrix
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 < numplayers; i++) {
1491                 if (!player[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 < numplayers; i++) {
1504                 if (!player[i].dead)
1505                     center += player[i].coords;
1506             }
1507             center /= numadd + numliveplayers;
1508
1509             center = player[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 < numplayers; i++) {
1522                 if (!player[i].dead) {
1523                     tempdist = distsq(&center, &player[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(player[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(&player[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(&player[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 < numplayers; i++) {
1607                 distcheck = distsq(&player[0].coords, &player[i].coords);
1608                 if (distcheck < mapviewdist) {
1609                     glPushMatrix();
1610                     Maparrowtexture.bind();
1611                     if (i == 0)
1612                         glColor4f(1, 1, 1, opac);
1613                     else if (player[i].dead == 2 || player[i].howactive > typesleeping)
1614                         glColor4f(0, 0, 0, opac * (1 - distcheck / mapviewdist));
1615                     else if (player[i].dead)
1616                         glColor4f(.3, .3, .3, opac * (1 - distcheck / mapviewdist));
1617                     else if (player[i].aitype == attacktypecutoff)
1618                         glColor4f(1, 0, 0, opac * (1 - distcheck / mapviewdist));
1619                     else if (player[i].aitype == passivetype)
1620                         glColor4f(0, 1, 0, opac * (1 - distcheck / mapviewdist));
1621                     else
1622                         glColor4f(1, 1, 0, 1);
1623                     glTranslatef(player[i].coords.x / terrain.scale / 256 * -2 + 1, player[i].coords.z / terrain.scale / 256 * 2 - 1, 0);
1624                     glRotatef(player[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);                                                // Select The Projection Matrix
1642             glPopMatrix();                                                                              // Restore The Old Projection Matrix
1643             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1644             glPopMatrix();                                                                              // Restore The Old Projection Matrix
1645             glEnable(GL_DEPTH_TEST);                                                    // Enables Depth Testing
1646             glEnable(GL_CULL_FACE);
1647             glDisable(GL_BLEND);
1648             glDepthMask(1);
1649         }
1650
1651         if (loading && !stealthloading && (!campaign || player[0].dead)) {
1652             glDisable(GL_DEPTH_TEST);                                                   // Disables Depth Testing
1653             glDisable(GL_CULL_FACE);
1654             glDisable(GL_LIGHTING);
1655             glDisable(GL_TEXTURE_2D);
1656             glDepthMask(0);
1657             glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
1658             glPushMatrix();                                                                             // Store The Projection Matrix
1659             glLoadIdentity();                                                                   // Reset The Projection Matrix
1660             glOrtho(0, screenwidth, 0, screenheight, -100, 100);                                                // Set Up An Ortho Screen
1661             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1662             glPushMatrix();                                                                             // Store The Modelview Matrix
1663             glLoadIdentity();                                                           // Reset The Modelview Matrix
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);                                                // Select The Projection Matrix
1675             glPopMatrix();                                                                              // Restore The Old Projection Matrix
1676             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1677             glPopMatrix();                                                                              // Restore The Old Projection Matrix
1678             glEnable(GL_DEPTH_TEST);                                                    // Enables Depth Testing
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);                                                   // Disables Depth Testing
1704             glDisable(GL_CULL_FACE);
1705             glDisable(GL_LIGHTING);
1706             glDisable(GL_TEXTURE_2D);
1707             glDepthMask(0);
1708             glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
1709             glPushMatrix();                                                                             // Store The Projection Matrix
1710             glLoadIdentity();                                                                   // Reset The Projection Matrix
1711             glOrtho(0, screenwidth, 0, screenheight, -100, 100);                                                // Set Up An Ortho Screen
1712             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1713             glPushMatrix();                                                                             // Store The Modelview Matrix
1714             glLoadIdentity();                                                           // Reset The Modelview Matrix
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);                                                // Select The Projection Matrix
1726             glPopMatrix();                                                                              // Restore The Old Projection Matrix
1727             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1728             glPopMatrix();                                                                              // Restore The Old Projection Matrix
1729             glEnable(GL_DEPTH_TEST);                                                    // Enables Depth Testing
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);                                                   // Disables Depth Testing
1832             glDisable(GL_CULL_FACE);
1833             glDisable(GL_LIGHTING);
1834             glDepthMask(0);
1835             glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
1836             glPushMatrix();                                                                             // Store The Projection Matrix
1837             glLoadIdentity();                                                                   // Reset The Projection Matrix
1838             glOrtho(0, screenwidth, 0, screenheight, -100, 100);                                                // Set Up An Ortho Screen
1839             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
1840             glPushMatrix();                                                                             // Store The Modelview Matrix
1841             glLoadIdentity();                                                           // Reset The Modelview Matrix
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(player[0].damage - player[0].superpermanentdamage - (player[0].damagetolerance - player[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);                                                // Select The Projection Matrix
2017             glPopMatrix();                                                                              // Restore The Old Projection Matrix
2018             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
2019             glPopMatrix();                                                                              // Restore The Old Projection Matrix
2020             glEnable(GL_DEPTH_TEST);                                                    // Enables Depth Testing
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 < consolechars[i]; j++) {
2040                     glColor4f(1, 1, 1, 1 - (float)(i) / 16);
2041                     if (j < consolechars[i]) {
2042                         sprintf (string, "%c", consoletext[i][j]);
2043                         text->glPrint(30 + j * 10 - offset * 10, 30 + i * 20, string, 0, 1, 1024, 768);
2044                     }
2045                 }
2046         }
2047     }
2048
2049     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
2050         multiplier = tempmult;
2051     }
2052
2053     if (mainmenu) {
2054         DrawMenu();
2055     }
2056
2057     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
2058         tempmult = multiplier;
2059         multiplier = 0;
2060     }
2061
2062     //glFlush();
2063     if ( side == stereoRight || side == stereoCenter ) {
2064         if (drawmode != motionblurmode || mainmenu) {
2065             swap_gl_buffers();
2066         }
2067     }
2068
2069     //myassert(glGetError() == GL_NO_ERROR);
2070     glDrawBuffer(GL_BACK);
2071     glReadBuffer(GL_BACK);
2072     //glFlush();
2073
2074     weapons.DoStuff();
2075
2076     if (drawtoggle == 2)
2077         drawtoggle = 0;
2078
2079     if (freeze || winfreeze || (mainmenu && gameon) || (!gameon && gamestarted)) {
2080         multiplier = tempmult;
2081     }
2082     //Jordan fixed your warning!
2083     return 0;
2084 }
2085
2086 void DrawMenu()
2087 {
2088     // !!! FIXME: hack: clamp framerate in menu so text input works correctly on fast systems.
2089     SDL_Delay(15);
2090
2091     glDrawBuffer(GL_BACK);
2092     glReadBuffer(GL_BACK);
2093     glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
2094     Game::ReSizeGLScene(90, .1f);
2095
2096     //draw menu background
2097     glClear(GL_DEPTH_BUFFER_BIT);
2098     glEnable(GL_ALPHA_TEST);
2099     glAlphaFunc(GL_GREATER, 0.001f);
2100     glEnable(GL_TEXTURE_2D);
2101     glDisable(GL_DEPTH_TEST);                                                   // Disables Depth Testing
2102     glDisable(GL_CULL_FACE);
2103     glDisable(GL_LIGHTING);
2104     glDepthMask(0);
2105     glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
2106     glPushMatrix();                                                                             // Store The Projection Matrix
2107     glLoadIdentity();                                                                   // Reset The Projection Matrix
2108     glOrtho(0, screenwidth, 0, screenheight, -100, 100);                                                // Set Up An Ortho Screen
2109     glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
2110     glPushMatrix();                                                                             // Store The Modelview Matrix
2111     glLoadIdentity();                                                           // Reset The Modelview Matrix
2112     glTranslatef(screenwidth / 2, screenheight / 2, 0);
2113     glPushMatrix();
2114     glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
2115     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2116     glDisable(GL_BLEND);
2117     glColor4f(0, 0, 0, 1.0);
2118     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2119     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2120     glDisable(GL_TEXTURE_2D);
2121     glBegin(GL_QUADS);
2122     glVertex3f(-1, -1, 0);
2123     glVertex3f(+1, -1, 0);
2124     glVertex3f(+1, +1, 0);
2125     glVertex3f(-1, +1, 0);
2126     glEnd();
2127     glEnable(GL_BLEND);
2128     glColor4f(0.4, 0.4, 0.4, 1.0);
2129     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2130     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2131     glEnable(GL_TEXTURE_2D);
2132     Game::Mainmenuitems[4].bind();
2133     glBegin(GL_QUADS);
2134     glTexCoord2f(0, 0);
2135     glVertex3f(-1, -1, 0);
2136     glTexCoord2f(1, 0);
2137     glVertex3f(+1, -1, 0);
2138     glTexCoord2f(1, 1);
2139     glVertex3f(+1, +1, 0);
2140     glTexCoord2f(0, 1);
2141     glVertex3f(-1, +1, 0);
2142     glEnd();
2143     glPopMatrix();
2144     glPopMatrix();
2145     glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
2146     glPopMatrix();
2147     glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
2148
2149
2150
2151     glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
2152     glPushMatrix();                                                                             // Store The Projection Matrix
2153     glLoadIdentity();                                                                   // Reset The Projection Matrix
2154     glOrtho(0, 640, 0, 480, -100, 100);                                         // Set Up An Ortho Screen
2155     glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
2156     glPushMatrix();                                                                             // Store The Modelview Matrix
2157     glLoadIdentity();                                                           // Reset The Modelview Matrix
2158     glEnable(GL_TEXTURE_2D);
2159
2160     Menu::drawItems();
2161
2162     //draw mouse cursor
2163     glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
2164     glPopMatrix();
2165     glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
2166     glPopMatrix();
2167
2168     glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
2169     glPushMatrix();                                                                             // Store The Projection Matrix
2170     glLoadIdentity();                                                                   // Reset The Projection Matrix
2171     glOrtho(0, screenwidth, 0, screenheight, -100, 100);                                                // Set Up An Ortho Screen
2172     glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
2173     glPushMatrix();                                                                             // Store The Modelview Matrix
2174     glLoadIdentity();                                                           // Reset The Modelview Matrix
2175     glTranslatef(screenwidth / 2, screenheight / 2, 0);
2176     glPushMatrix();
2177     glScalef((float)screenwidth / 2, (float)screenheight / 2, 1);
2178     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2179     glEnable(GL_BLEND);
2180     glEnable(GL_TEXTURE_2D);
2181     glColor4f(1, 1, 1, 1);
2182     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2183     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2184     glPopMatrix();
2185     if (!Game::waiting) { // hide the cursor while waiting for a key
2186         glPushMatrix();
2187         glTranslatef(Game::mousecoordh - screenwidth / 2, Game::mousecoordv * -1 + screenheight / 2, 0);
2188         glScalef((float)screenwidth / 64, (float)screenwidth / 64, 1);
2189         glTranslatef(1, -1, 0);
2190         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2191         glColor4f(1, 1, 1, 1);
2192         Game::cursortexture.bind();
2193         glPushMatrix();
2194         //glScalef(.25,.25,.25);
2195         glBegin(GL_QUADS);
2196         glTexCoord2f(0, 0);
2197         glVertex3f(-1, -1, 0.0f);
2198         glTexCoord2f(1, 0);
2199         glVertex3f(1, -1, 0.0f);
2200         glTexCoord2f(1, 1);
2201         glVertex3f(1, 1, 0.0f);
2202         glTexCoord2f(0, 1);
2203         glVertex3f(-1, 1, 0.0f);
2204         glEnd();
2205         glPopMatrix();
2206         glPopMatrix();
2207     }
2208     glPopMatrix();
2209     glMatrixMode(GL_PROJECTION);                                                // Select The Projection Matrix
2210     glPopMatrix();
2211
2212
2213     //draw screen flash
2214     if (flashamount > 0) {
2215         if (flashamount > 1)
2216             flashamount = 1;
2217         if (flashdelay <= 0)
2218             flashamount -= multiplier;
2219         flashdelay--;
2220         if (flashamount < 0)
2221             flashamount = 0;
2222         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
2223         glDisable(GL_CULL_FACE);
2224         glDisable(GL_LIGHTING);
2225         glDisable(GL_TEXTURE_2D);
2226         glDepthMask(0);
2227         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2228         glPushMatrix();                                                                         // Store The Projection Matrix
2229         glLoadIdentity();                                                                       // Reset The Projection Matrix
2230         glOrtho(0, screenwidth, 0, screenheight, -100, 100);                                            // Set Up An Ortho Screen
2231         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2232         glPushMatrix();                                                                         // Store The Modelview Matrix
2233         glLoadIdentity();                                                               // Reset The Modelview Matrix
2234         glScalef(screenwidth, screenheight, 1);
2235         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2236         glEnable(GL_BLEND);
2237         glColor4f(flashr, flashg, flashb, flashamount);
2238         glBegin(GL_QUADS);
2239         glVertex3f(0,           0,       0.0f);
2240         glVertex3f(256, 0,       0.0f);
2241         glVertex3f(256, 256, 0.0f);
2242         glVertex3f(0,   256, 0.0f);
2243         glEnd();
2244         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2245         glPopMatrix();                                                                          // Restore The Old Projection Matrix
2246         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2247         glPopMatrix();                                                                          // Restore The Old Projection Matrix
2248         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
2249         glEnable(GL_CULL_FACE);
2250         glDisable(GL_BLEND);
2251         glDepthMask(1);
2252     }
2253 }