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