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