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