]> git.jsancho.org Git - lugaru.git/blob - Source/GameDraw.cpp
Various SDL input and Game::* cleanups
[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
26 using namespace std;
27
28 extern XYZ viewer;
29 extern int environment;
30 extern float texscale;
31 extern Light light;
32 extern Terrain terrain;
33 extern Sprites sprites;
34 extern float multiplier;
35 extern float sps;
36 extern float viewdistance;
37 extern float fadestart;
38 extern float screenwidth,screenheight;
39 extern int kTextureSize;
40 extern FRUSTUM frustum;
41 extern Light light;
42 extern Objects objects;
43 extern int detail;
44 extern float usermousesensitivity;
45 extern bool osx;
46 extern float camerashake;
47 extern Weapons weapons;
48 extern Person player[maxplayers];
49 extern int slomo;
50 extern float slomodelay;
51 extern bool ismotionblur;
52 extern float woozy;
53 extern float blackout;
54 extern bool damageeffects;
55 extern float volume;
56 extern int numplayers;
57 extern bool texttoggle;
58 extern float blurness;
59 extern float targetblurness;
60 extern float playerdist;
61 extern bool cellophane;
62 extern bool freeze;
63 extern float flashamount,flashr,flashg,flashb;
64 extern int flashdelay;
65 extern int netstate;
66 extern float motionbluramount;
67 extern bool isclient;
68 extern bool alwaysblur;
69 extern int test;
70 extern bool tilt2weird;
71 extern bool tiltweird;
72 extern bool midweird;
73 extern bool proportionweird;
74 extern bool vertexweird[6];
75 extern bool velocityblur;
76 extern bool debugmode;
77 extern int mainmenu;
78 extern int oldmainmenu;
79 extern int bloodtoggle;
80 extern int difficulty;
81 extern bool decals;
82 // MODIFIED GWC
83 //extern int texdetail;
84 extern float texdetail;
85 extern bool musictoggle;
86 extern int bonus;
87 extern float bonusvalue;
88 extern float bonustotal;
89 extern float bonustime;
90 extern int oldbonus;
91 extern float startbonustotal;
92 extern float bonusnum[100];
93 extern int tutoriallevel;
94 extern float smoketex;
95 extern float tutorialstagetime;
96 extern float tutorialmaxtime;
97 extern int tutorialstage;
98 extern bool againbonus;
99 extern float damagedealt;
100 extern float damagetaken;
101 extern bool invertmouse;
102
103 extern int numhotspots;
104 extern int winhotspot;
105 extern int killhotspot;
106 extern XYZ hotspot[40];
107 extern int hotspottype[40];
108 extern float hotspotsize[40];
109 extern char hotspottext[40][256];
110 extern int currenthotspot;;
111
112 extern int numfalls;
113 extern int numflipfail;
114 extern int numseen;
115 extern int numstaffattack;
116 extern int numswordattack;
117 extern int numknifeattack;
118 extern int numunarmedattack;
119 extern int numescaped;
120 extern int numflipped;
121 extern int numwallflipped;
122 extern int numthrowkill;
123 extern int numafterkill;
124 extern int numreversals;
125 extern int numattacks;
126 extern int maxalarmed;
127 extern int numresponded;
128
129 extern bool campaign;
130 extern bool winfreeze;
131
132 extern float menupulse;
133
134 extern bool gamestart;
135
136 extern int numdialogues;
137 extern int numdialogueboxes[max_dialogues];
138 extern int dialoguetype[max_dialogues];
139 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
140 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
141 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
142 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
143 extern char dialoguename[max_dialogues][max_dialoguelength][64];
144 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
145 extern XYZ participantlocation[max_dialogues][10];
146 extern int participantfocus[max_dialogues][max_dialoguelength];
147 extern int participantaction[max_dialogues][max_dialoguelength];
148 extern float participantrotation[max_dialogues][10];
149 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
150 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
151 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
152 extern int indialogue;
153 extern int whichdialogue;
154 extern int directing;
155 extern float dialoguetime;
156 extern int dialoguegonethrough[20];
157
158 extern bool gamestarted;
159
160 extern bool showdamagebar;
161
162 extern OPENAL_SAMPLE    *samp[100];
163 extern int channels[100];
164 extern "C"      void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
165
166 void Game::flash() { // shouldn't be that way, these should be attributes and Person class should not change rendering.
167         flashr=1;
168         flashg=0;
169         flashb=0;
170         flashamount=1;
171         flashdelay=1;
172 }
173 /*********************> DrawGLScene() <*****/
174 long long Game::MD5_string (char *string){
175         char temp[256]="";
176         char temp2[256]="";
177         long long num=90814;
178
179         sprintf (temp, "%s",string);
180
181         int i=0;
182         while (i<256&&temp[i]!='\0'){
183                 if(temp[i]%3==0)num+=temp[i]*124;
184                 else if(temp[i]%3==1)num-=temp[i]*temp[i];
185                 else num*=temp[i];
186                 i++;
187         }
188
189         num=longlongabs(num);
190         if(num==0)num+=1452;
191
192         while(num<LONGLONGCONST(5000000000000000)){
193                 num*=1.85421521;
194         }
195
196         while(num>LONGLONGCONST(9900000000000000)){
197                 num/=1.235421521;
198         }
199
200         return num;
201
202         //return 1111111111111111;
203 }
204
205 int Game::DrawGLScene(StereoSide side)
206 {       
207         static float texcoordwidth,texcoordheight;
208         static float texviewwidth, texviewheight;
209         static int i,j,k,l;
210         static GLubyte color;
211         static float newbrightness;
212         static float changespeed;
213         static XYZ checkpoint;
214         static float tempmult;
215         float tutorialopac;
216         static char string[256]="";
217         static char string2[256]="";
218         static char string3[256]="";
219
220         static float lastcheck;
221
222         lastcheck+=multiplier;
223
224         if ( stereomode == stereoAnaglyph ) {
225                 switch(side) {
226                         case stereoLeft: glColorMask( 0.0, 1.0, 1.0, 1.0 ); break;
227                         case stereoRight: glColorMask( 1.0, 0.0, 0.0, 1.0 ); break;
228                 }
229         } else {
230                 glColorMask( 1.0, 1.0, 1.0, 1.0 );
231                 
232                 if ( stereomode == stereoHorizontalInterlaced || stereomode == stereoVerticalInterlaced ) {
233                         glStencilFunc(side == stereoLeft ? GL_NOTEQUAL : GL_EQUAL, 0x01, 0x01);
234                 }
235         }
236
237         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)){
238                 tempmult=multiplier;
239                 multiplier=0;
240         }
241
242         if(!mainmenu){
243                 if(editorenabled){
244                         numboundaries=mapradius*2;
245                         if(numboundaries>360)numboundaries=360;
246                         for(i=0;i<numboundaries;i++){
247                                 boundary[i]=0;
248                                 boundary[i].z=1;
249                                 boundary[i]=mapcenter+DoRotation(boundary[i]*mapradius,0,i*(360/((float)(numboundaries))),0);
250                         }
251                 }
252
253                 SetUpLighting();
254
255                 static int changed;
256                 changed=0;
257
258                 olddrawmode=drawmode;
259                 if(ismotionblur&&!loading){
260                         if((findLengthfast(&player[0].velocity)>200)&&velocityblur&&!cameramode){
261                                 drawmode=motionblurmode;
262                                 motionbluramount=200/(findLengthfast(&player[0].velocity));
263                                 changed=1;
264                         }
265                         if(player[0].damage-player[0].superpermanentdamage>(player[0].damagetolerance-player[0].superpermanentdamage)*1/2&&damageeffects&&!cameramode){
266                                 drawmode=doublevisionmode;
267                                 changed=1;
268                         }
269                 }
270
271                 if(slomo&&!loading){
272                         if(ismotionblur)
273                                 drawmode=motionblurmode;
274                         motionbluramount=.2;
275                         slomodelay-=multiplier;
276                         if(slomodelay<0)slomo=0;
277                         camerashake=0;
278                         changed=1;
279                 }
280                 if((!changed&&!slomo)||loading){
281                         drawmode=normalmode;
282                         if(ismotionblur&&(/*fps>100||*/alwaysblur)){
283                                 if(olddrawmode!=realmotionblurmode)change=1;
284                                 else change=0;
285                                 drawmode=realmotionblurmode;
286                         }
287                         else if(olddrawmode==realmotionblurmode)change=2;
288                         else change=0;
289                 }
290
291                 if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted))drawmode=normalmode;
292                 if((freeze||winfreeze)&&ismotionblur&&!mainmenu)drawmode=radialzoommode;
293
294                 if(winfreeze||mainmenu)drawmode=normalmode;
295
296                 //drawmode=glowmode;
297                 if(drawmode==glowmode){
298                         RGBColor color2;
299                         color2.red=0;
300                         color2.green=0;
301                         color2.blue=0;
302 #if PLATFORM_MACOSX
303                         DSpContext_FadeGamma(NULL,200,&color2);
304 #endif
305                 }
306
307                 if(drawtoggle!=2)drawtoggle=1-drawtoggle;
308
309                 if(!texcoordwidth){
310
311                         texviewwidth=kTextureSize;
312                         if(texviewwidth>screenwidth)texviewwidth=screenwidth;
313                         texviewheight=kTextureSize;
314                         if(texviewheight>screenheight)texviewheight=screenheight;
315
316                         texcoordwidth=screenwidth/kTextureSize;
317                         texcoordheight=screenheight/kTextureSize;
318                         if(texcoordwidth>1)texcoordwidth=1;
319                         if(texcoordheight>1)texcoordheight=1;
320                 }
321
322                 glDrawBuffer(GL_BACK);
323                 glReadBuffer(GL_BACK);
324
325                 /*if(environment==desertenvironment)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, (float)(abs(Random()%100))/50 );
326                 else glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
327                 */
328                 if(abs(blurness-targetblurness)<multiplier*10||abs(blurness-targetblurness)>2){
329                         blurness=targetblurness;
330                         targetblurness=(float)(abs(Random()%100))/40;
331                 }
332                 if(blurness<targetblurness)blurness+=multiplier*5;
333                 if(blurness>targetblurness)blurness-=multiplier*5;
334
335                 //glFinish();
336                 static XYZ terrainlight;
337                 static float distance;
338                 //if(drawmode==normalmode)ReSizeGLScene(90,.1);
339                 if(drawmode==normalmode)ReSizeGLScene(90,.1f);
340                 if(drawmode!=normalmode)glViewport(0,0,texviewwidth,texviewheight);     
341                 glDepthFunc(GL_LEQUAL);
342                 glDepthMask(1);
343                 glAlphaFunc(GL_GREATER, 0.0001f);
344                 glEnable(GL_ALPHA_TEST);
345                 glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
346                 glClear(GL_DEPTH_BUFFER_BIT);
347
348                 glMatrixMode (GL_MODELVIEW);
349                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
350                 glLoadIdentity ();
351                 
352                 // Move the camera for the current eye's point of view.
353                 // Reverse the movement if we're reversing stereo
354                 glTranslatef((stereoseparation/2) * side * (stereoreverse  ? -1 : 1), 0, 0);
355                 
356                 if(!cameramode&&!freeze&&!winfreeze){
357                         glRotatef(float(Random()%100)/10*camerashake/*+(woozy*woozy)/10*/,0,0,1);
358                         glRotatef(rotation2+sin(woozy/2)*(player[0].damage/player[0].damagetolerance)*5,1,0,0);
359                         glRotatef(rotation+sin(woozy)*(player[0].damage/player[0].damagetolerance)*5,0,1,0);
360                 }
361                 if(cameramode||freeze||winfreeze){
362                         //glRotatef(float(Random()%100)/10*camerashake/*+(woozy*woozy)/10*/,0,0,1);
363                         glRotatef(rotation2,1,0,0);
364                         glRotatef(rotation,0,1,0);
365                 }
366
367                 if(environment==desertenvironment){
368                         glRotatef((float)(abs(Random()%100))/3000-1,1,0,0);
369                         glRotatef((float)(abs(Random()%100))/3000-1,0,1,0);
370                         //glRotatef(blurness/40-1,1,0,0);
371                         //glRotatef(blurness/40-1,0,1,0);
372                 }
373                 SetUpLight(&light,0);
374                 glPushMatrix();
375                 if(environment==desertenvironment&&detail==2)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness+.4 );
376                 if(environment==desertenvironment){
377                         glRotatef((float)(abs(Random()%100))/1000,1,0,0);
378                         glRotatef((float)(abs(Random()%100))/1000,0,1,0);
379                 }       
380                 skybox.draw();
381                 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0);
382                 glPopMatrix();
383                 glTranslatef(-viewer.x,-viewer.y,-viewer.z);
384                 frustum.GetFrustum();
385
386                 //Make Shadow
387                 static XYZ point;
388                 static float size,opacity,rotation;
389                 rotation=0;
390                 for(k=0;k<numplayers;k++){
391                         if(!player[k].skeleton.free&&player[k].playerdetail&&player[k].howactive<typesleeping)
392                                 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)
393                                         for(i=0;i<player[k].skeleton.num_joints;i++){
394                                                 if(player[k].skeleton.joints[i].label==leftknee||player[k].skeleton.joints[i].label==rightknee||player[k].skeleton.joints[i].label==groin){
395                                                         point=DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
396                                                         size=.4f;
397                                                         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;
398                                                         if(k!=0&&tutoriallevel==1){
399                                                                 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;
400                                                         }
401                                                         terrain.MakeDecal(shadowdecal,point,size,opacity,rotation);
402                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
403                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
404                                                                         j=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
405                                                                         if(objects.position[j].y<player[k].coords.y||objects.type[j]==tunneltype||objects.type[j]==weirdtype){
406                                                                                 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);
407                                                                                 size=.4f;
408                                                                                 opacity=.4f;
409                                                                                 if(k!=0&&tutoriallevel==1){
410                                                                                         opacity=.2+.2*sin(smoketex*6+i);
411                                                                                 }
412                                                                                 objects.model[j].MakeDecal(shadowdecal,&point,&size,&opacity,&rotation);
413                                                                         }
414                                                                 }
415                                                 }
416                                         }
417                                         if((player[k].skeleton.free||player[k].howactive>=typesleeping)&&player[k].playerdetail)
418                                                 if(frustum.SphereInFrustum(player[k].coords.x,player[k].coords.y,player[k].coords.z,player[k].scale*5)&&player[k].occluded<25)
419                                                         for(i=0;i<player[k].skeleton.num_joints;i++){
420                                                                 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){
421                                                                         if(player[k].skeleton.free)point=player[k].skeleton.joints[i].position*player[k].scale+player[k].coords;
422                                                                         else point=DoRotation(player[k].skeleton.joints[i].position,0,player[k].rotation,0)*player[k].scale+player[k].coords;
423                                                                         size=.4f;
424                                                                         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;
425                                                                         if(k!=0&&tutoriallevel==1){
426                                                                                 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;
427                                                                         }
428                                                                         terrain.MakeDecal(shadowdecal,point,size,opacity*.7,rotation);
429                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
430                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
431                                                                                         j=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
432                                                                                         if(objects.position[j].y<player[k].coords.y||objects.type[j]==tunneltype||objects.type[j]==weirdtype){
433                                                                                                 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);
434                                                                                                 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);
435                                                                                                 size=.4f;
436                                                                                                 opacity=.4f;
437                                                                                                 if(k!=0&&tutoriallevel==1){
438                                                                                                         opacity=.2+.2*sin(smoketex*6+i);
439                                                                                                 }
440                                                                                                 objects.model[j].MakeDecal(shadowdecal,&point,&size,&opacity,&rotation);
441                                                                                         }
442                                                                                 }
443                                                                 }
444                                                         }
445
446                                                         if(!player[k].playerdetail)
447                                                                 if(frustum.SphereInFrustum(player[k].coords.x,player[k].coords.y,player[k].coords.z,player[k].scale*5))
448                                                                 {
449                                                                         point=player[k].coords;
450                                                                         size=.7;
451                                                                         opacity=.4-(player[k].coords.y-terrain.getHeight(player[k].coords.x,player[k].coords.z))/5;
452                                                                         terrain.MakeDecal(shadowdecal,point,size,opacity*.7,rotation);
453                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
454                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
455                                                                                         j=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
456                                                                                         point=DoRotation(player[k].coords-objects.position[j],0,-objects.rotation[j],0);
457                                                                                         size=.7;
458                                                                                         opacity=.4f;
459                                                                                         objects.model[j].MakeDecal(shadowdecal,&point,&size,&opacity,&rotation);
460                                                                                 }
461                                                                 }
462                 }
463
464                 //Terrain
465                 glEnable(GL_TEXTURE_2D);
466                 glDepthMask(1);
467                 glEnable(GL_DEPTH_TEST);
468                 glEnable(GL_CULL_FACE);
469                 glDisable(GL_BLEND);
470                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
471                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
472                 glBindTexture( GL_TEXTURE_2D, terraintexture);
473                 terrain.draw(0);
474                 glBindTexture( GL_TEXTURE_2D, terraintexture2);
475                 terrain.draw(1);
476                 //glBindTexture( GL_TEXTURE_2D, terraintexture3);
477                 //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
478                 //terrain.draw(2);
479
480                 terrain.drawdecals();
481
482                 //Model
483                 glEnable(GL_CULL_FACE);
484                 glEnable(GL_LIGHTING);
485                 glDisable(GL_BLEND);
486                 glEnable(GL_TEXTURE_2D);
487                 glDepthMask(1);
488
489                 glEnable(GL_COLOR_MATERIAL);
490
491                 test=2;
492                 tilt2weird=0;
493                 tiltweird=0;
494                 midweird=0;
495                 proportionweird=0;
496                 vertexweird[0]=0;
497                 vertexweird[1]=0;
498                 vertexweird[2]=0;
499                 vertexweird[3]=0;
500                 vertexweird[4]=0;
501                 vertexweird[5]=0;
502
503                 if(!cellophane){
504                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
505                         glEnable(GL_CULL_FACE);
506                         glCullFace(GL_FRONT);
507                         glDepthMask(1);
508                         for(k=0;k<numplayers;k++){
509                                 if(k==0||tutoriallevel!=1){
510                                         glEnable(GL_BLEND);
511                                         glEnable(GL_LIGHTING);
512                                         terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z);
513                                         distance=findDistancefast(&viewer,&player[k].coords);
514                                         distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
515                                         glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
516                                         if(distance>=1)glDisable(GL_BLEND);
517                                         if(distance>=.5){
518                                                 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;
519                                                 checkpoint.y+=1;
520                                                 if(!player[k].occluded==0)i=checkcollide(viewer,checkpoint,player[k].lastoccluded);
521                                                 if(i==-1||player[k].occluded==0)i=checkcollide(viewer,checkpoint);
522                                                 if(i!=-1){
523                                                         player[k].occluded+=1;
524                                                         player[k].lastoccluded=i;
525                                                 }
526                                                 else player[k].occluded=0;
527                                                 if(player[k].occluded<25)player[k].DrawSkeleton();
528                                         }
529                                 }
530                         }
531                 }
532
533                 if(!cameramode&&musictype==stream_music2)playerdist=findDistancefastflat(&player[0].coords,&viewer);
534                 else playerdist=-100;
535                 glPushMatrix();
536                 glCullFace(GL_BACK);
537                 glEnable(GL_TEXTURE_2D);
538                 objects.Draw();
539                 glPopMatrix();
540
541                 glPushMatrix();
542                 if(frustum.SphereInFrustum(realhawkcoords.x+hawk.boundingspherecenter.x,realhawkcoords.y+hawk.boundingspherecenter.y,realhawkcoords.z+hawk.boundingspherecenter.z,2)){   
543                         glAlphaFunc(GL_GREATER, 0.0001f);
544                         glDepthMask(1);
545                         glDisable(GL_CULL_FACE);
546                         glDisable(GL_LIGHTING);
547                         glEnable(GL_BLEND);
548                         glTranslatef(hawkcoords.x,hawkcoords.y,hawkcoords.z);
549                         glRotatef(hawkrotation,0,1,0);
550                         glTranslatef(25,0,0);
551                         distance=findDistancefast(&viewer,&realhawkcoords)*1.2;
552                         glColor4f(light.color[0],light.color[1],light.color[2],(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance);
553                         if((viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance>1)glColor4f(light.color[0],light.color[1],light.color[2],1);
554                         if((viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance>0)
555                                 hawk.drawdifftex(hawktexture);
556                 }
557                 glPopMatrix();
558
559                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
560                 glEnable(GL_CULL_FACE);
561                 glCullFace(GL_FRONT);
562                 glDepthMask(1);
563                 for(k=0;k<numplayers;k++){
564                         if(!(k==0||tutoriallevel!=1)){
565                                 glEnable(GL_BLEND);
566                                 glEnable(GL_LIGHTING);
567                                 terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z);
568                                 distance=findDistancefast(&viewer,&player[k].coords);
569                                 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
570                                 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance);
571                                 if(distance>=1)glDisable(GL_BLEND);
572                                 if(distance>=.5){
573                                         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;
574                                         checkpoint.y+=1;
575                                         if(!player[k].occluded==0)i=checkcollide(viewer,checkpoint,player[k].lastoccluded);
576                                         if(i==-1||player[k].occluded==0)i=checkcollide(viewer,checkpoint);
577                                         if(i!=-1){
578                                                 player[k].occluded+=1;
579                                                 player[k].lastoccluded=i;
580                                         }
581                                         else player[k].occluded=0;
582                                         if(player[k].occluded<25)player[k].DrawSkeleton();
583                                 }
584                         }
585                 }
586                 //}
587
588                 glPushMatrix();
589                 glEnable(GL_TEXTURE_2D);
590                 weapons.Draw();
591                 glPopMatrix();
592                 glCullFace(GL_BACK);
593
594                 glDisable(GL_COLOR_MATERIAL);
595
596                 glDisable(GL_LIGHTING);
597                 glDisable(GL_TEXTURE_2D);
598
599                 glDepthMask(0);
600
601                 sprites.Draw();
602
603                 if(editorenabled){
604                         glEnable(GL_BLEND);
605                         glDisable(GL_LIGHTING);
606                         glDisable(GL_TEXTURE_2D);
607                         glDisable(GL_COLOR_MATERIAL);
608                         glColor4f(1,1,0,1);
609
610                         for(k=0;k<numplayers;k++){
611                                 if(player[k].numwaypoints>1){
612                                         glBegin(GL_LINE_LOOP);
613                                         for(i=0;i<player[k].numwaypoints;i++){
614                                                 glVertex3f(player[k].waypoints[i].x,player[k].waypoints[i].y+.5,player[k].waypoints[i].z);
615                                         }
616                                         glEnd();
617                                 }
618                         }
619
620
621                         if(numpathpoints>1){
622                                 glColor4f(0,1,0,1);
623                                 for(k=0;k<numpathpoints;k++){
624                                         if(numpathpointconnect[k]){
625                                                 for(i=0;i<numpathpointconnect[k];i++){
626                                                         glBegin(GL_LINE_LOOP);
627                                                         glVertex3f(pathpoint[k].x,pathpoint[k].y+.5,pathpoint[k].z);
628                                                         glVertex3f(pathpoint[pathpointconnect[k][i]].x,pathpoint[pathpointconnect[k][i]].y+.5,pathpoint[pathpointconnect[k][i]].z);                                     
629                                                         glEnd();
630                                                 }
631                                         }
632                                 }
633                                 glColor4f(1,1,1,1);
634                                 glPointSize(4);
635                                 glBegin(GL_POINTS);
636                                 glVertex3f(pathpoint[pathpointselected].x,pathpoint[pathpointselected].y+.5,pathpoint[pathpointselected].z);
637                                 glEnd();
638                         }
639                 }
640
641                 //Text
642
643                 glEnable(GL_TEXTURE_2D);
644                 glColor4f(.5,.5,.5,1);
645                 if(!console){
646                         sprintf (string, " ",(int)(fps));
647                         text.glPrint(10,30,string,0,.8,screenwidth,screenheight);
648
649                         if(!tutoriallevel)
650                                 if(bonus>0&&bonustime<1&&!winfreeze&&indialogue==-1/*bonustime<4*/){
651                                         if(bonus==tracheotomy)sprintf (string, "Tracheotomy!");
652                                         else if(bonus==backstab)sprintf (string, "Backstabber!");
653                                         else if(bonus==spinecrusher)sprintf (string, "Spinecrusher!");
654                                         else if(bonus==ninja)sprintf (string, "Ninja Bonus!");
655                                         else if(bonus==style)sprintf (string, "Style Bonus!");
656                                         else if(bonus==cannon)sprintf (string, "Leg Cannon!");
657                                         else if(bonus==aimbonus)sprintf (string, "Nice Aim!");
658                                         else if(bonus==deepimpact)sprintf (string, "Heavy Impact!");
659                                         else if(bonus==touchofdeath)sprintf (string, "Touch of Death!");
660                                         else if(bonus==swordreversebonus)sprintf (string, "Sword Disarm!");
661                                         else if(bonus==staffreversebonus)sprintf (string, "Staff Disarm!");
662                                         else if(bonus==reverseko)sprintf (string, "Reversal KO!");
663                                         else if(bonus==solidhit)sprintf (string, "Solid Hit!");
664                                         else if(bonus==twoxcombo)sprintf (string, "2X Combo!");
665                                         else if(bonus==threexcombo)sprintf (string, "3X Combo!");
666                                         else if(bonus==fourxcombo)sprintf (string, "4X COMBO!");
667                                         else if(bonus==megacombo)sprintf (string, "MEGA COMBO!");
668                                         else if(bonus==Reversal)sprintf (string, "Reversal!");
669                                         else if(bonus==Stabbonus)sprintf (string, "Punctured!");
670                                         else if(bonus==Slicebonus)sprintf (string, "Sliced!");
671                                         else if(bonus==Bullseyebonus)sprintf (string, "Bullseye!");
672                                         else if(bonus==Slashbonus)sprintf (string, "Slashed!");
673                                         else if(bonus==Wolfbonus)sprintf (string, "WOLF SLAYER!");
674                                         else if(bonus==FinishedBonus)sprintf (string, "SLAIN!");
675                                         else if(bonus==TackleBonus)sprintf (string, "Tackle!");
676                                         else if(bonus==AboveBonus)sprintf (string, "Death from Above!");
677                                         else sprintf (string, "Excellent!");
678
679                                         glColor4f(0,0,0,1-bonustime);
680                                         text.glPrintOutline(1024/2-10*strlen(string)-4,768/16-4+768*4/5,string,1,2.5,1024,768);
681                                         glColor4f(1,0,0,1-bonustime);
682                                         text.glPrint(1024/2-10*strlen(string),768/16+768*4/5,string,1,2,1024,768);
683
684                                         sprintf (string, "%d",(int)bonusvalue);
685                                         glColor4f(0,0,0,1-bonustime);
686                                         text.glPrintOutline(1024/2-10*strlen(string)-4,768/16-4-20+768*4/5,string,1,2.5*.8,1024,768);
687                                         glColor4f(1,0,0,1-bonustime);
688                                         text.glPrint(1024/2-10*strlen(string),768/16-20+768*4/5,string,1,2*.8,1024,768);
689                                         glColor4f(.5,.5,.5,1);
690                                 }
691
692                                 if(tutoriallevel==1){
693                                         tutorialopac=tutorialmaxtime-tutorialstagetime;
694                                         if(tutorialopac>1)tutorialopac=1;
695                                         if(tutorialopac<0)tutorialopac=0;
696
697                                         sprintf (string, " ");
698                                         sprintf (string2, " ");
699                                         sprintf (string3, " ");
700                                         if(tutorialstage==0){
701                                                 sprintf (string, " ");
702                                                 sprintf (string2, " ");
703                                                 sprintf (string3, " ");
704                                         }
705                                         if(tutorialstage==1){
706                                                 sprintf (string, "Welcome to the Lugaru training level!");
707                                                 sprintf (string2, " ");
708                                                 sprintf (string3, " ");
709                                         }
710                                         if(tutorialstage==2){
711                                                 sprintf (string, "BASIC MOVEMENT:");
712                                                 sprintf (string2, " ");
713                                                 sprintf (string3, " ");
714                                         }
715                                         if(tutorialstage==3){
716                                                 sprintf (string, "You can move the mouse to rotate the camera.");
717                                                 sprintf (string2, " ");
718                                                 sprintf (string3, " ");
719                                         }
720                                         if(tutorialstage==4){
721                                                 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));
722                                                 sprintf (string2, "All movement is relative to the camera.");
723                                                 sprintf (string3, " ");
724                                         }
725                                         if(tutorialstage==5){
726                                                 sprintf (string, "Please press %s to jump.",Input::keyToChar(jumpkey));
727                                                 sprintf (string2, "You can hold it longer to jump higher.");
728                                                 sprintf (string3, " ");
729                                         }
730                                         if(tutorialstage==6){
731                                                 sprintf (string, "You can press %s to crouch.",Input::keyToChar(crouchkey));
732                                                 sprintf (string2, "You can jump higher from a crouching position.");
733                                                 sprintf (string3, " ");
734                                         }
735                                         if(tutorialstage==7){
736                                                 sprintf (string, "While running, you can press %s to roll.",Input::keyToChar(crouchkey));
737                                                 sprintf (string2, " ");
738                                                 sprintf (string3, " ");
739                                         }
740                                         if(tutorialstage==8){
741                                                 sprintf (string, "While crouching, you can sneak around silently");
742                                                 sprintf (string2, "using the movement keys.");
743                                                 sprintf (string3, " ");
744                                         }
745                                         if(tutorialstage==9){
746                                                 sprintf (string, "Release the crouch key while sneaking and hold the movement keys");
747                                                 sprintf (string2, "to run animal-style.");
748                                                 sprintf (string3, " ");
749                                         }
750                                         if(tutorialstage==10){
751                                                 sprintf (string, "ADVANCED MOVEMENT:");
752                                                 sprintf (string2, " ");
753                                                 sprintf (string3, " ");
754                                         }
755                                         if(tutorialstage==11){
756                                                 sprintf (string, "When you jump at a wall, you can hold %s again",Input::keyToChar(jumpkey));
757                                                 sprintf (string2, "during impact to perform a walljump.");
758                                                 sprintf (string3, "Be sure to use the movement keys to press against the wall");
759                                         }
760                                         if(tutorialstage==12){
761                                                 sprintf (string, "While in the air, you can press crouch to flip.",Input::keyToChar(jumpkey));
762                                                 sprintf (string2, "Walljumps and flips confuse enemies and give you more control.");
763                                                 sprintf (string3, " ");
764                                         }
765                                         if(tutorialstage==13){
766                                                 sprintf (string, "BASIC COMBAT:");
767                                                 sprintf (string2, " ");
768                                                 sprintf (string3, " ");
769                                         }
770                                         if(tutorialstage==14){
771                                                 sprintf (string, "There is now an imaginary enemy");
772                                                 sprintf (string2, "in the middle of the training area.");
773                                                 sprintf (string3, " ");
774                                         }
775                                         if(tutorialstage==15){
776                                                 if(attackkey==MOUSEBUTTON1)sprintf (string, "Click to attack when you are near an enemy.");
777                                                 else sprintf (string, "Press %s to attack when you are near an enemy.",Input::keyToChar(attackkey));
778                                                 sprintf (string2, "You can punch by standing still near an enemy and attacking.");
779                                                 sprintf (string3, " ");
780                                         }
781                                         if(tutorialstage==16){
782                                                 sprintf (string, "If you are close, you will perform a weak punch.");
783                                                 sprintf (string2, "The weak punch is excellent for starting attack combinations.");
784                                                 sprintf (string3, " ");
785                                         }
786                                         if(tutorialstage==17){
787                                                 sprintf (string, "Attacking while running results in a spin kick.");
788                                                 sprintf (string2, "This is one of your most powerful ground attacks.");
789                                                 sprintf (string3, " ");
790                                         }
791                                         if(tutorialstage==18){
792                                                 sprintf (string, "Sweep the enemy's legs out by attacking while crouched.");
793                                                 sprintf (string2, "This is a very fast attack, and easy to follow up.");
794                                                 sprintf (string3, " ");
795                                         }
796                                         if(tutorialstage==19){
797                                                 sprintf (string, "When an enemy is on the ground, you can deal some extra");
798                                                 sprintf (string2, "damage by running up and drop-kicking him.");
799                                                 sprintf (string3, "(Try knocking them down with a sweep first)");
800                                         }
801                                         if(tutorialstage==20){
802                                                 sprintf (string, "Your most powerful individual attack is the rabbit kick.");
803                                                 if(attackkey==MOUSEBUTTON1)sprintf (string2, "Run at the enemy while holding the mouse button, and press");
804                                                 else sprintf (string2, "Run at the enemy while holding %s, and press", Input::keyToChar(attackkey));
805                                                 sprintf (string3, "the jump key (%s) to attack.",Input::keyToChar(jumpkey));
806                                         }
807                                         if(tutorialstage==21){
808                                                 sprintf (string, "This attack is devastating if timed correctly.");
809                                                 sprintf (string2, "Even if timed incorrectly, it will knock the enemy over.");
810                                                 if(againbonus)sprintf (string3, "Try rabbit-kicking the imaginary enemy again.");
811                                                 else sprintf (string3, "Try rabbit-kicking the imaginary enemy.");
812                                         }
813                                         if(tutorialstage==22){
814                                                 sprintf (string, "If you sneak behind an enemy unnoticed, you can kill");
815                                                 sprintf (string2, "him instantly. Move close behind this enemy");
816                                                 sprintf (string3, "and attack.");
817                                         }
818                                         if(tutorialstage==23){
819                                                 sprintf (string, "Another important attack is the wall kick. When an enemy");
820                                                 sprintf (string2, "is near a wall, perform a walljump nearby and hold");
821                                                 sprintf (string3, "the attack key during impact with the wall.");
822                                         }
823                                         if(tutorialstage==24){
824                                                 sprintf (string, "You can tackle enemies by running at them animal-style");
825                                                 if(attackkey==MOUSEBUTTON1)sprintf (string2, "and pressing jump (%s) or attack(mouse button).",Input::keyToChar(jumpkey));
826                                                 else sprintf (string2, "and pressing jump (%s) or attack(%s).",Input::keyToChar(jumpkey),Input::keyToChar(attackkey));
827                                                 sprintf (string3, "This is especially useful when they are running away.");
828                                         }
829                                         if(tutorialstage==25){
830                                                 sprintf (string, "Dodge by pressing back and attack. Dodging is essential");
831                                                 sprintf (string2, "against enemies with swords or other long weapons.");
832                                                 sprintf (string3, " ");
833                                         }
834                                         if(tutorialstage==26){
835                                                 sprintf (string, "REVERSALS AND COUNTER-REVERSALS");
836                                                 sprintf (string2, " ");
837                                                 sprintf (string3, " ");
838                                         }
839                                         if(tutorialstage==27){
840                                                 sprintf (string, "The enemy can now reverse your attacks.");
841                                                 sprintf (string2, " ");
842                                                 sprintf (string3, " ");
843                                         }
844                                         if(tutorialstage==28){
845                                                 sprintf (string, "If you attack, you will notice that the enemy now sometimes");
846                                                 sprintf (string2, "catches your attack and uses it against you. Hold");
847                                                 sprintf (string3, "crouch (%s) after attacking to escape from reversals.",Input::keyToChar(crouchkey));
848                                         }
849                                         if(tutorialstage==29){
850                                                 sprintf (string, "Try escaping from two more reversals in a row.");
851                                                 sprintf (string2, " ");
852                                                 sprintf (string3, " ");
853                                         }
854                                         if(tutorialstage==30){
855                                                 sprintf (string, "Good!");
856                                                 sprintf (string2, " ");
857                                                 sprintf (string3, " ");
858                                         }
859                                         if(tutorialstage==31){
860                                                 sprintf (string, "To reverse an attack, you must tap crouch (%s) during the",Input::keyToChar(crouchkey));
861                                                 sprintf (string2, "enemy's attack. You must also be close to the enemy;");
862                                                 sprintf (string3, "this is especially important against armed opponents.");
863                                         }
864                                         if(tutorialstage==32){
865                                                 sprintf (string, "The enemy can attack in %d seconds.", (int)(tutorialmaxtime-tutorialstagetime));
866                                                 sprintf (string2, "This imaginary opponents attacks will be highlighted");
867                                                 sprintf (string3, "to make this easier.");
868                                         }
869                                         if(tutorialstage==33){
870                                                 sprintf (string, "Reverse three enemy attacks!");
871                                                 sprintf (string2, " ");
872                                                 sprintf (string3, " ");
873                                         }
874                                         if(tutorialstage==34){
875                                                 sprintf (string, "Reverse two more enemy attacks!");
876                                                 sprintf (string2, " ");
877                                                 sprintf (string3, " ");
878                                         }
879                                         if(tutorialstage==35){
880                                                 sprintf (string, "Reverse one more enemy attack!");
881                                                 sprintf (string2, " ");
882                                                 sprintf (string3, " ");
883                                         }
884                                         if(tutorialstage==36){
885                                                 sprintf (string, "Excellent!");
886                                                 sprintf (string2, " ");
887                                                 sprintf (string3, " ");
888                                         }
889                                         if(tutorialstage==37){
890                                                 sprintf (string, "Now spar with the enemy for %d more seconds.", (int)(tutorialmaxtime-tutorialstagetime));
891                                                 sprintf (string2, "Damage dealt: %d",(int)damagedealt);
892                                                 sprintf (string3, "Damage taken: %d.",(int)damagetaken);
893                                         }
894                                         if(tutorialstage==38){
895                                                 sprintf (string, "WEAPONS:");
896                                                 sprintf (string2, " ");
897                                                 sprintf (string3, " ");
898                                         }
899                                         if(tutorialstage==39){
900                                                 sprintf (string, "There is now an imaginary knife");
901                                                 sprintf (string2, "in the center of the training area.");
902                                                 sprintf (string3, " ");
903                                         }
904                                         if(tutorialstage==40){
905                                                 sprintf (string, "Stand, roll or handspring over the knife");
906                                                 sprintf (string2, "while pressing %s to pick it up.",Input::keyToChar(throwkey));
907                                                 sprintf (string3, "You can crouch and press the same key to drop it again.");
908                                         }
909                                         if(tutorialstage==41){
910                                                 sprintf (string, "You can equip and unequip weapons using the %s key.",Input::keyToChar(drawkey));
911                                                 sprintf (string2, "Sometimes it is best to keep them unequipped to");
912                                                 sprintf (string3, "prevent enemies from taking them. ");
913                                         }
914                                         if(tutorialstage==42){
915                                                 sprintf (string, "The knife is the smallest weapon and the least encumbering.");
916                                                 sprintf (string2, "You can equip or unequip it while standing, crouching,");
917                                                 sprintf (string3, "running or flipping.");
918                                         }
919                                         if(tutorialstage==43){
920                                                 sprintf (string, "You perform weapon attacks the same way as unarmed attacks,");
921                                                 sprintf (string2, "but sharp weapons cause permanent damage, instead of the");
922                                                 sprintf (string3, "temporary trauma from blunt weapons, fists and feet.");
923                                         }
924                                         if(tutorialstage==44){
925                                                 sprintf (string, "The enemy now has your knife!");
926                                                 sprintf (string2, "Please reverse two of his knife attacks.");
927                                                 sprintf (string3, " ");
928                                         }
929                                         if(tutorialstage==45){
930                                                 sprintf (string, "Please reverse one more of his knife attacks.");
931                                                 sprintf (string2, " ");
932                                                 sprintf (string3, " ");
933                                         }
934                                         if(tutorialstage==46){
935                                                 sprintf (string, "Now he has a sword!");
936                                                 sprintf (string2, "The sword has longer reach than your arms, so you");
937                                                 sprintf (string3, "must move close to reverse the sword slash.");
938                                         }
939                                         if(tutorialstage==47){
940                                                 sprintf (string, "Long weapons like the sword and staff are also useful for defense;");
941                                                 sprintf (string2, "you can parry enemy weapon attacks by pressing the attack key");
942                                                 sprintf (string3, "at the right time. Please try parrying the enemy's attacks!");
943                                         }
944                                         if(tutorialstage==48){
945                                                 sprintf (string, "The staff is like the sword, but has two main attacks.");
946                                                 sprintf (string2, "The standing smash is fast and effective, and the running");
947                                                 sprintf (string3, "spin smash is slower and more powerful.");
948                                         }
949                                         if(tutorialstage==49){
950                                                 sprintf (string, "When facing an enemy, you can throw the knife with %s.",Input::keyToChar(throwkey));
951                                                 sprintf (string2, "It is possible to throw the knife while flipping,");
952                                                 sprintf (string3, "but it is very inaccurate.");
953                                         }
954                                         if(tutorialstage==50){
955                                                 sprintf (string, "You now know everything you can learn from training.");
956                                                 sprintf (string2, "Everything else you must learn from experience!");
957                                                 sprintf (string3, " ");
958                                         }
959                                         if(tutorialstage==51){
960                                                 sprintf (string, "Walk out of the training area to return to the main menu.");
961                                                 sprintf (string2, " ");
962                                                 sprintf (string3, " ");
963                                         }
964
965                                         glColor4f(0,0,0,tutorialopac);
966                                         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);
967                                         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);
968                                         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);
969                                         glColor4f(1,1,1,tutorialopac);
970                                         text.glPrint(screenwidth/2-7.6*strlen(string)*screenwidth/1024,screenheight/16+screenheight*4/5,string,1,1.5*screenwidth/1024,screenwidth,screenheight);
971                                         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);
972                                         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);
973
974                                         sprintf (string, "Press 'tab' to skip to the next item.",Input::keyToChar(jumpkey));
975                                         sprintf (string2, "Press escape at any time to");
976                                         sprintf (string3, "pause or exit the tutorial.");
977
978                                         glColor4f(0,0,0,1);
979                                         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);
980                                         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);
981                                         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);
982                                         glColor4f(0.5,0.5,0.5,1);
983                                         text.glPrint(screenwidth/2-7.6*strlen(string)*screenwidth/1024*.8,0+screenheight*1/10,string,1,1.5*screenwidth/1024*.8,screenwidth,screenheight);
984                                         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);
985                                         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);
986                                 }
987                                 //Hot spots     
988
989                                 if(numhotspots&&(bonustime>=1||bonus<=0||bonustime<0)&&!tutoriallevel){
990                                         int closest=-1;
991                                         float closestdist=-1;
992                                         float distance=0;
993                                         closest=currenthotspot;
994                                         for(i=0;i<numhotspots;i++){
995                                                 distance=findDistancefast(&player[0].coords,&hotspot[i]);
996                                                 if(closestdist==-1||distance<closestdist){
997                                                         if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i]&&((hotspottype[i]<=10&&hotspottype[i]>=0)||(hotspottype[i]<=40&&hotspottype[i]>=20))){
998                                                                 closestdist=distance;
999                                                                 closest=i;
1000                                                         }
1001                                                 }
1002                                         }
1003                                         if(closest!=-1)
1004                                                 currenthotspot=closest;
1005                                         if(currenthotspot!=-1){
1006                                                 if(hotspottype[closest]<=10){
1007                                                         if(findDistancefast(&player[0].coords,&hotspot[closest])<hotspotsize[closest])
1008                                                                 tutorialstagetime=0;
1009                                                         tutorialmaxtime=1;
1010                                                         tutorialopac=tutorialmaxtime-tutorialstagetime;
1011                                                         if(tutorialopac>1)tutorialopac=1;
1012                                                         if(tutorialopac<0)tutorialopac=0;
1013
1014                                                         sprintf (string, "%s", hotspottext[closest]);
1015
1016                                                         int lastline;
1017                                                         int line=0;
1018                                                         bool done=0;
1019                                                         lastline=0;
1020                                                         i=0;
1021                                                         while(!done){
1022                                                                 if(string[i]=='\n'||string[i]>'z'||string[i]<' '||string[i]=='\0'){
1023                                                                         glColor4f(0,0,0,tutorialopac);
1024                                                                         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);
1025                                                                         glColor4f(1,1,1,tutorialopac);
1026                                                                         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);
1027                                                                         lastline=i+1;
1028                                                                         line++;
1029                                                                         if(string[i]=='\0')done=1;
1030                                                                 }
1031                                                                 if(i>=255)done=1;
1032                                                                 i++;
1033                                                         }
1034                                                 }
1035                                                 else if (hotspottype[closest]>=20&&dialoguegonethrough[hotspottype[closest]-20]==0){
1036                                                         whichdialogue=hotspottype[closest]-20;
1037                                                         for(j=0;j<numdialogueboxes[whichdialogue];j++){
1038                                                                 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
1039                                                                 player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
1040                                                                 player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
1041                                                                 player[participantfocus[whichdialogue][j]].velocity=0;
1042                                                                 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
1043                                                                 player[participantfocus[whichdialogue][j]].targetframe=0;
1044                                                         }
1045                                                         directing=0;
1046                                                         indialogue=0;
1047                                                         dialoguegonethrough[whichdialogue]++;
1048                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
1049                                                                 static float gLoc[3];
1050                                                                 static float vel[3];
1051                                                                 gLoc[0]=player[participantfocus[whichdialogue][indialogue]].coords.x;
1052                                                                 gLoc[1]=player[participantfocus[whichdialogue][indialogue]].coords.y;
1053                                                                 gLoc[2]=player[participantfocus[whichdialogue][indialogue]].coords.z;
1054                                                                 vel[0]=0;
1055                                                                 vel[1]=0;
1056                                                                 vel[2]=0;
1057                                                                 int whichsoundplay;
1058                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
1059                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
1060                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
1061                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
1062                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
1063                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
1064                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
1065                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
1066                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
1067                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
1068                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
1069                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
1070                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
1071                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
1072                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
1073                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
1074                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
1075                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
1076                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
1077                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
1078                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
1079                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
1080                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
1081                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
1082                                                         }
1083                                                 }
1084                                         }
1085                                 }
1086
1087                                 if(indialogue!=-1&&!mainmenu){
1088                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1089                                         glDisable(GL_CULL_FACE);
1090                                         glDisable(GL_LIGHTING);
1091                                         glDisable(GL_TEXTURE_2D);
1092                                         glDepthMask(0);
1093                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1094                                         glPushMatrix();                                                                         // Store The Projection Matrix
1095                                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1096                                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1097                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1098                                         glPushMatrix();                                                                         // Store The Modelview Matrix
1099                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1100                                         if(dialogueboxlocation[whichdialogue][indialogue]==1)glTranslatef(0,screenheight*3/4,0);
1101                                         glScalef(screenwidth,screenheight/4,1);
1102                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1103                                         glEnable(GL_BLEND);
1104
1105                                         glColor4f(dialogueboxcolor[whichdialogue][indialogue][0],dialogueboxcolor[whichdialogue][indialogue][1],dialogueboxcolor[whichdialogue][indialogue][2],0.7);
1106                                         glBegin(GL_QUADS);
1107                                         glVertex3f(0,           0,       0.0f);
1108                                         glVertex3f(1,   0,       0.0f);
1109                                         glVertex3f(1,   1, 0.0f);
1110                                         glVertex3f(0,   1, 0.0f);
1111                                         glEnd();
1112                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1113                                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1114                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1115                                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1116                                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1117                                         glEnable(GL_CULL_FACE);
1118                                         glDisable(GL_BLEND);
1119                                         glDepthMask(1);
1120                                         glEnable(GL_TEXTURE_2D);
1121
1122                                         tutorialopac=1;
1123
1124                                         float startx;
1125                                         float starty;
1126
1127                                         startx=screenwidth*1/5;
1128                                         if(dialogueboxlocation[whichdialogue][indialogue]==1)starty=screenheight/16+screenheight*4/5;
1129                                         if(dialogueboxlocation[whichdialogue][indialogue]==2)starty=screenheight*1/5-screenheight/16;
1130
1131 //                                      char tempname[64];
1132                                         char tempname[264];
1133                                         bool goodchar;
1134                                         int tempnum=0;
1135 //                                      for(i=0;i<64;i++){
1136                                         for(i=0;i<264;i++){
1137                                                 tempname[i]='\0';
1138                                         }
1139
1140                                         for(i=0;i<(int)strlen(dialoguename[whichdialogue][indialogue]);i++){
1141                                                 tempname[tempnum]=dialoguename[whichdialogue][indialogue][i];
1142                                                 goodchar=1;
1143                                                 if(dialoguename[whichdialogue][indialogue][i]=='#'||dialoguename[whichdialogue][indialogue][i]=='\0')goodchar=0;
1144                                                 //if(tempnum>2)if(tempname[tempnum-2]=='e'&&tempname[tempnum-1]=='r')goodchar=0;
1145                                                 //if(tempnum>2)if(tempname[tempnum]=='r'&&tempname[0]=='a')goodchar=0;
1146                                                 if(goodchar)tempnum++;
1147                                                 else tempname[tempnum]='\0';
1148                                         }
1149
1150                                         sprintf (string, "%s: ", tempname);
1151
1152                                         if(dialogueboxcolor[whichdialogue][indialogue][0]+dialogueboxcolor[whichdialogue][indialogue][1]+dialogueboxcolor[whichdialogue][indialogue][2]<1.5){
1153                                                 glColor4f(0,0,0,tutorialopac);
1154                                                 text.glPrintOutline(startx-2*7.6*strlen(string)*screenwidth/1024-4,starty-4,string,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight);
1155                                                 glColor4f(0.7,0.7,0.7,tutorialopac);
1156                                                 text.glPrint(startx-2*7.6*strlen(string)*screenwidth/1024,starty,string,1,1.5*screenwidth/1024,screenwidth,screenheight);
1157                                         }
1158                                         else
1159                                         {
1160                                                 glColor4f(0,0,0,tutorialopac);
1161                                                 text.glPrintOutline(startx-2*7.6*strlen(string)*screenwidth/1024-4,starty-4,string,1,1.5*1.25*screenwidth/1024,screenwidth,screenheight);
1162
1163                                         }
1164
1165                                         tempnum=0;
1166                                         for(i=0;i<(int)strlen(dialoguetext[whichdialogue][indialogue])+1;i++){
1167                                                 tempname[tempnum]=dialoguetext[whichdialogue][indialogue][i];
1168                                                 if(dialoguetext[whichdialogue][indialogue][i]!='#')tempnum++;
1169                                         }
1170
1171
1172                                         sprintf (string, "%s", tempname);
1173
1174
1175                                         int lastline;
1176                                         int line=0;
1177                                         bool done=0;
1178                                         lastline=0;
1179                                         i=0;
1180                                         while(!done){
1181                                                 if(string[i]=='\n'||string[i]>'z'||string[i]<' '||string[i]=='\0'){
1182                                                         if(dialogueboxcolor[whichdialogue][indialogue][0]+dialogueboxcolor[whichdialogue][indialogue][1]+dialogueboxcolor[whichdialogue][indialogue][2]<1.5){
1183                                                                 glColor4f(0,0,0,tutorialopac);
1184                                                                 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);
1185                                                                 glColor4f(1,1,1,tutorialopac);
1186                                                                 text.glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/,starty-20*screenwidth/1024*line,string,1,1.5*screenwidth/1024,screenwidth,screenheight,lastline,i);
1187                                                         }
1188                                                         else
1189                                                         {
1190                                                                 glColor4f(0,0,0,tutorialopac);
1191                                                                 text.glPrint(startx/*-7.6*(i-lastline)*screenwidth/1024*/,starty-20*screenwidth/1024*line,string,1,1.5*screenwidth/1024,screenwidth,screenheight,lastline,i);
1192                                                         }
1193                                                         lastline=i+1;
1194                                                         line++;
1195                                                         if(string[i]=='\0')done=1;
1196                                                 }
1197                                                 if(i>=255)done=1;
1198                                                 i++;
1199                                         }
1200                                 }       
1201
1202                                 if(!tutoriallevel&&!winfreeze&&indialogue==-1&&!mainmenu){
1203                                         if(campaign){
1204                                                 if(!scoreadded)sprintf (string, "Score: %d", (int)accountactive->getCampaignScore()+(int)bonustotal);//(int)bonustotal);
1205                                                 if(scoreadded)sprintf (string, "Score: %d", (int)accountactive->getCampaignScore());//(int)bonustotal);
1206                                         }
1207                                         if(!campaign)sprintf (string, "Score: %d", (int)bonustotal);
1208                                         glColor4f(0,0,0,1);
1209                                         text.glPrintOutline(1024/40-4,768/16-4+768*14/16,string,1,1.5*1.25,1024,768);
1210                                         glColor4f(1,0,0,1);
1211                                         text.glPrint(1024/40,768/16+768*14/16,string,1,1.5,1024,768);
1212                                         if(showdamagebar) {
1213                                                 glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1214                                                 glDisable(GL_CULL_FACE);
1215                                                 glDisable(GL_LIGHTING);
1216                                                 glDisable(GL_TEXTURE_2D);
1217                                                 glDepthMask(0);
1218                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1219                                                 glPushMatrix();                                                                         // Store The Projection Matrix
1220                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
1221                                                 glOrtho(0,screenwidth,0,screenheight,-100,100);         // Set Up An Ortho Screen
1222                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1223                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
1224                                                 glLoadIdentity();                                                                       // Reset The Modelview Matrix
1225                                                 glTranslatef(15,screenheight*17.5/20,0);
1226                                                 glScalef(screenwidth/3+20,screenheight/20,1);
1227                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1228                                                 glEnable(GL_BLEND);
1229                                                 glColor4f(0.0,0.4,0.0,0.7);
1230                                                 float bar=((float)player[0].damage)/player[0].damagetolerance;
1231                                                 glBegin(GL_QUADS);
1232                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1233                                                 glVertex3f(1,0,0.0f);
1234                                                 glVertex3f(1,1,0.0f);
1235                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1236                                                 glEnd();
1237                                                 glColor4f(0.1,0.0,0.0,1);
1238                                                 bar = ((float)player[0].bloodloss)/player[0].damagetolerance;
1239                                                 glBegin(GL_QUADS);
1240                                                 glVertex3f(0,0,0.0f);
1241                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1242                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1243                                                 glVertex3f(0,1,0.0f);
1244                                                 glEnd();
1245                                                 glColor4f(0.4,0.0,0.0,0.7);
1246                                                 bar = ((float)player[0].damage)/player[0].damagetolerance;
1247                                                 glBegin(GL_QUADS);
1248                                                 glVertex3f(0,0,0.0f);
1249                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1250                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1251                                                 glVertex3f(0,1,0.0f);
1252                                                 glEnd();
1253                                                 glColor4f(0.4,0.0,0.0,0.7);
1254                                                 bar = ((float)player[0].permanentdamage)/player[0].damagetolerance;
1255                                                 glBegin(GL_QUADS);
1256                                                 glVertex3f(0,0,0.0f);
1257                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1258                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1259                                                 glVertex3f(0,1,0.0f);
1260                                                 glEnd();
1261                                                 glColor4f(0.4,0.0,0.0,0.7);
1262                                                 bar = ((float)player[0].superpermanentdamage)/player[0].damagetolerance;
1263                                                 glBegin(GL_QUADS);
1264                                                 glVertex3f(0,0,0.0f);
1265                                                 glVertex3f((bar<1?bar:1),0,0.0f);
1266                                                 glVertex3f((bar<1?bar:1),1,0.0f);
1267                                                 glVertex3f(0,1,0.0f);
1268                                                 glEnd();
1269                                                 glColor4f(0.0,0.0,0.0,0.7);
1270                                                 glLineWidth(2.0);
1271                                                 glBegin(GL_LINE_STRIP);
1272                                                 glVertex3f(0,0,0.0f);
1273                                                 glVertex3f(1,0,0.0f);
1274                                                 glVertex3f(1,1,0.0f);
1275                                                 glVertex3f(0,1,0.0f);
1276                                                 glVertex3f(0,0,0.0f);
1277                                                 glEnd();
1278                                                 
1279                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1280                                                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
1281                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1282                                                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
1283                                                 glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1284                                                 glEnable(GL_CULL_FACE);
1285                                                 glDisable(GL_BLEND);
1286                                                 glDepthMask(1);
1287                                                 glEnable(GL_TEXTURE_2D);
1288                                                 
1289                                                 // writing the numbers : 
1290                                                 sprintf (string, "Damages : %d/%d (%d)",(int)(player[0].damage),(int)(player[0].damagetolerance),(int)(player[0].bloodloss));
1291                                                 glColor4f(0,0,0,1);
1292                                                 text.glPrintOutline(1024/40-4,768/16-4+768*14/16-40,string,1,1.5*1.25,1024,768);
1293                                                 glColor4f(1,0,0,1);
1294                                                 text.glPrint(1024/40,768/16+768*14/16-40,string,1,1.5,1024,768);
1295                                         }
1296                                 }
1297
1298                                 glColor4f(.5,.5,.5,1);
1299
1300
1301                                 if((texttoggle||editorenabled)&&debugmode&&!mainmenu){
1302                                         sprintf (string, "The framespersecond is %d.",(int)(fps));
1303                                         text.glPrint(10,30,string,0,.8,1024,768);
1304
1305                                         sprintf (string, "Name: %s", registrationname);
1306                                         text.glPrint(10,260,string,0,.8,1024,768);
1307
1308
1309                                         if(editorenabled)sprintf (string, "Map editor enabled.");
1310                                         if(!editorenabled)sprintf (string, "Map editor Disabled.");
1311                                         text.glPrint(10,60,string,0,.8,1024,768);
1312                                         if(editorenabled){
1313                                                 sprintf (string, "Object size: %f",editorsize);
1314                                                 text.glPrint(10,75,string,0,.8,1024,768);
1315                                                 if(editorrotation>=0)sprintf (string, "Object rotation: %f",editorrotation);
1316                                                 else sprintf (string, "Object rotation: Random");
1317                                                 text.glPrint(10,90,string,0,.8,1024,768);
1318                                                 if(editorrotation2>=0)sprintf (string, "Object rotation2: %f",editorrotation2);
1319                                                 else sprintf (string, "Object rotation2: Random");
1320                                                 text.glPrint(10,105,string,0,.8,1024,768);
1321                                                 sprintf (string, "Object type: %d",editortype);
1322                                                 text.glPrint(10,120,string,0,.8,1024,768);
1323                                                 if(editortype==boxtype)sprintf (string, "(box)");
1324                                                 if(editortype==treetrunktype)sprintf (string, "(tree)");
1325                                                 if(editortype==walltype)sprintf (string, "(wall)");
1326                                                 if(editortype==weirdtype)sprintf (string, "(weird)");
1327                                                 if(editortype==spiketype)sprintf (string, "(spike)");
1328                                                 if(editortype==rocktype)sprintf (string, "(rock)");
1329                                                 if(editortype==bushtype)sprintf (string, "(bush)");
1330                                                 if(editortype==tunneltype)sprintf (string, "(tunnel)");
1331                                                 if(editortype==chimneytype)sprintf (string, "(chimney)");
1332                                                 if(editortype==platformtype)sprintf (string, "(platform)");
1333                                                 if(editortype==cooltype)sprintf (string, "(cool)");
1334                                                 if(editortype==firetype)sprintf (string, "(fire)");
1335                                                 text.glPrint(130,120,string,0,.8,1024,768);
1336
1337                                                 sprintf (string, "Numplayers: %d",numplayers);
1338                                                 text.glPrint(10,155,string,0,.8,1024,768);
1339                                                 sprintf (string, "Player %d: numwaypoints: %d",numplayers,player[numplayers-1].numwaypoints);
1340                                                 text.glPrint(10,140,string,0,.8,1024,768);
1341                                         }
1342                                         /*sprintf (string, "Coords are: %f %f %f",player[0].coords.x,player[0].coords.y,player[0].coords.z);
1343                                         text.glPrint(10,200,string,0,.8,1024,768);*/
1344                                         sprintf (string, "Difficulty: %d",difficulty);
1345                                         text.glPrint(10,240,string,0,.8,1024,768);
1346                                         /*
1347                                         sprintf (string, "lasthotspot: %d",hotspottype[numhotspots-1]);
1348                                         text.glPrint(10,240,string,0,.8,1024,768);
1349                                         sprintf (string, "killhotspot: %d",killhotspot);
1350                                         text.glPrint(10,220,string,0,.8,1024,768);
1351                                         sprintf (string, "winhotspot: %d",winhotspot);
1352                                         text.glPrint(10,200,string,0,.8,1024,768);*/
1353
1354                                 }
1355                 }
1356
1357                 if(drawmode==glowmode){
1358                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1359                         glDisable(GL_CULL_FACE);
1360                         glDisable(GL_LIGHTING);
1361                         glDisable(GL_TEXTURE_2D);
1362                         glDepthMask(0);
1363                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1364                         glPushMatrix();                                                                         // Store The Projection Matrix
1365                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1366                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1367                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1368                         glPushMatrix();                                                                         // Store The Modelview Matrix
1369                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1370                         glScalef(screenwidth,screenheight,1);
1371                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1372                         glEnable(GL_BLEND);
1373                         glColor4f(0,0,0,.5);
1374                         glBegin(GL_QUADS);
1375                         glVertex3f(0,           0,       0.0f);
1376                         glVertex3f(256, 0,       0.0f);
1377                         glVertex3f(256, 256, 0.0f);
1378                         glVertex3f(0,   256, 0.0f);
1379                         glEnd();
1380                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1381                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1382                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1383                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1384                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1385                         glEnable(GL_CULL_FACE);
1386                         glDisable(GL_BLEND);
1387                         glDepthMask(1);
1388                 }
1389
1390                 if((((blackout&&damageeffects)||(player[0].bloodloss>0&&damageeffects&&player[0].blooddimamount>0)||player[0].dead)&&!cameramode)||console){
1391                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1392                         glDisable(GL_CULL_FACE);
1393                         glDisable(GL_LIGHTING);
1394                         glDisable(GL_TEXTURE_2D);
1395                         glDepthMask(0);
1396                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1397                         glPushMatrix();                                                                         // Store The Projection Matrix
1398                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1399                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1400                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1401                         glPushMatrix();                                                                         // Store The Modelview Matrix
1402                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1403                         glScalef(screenwidth,screenheight,1);
1404                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1405                         glEnable(GL_BLEND);
1406                         if(player[0].dead)blackout+=multiplier*3;
1407                         if(player[0].dead==1)blackout=.4f;
1408                         if(player[0].dead==2&&blackout>.6)blackout=.6;
1409                         glColor4f(0,0,0,blackout);
1410                         if(!player[0].dead){
1411                                 if((player[0].bloodloss/player[0].damagetolerance*(sin(woozy)/4+.5))*.3<.3){
1412                                         glColor4f(0,0,0,player[0].blooddimamount*player[0].bloodloss/player[0].damagetolerance*(sin(woozy)/4+.5)*.3);
1413                                         blackout=player[0].blooddimamount*player[0].bloodloss/player[0].damagetolerance*(sin(woozy)/4+.5)*.3;
1414                                 }
1415                                 else {
1416                                         glColor4f(0,0,0,player[0].blooddimamount*.3);
1417                                         blackout=player[0].blooddimamount*.3;
1418                                 }
1419                         }
1420                         if(console)glColor4f(.7,0,0,.2);
1421                         glBegin(GL_QUADS);
1422                         glVertex3f(0,           0,       0.0f);
1423                         glVertex3f(256, 0,       0.0f);
1424                         glVertex3f(256, 256, 0.0f);
1425                         glVertex3f(0,   256, 0.0f);
1426                         glEnd();
1427                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1428                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1429                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1430                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1431                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1432                         glEnable(GL_CULL_FACE);
1433                         glDisable(GL_BLEND);
1434                         glDepthMask(1);
1435                 }
1436
1437                 if(flashamount>0&&damageeffects){
1438                         if(flashamount>1)flashamount=1;
1439                         if(flashdelay<=0)flashamount-=multiplier;
1440                         flashdelay--;
1441                         if(flashamount<0)flashamount=0;
1442                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1443                         glDisable(GL_CULL_FACE);
1444                         glDisable(GL_LIGHTING);
1445                         glDepthMask(0);
1446                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1447                         glPushMatrix();                                                                         // Store The Projection Matrix
1448                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1449                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1450                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1451                         glPushMatrix();                                                                         // Store The Modelview Matrix
1452                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1453                         glScalef(screenwidth,screenheight,1);
1454                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1455                         glEnable(GL_BLEND);
1456                         glColor4f(flashr,flashg,flashb,flashamount);
1457                         glBegin(GL_QUADS);
1458                         glVertex3f(0,           0,       0.0f);
1459                         glVertex3f(256, 0,       0.0f);
1460                         glVertex3f(256, 256, 0.0f);
1461                         glVertex3f(0,   256, 0.0f);
1462                         glEnd();
1463                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1464                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1465                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1466                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1467                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1468                         glEnable(GL_CULL_FACE);
1469                         glDisable(GL_BLEND);
1470                         glDepthMask(1);
1471                 }       
1472
1473                 if(!console){
1474                         displaytime[0]=0;
1475                         glEnable(GL_TEXTURE_2D);
1476                         glColor4f(1,1,1,1);
1477                         if(chatting){
1478                                 sprintf (string, " ]");
1479                                 text.glPrint(10,30+screenheight-330,string,0,1,screenwidth,screenheight);
1480                                 if(displayblink){
1481                                         sprintf (string, "_");
1482                                         text.glPrint(30+(float)(displayselected)*10,30+(screenheight-330),string,0,1,screenwidth,screenheight);
1483                                 }
1484                         }
1485                         for(i=0;i<15;i++){
1486                                 if((i!=0||chatting)&&displaytime[i]<4)
1487                                         for(j=0;j<displaychars[i];j++){
1488                                                 glColor4f(1,1,1,4-displaytime[i]);
1489                                                 if(j<displaychars[i]){
1490                                                         sprintf (string, "%c",displaytext[i][j]);
1491                                                         text.glPrint(30+j*10,30+i*20+(screenheight-330),string,0,1,screenwidth,screenheight);
1492                                                 }
1493                                         }
1494                         }
1495                 }
1496
1497                 if(minimap&&indialogue==-1){
1498                         float mapviewdist;
1499                         mapviewdist=20000;
1500
1501                         glDisable(GL_DEPTH_TEST);
1502                         glColor3f (1.0, 1.0, 1.0); // no coloring
1503
1504                         glEnable(GL_TEXTURE_2D);
1505                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1506                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1507                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1508                         glDisable(GL_CULL_FACE);
1509                         glDisable(GL_LIGHTING);
1510                         glDepthMask(0);
1511                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1512                         glPushMatrix();                                                                         // Store The Projection Matrix
1513                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1514                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1515                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1516                         glPushMatrix();                                                                         // Store The Modelview Matrix
1517                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1518                         glScalef((float)screenwidth/2,(float)screenwidth/2,1);
1519                         glTranslatef(1.75,.25,0);
1520                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1521                         glEnable(GL_BLEND);
1522                         glColor4f(1,1,1,1);
1523                         glPushMatrix();
1524                         float opac;
1525                         opac=.7;
1526                         XYZ center;
1527                         float radius;
1528                         float distcheck;
1529                         center=0;
1530                         int numliveplayers=0;
1531                         for(i=0;i<numplayers;i++){
1532                                 if(!player[i].dead)numliveplayers++;
1533                         }
1534
1535                         int numadd;
1536                         numadd=0;
1537
1538                         for(i=0;i<objects.numobjects;i++){
1539                                 if(objects.type[i]==treetrunktype||objects.type[i]==boxtype){
1540                                         center+=objects.position[i];    
1541                                         numadd++;
1542                                 }
1543                         }
1544                         for(i=0;i<numplayers;i++){
1545                                 if(!player[i].dead)center+=player[i].coords;    
1546                         }
1547                         center/=numadd+numliveplayers;
1548
1549                         center=player[0].coords;
1550
1551                         float maxdistance=0;
1552                         float tempdist;
1553                         int whichclosest;
1554                         for(i=0;i<objects.numobjects;i++){
1555                                 tempdist=findDistancefast(&center,&objects.position[i]);
1556                                 if(tempdist>maxdistance){
1557                                         whichclosest=i;
1558                                         maxdistance=tempdist;
1559                                 }
1560                         }
1561                         for(i=0;i<numplayers;i++){
1562                                 if(!player[i].dead){
1563                                         tempdist=findDistancefast(&center,&player[i].coords);
1564                                         if(tempdist>maxdistance){
1565                                                 whichclosest=i;
1566                                                 maxdistance=tempdist;
1567                                         }
1568                                 }
1569                         }
1570                         radius=fast_sqrt(maxdistance);
1571
1572                         radius=110;
1573
1574                         glScalef(.25/radius*256*terrain.scale*.4,.25/radius*256*terrain.scale*.4,1);
1575                         glPushMatrix();
1576                         glScalef(1/(1/radius*256*terrain.scale*.4),1/(1/radius*256*terrain.scale*.4),1);
1577                         /*float startx,starty,endx,endy;
1578                         glBegin(GL_QUADS);
1579                         glTexCoord2f(1-(center.x-radius)/terrain.scale/256,(center.z-radius)/terrain.scale/256);
1580                         glVertex3f(-1,          -1,      0.0f);
1581                         glTexCoord2f(1-(center.x+radius)/terrain.scale/256,(center.z-radius)/terrain.scale/256);
1582                         glVertex3f(1,   -1,      0.0f);
1583                         glTexCoord2f(1-(center.x+radius)/terrain.scale/256,(center.z+radius)/terrain.scale/256);
1584                         glVertex3f(1,   1, 0.0f);
1585                         glTexCoord2f(1-(center.x-radius)/terrain.scale/256,(center.z+radius)/terrain.scale/256);
1586                         glVertex3f(-1,  1, 0.0f);
1587                         glEnd();*/
1588                         glPopMatrix();
1589                         glRotatef(player[0].lookrotation*-1+180,0,0,1);
1590                         glTranslatef(-(center.x/terrain.scale/256*-2+1),(center.z/terrain.scale/256*-2+1),0);
1591                         for(i=0;i<objects.numobjects;i++){
1592                                 if(objects.type[i]==treetrunktype){
1593                                         distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
1594                                         if(distcheck<mapviewdist){
1595                                                 glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
1596                                                 glColor4f(0,.3,0,opac*(1-distcheck/mapviewdist));
1597                                                 glPushMatrix();
1598                                                 glTranslatef(objects.position[i].x/terrain.scale/256*-2+1,objects.position[i].z/terrain.scale/256*2-1,0);
1599                                                 glRotatef(objects.rotation[i],0,0,1);
1600                                                 glScalef(.003,.003,.003);
1601                                                 glBegin(GL_QUADS);
1602                                                 glTexCoord2f(0,0);
1603                                                 glVertex3f(-1,          -1,      0.0f);
1604                                                 glTexCoord2f(1,0);
1605                                                 glVertex3f(1,   -1,      0.0f);
1606                                                 glTexCoord2f(1,1);
1607                                                 glVertex3f(1,   1, 0.0f);
1608                                                 glTexCoord2f(0,1);
1609                                                 glVertex3f(-1,  1, 0.0f);
1610                                                 glEnd();
1611                                                 glPopMatrix();
1612                                         }
1613                                 }
1614                                 if(objects.type[i]==boxtype){
1615                                         distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
1616                                         if(distcheck<mapviewdist){
1617                                                 glBindTexture( GL_TEXTURE_2D, Mapboxtexture);
1618                                                 glColor4f(.4,.4,.4,opac*(1-distcheck/mapviewdist));
1619                                                 glPushMatrix();
1620                                                 glTranslatef(objects.position[i].x/terrain.scale/256*-2+1,objects.position[i].z/terrain.scale/256*2-1,0);
1621                                                 glRotatef(objects.rotation[i],0,0,1);
1622                                                 glScalef(.01*objects.scale[i],.01*objects.scale[i],.01*objects.scale[i]);
1623                                                 glBegin(GL_QUADS);
1624                                                 glTexCoord2f(0,0);
1625                                                 glVertex3f(-1,          -1,      0.0f);
1626                                                 glTexCoord2f(1,0);
1627                                                 glVertex3f(1,   -1,      0.0f);
1628                                                 glTexCoord2f(1,1);
1629                                                 glVertex3f(1,   1, 0.0f);
1630                                                 glTexCoord2f(0,1);
1631                                                 glVertex3f(-1,  1, 0.0f);
1632                                                 glEnd();
1633                                                 glPopMatrix();
1634                                         }
1635                                 }
1636                         }
1637                         if(editorenabled){
1638                                 glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
1639                                 for(i=0;i<numboundaries;i++){
1640                                         glColor4f(0,0,0,opac/3);
1641                                         glPushMatrix();
1642                                         glTranslatef(boundary[i].x/terrain.scale/256*-2+1,boundary[i].z/terrain.scale/256*2-1,0);
1643                                         glScalef(.002,.002,.002);
1644                                         glBegin(GL_QUADS);
1645                                         glTexCoord2f(0,0);
1646                                         glVertex3f(-1,          -1,      0.0f);
1647                                         glTexCoord2f(1,0);
1648                                         glVertex3f(1,   -1,      0.0f);
1649                                         glTexCoord2f(1,1);
1650                                         glVertex3f(1,   1, 0.0f);
1651                                         glTexCoord2f(0,1);
1652                                         glVertex3f(-1,  1, 0.0f);
1653                                         glEnd();
1654                                         glPopMatrix();
1655                                 }
1656                         }
1657                         for(i=0;i<numplayers;i++){
1658                                 distcheck=findDistancefast(&player[0].coords,&player[i].coords);
1659                                 if(distcheck<mapviewdist){
1660                                         glPushMatrix();
1661                                         glBindTexture( GL_TEXTURE_2D, Maparrowtexture);
1662                                         if(i==0)glColor4f(1,1,1,opac);
1663                                         else if(player[i].dead==2||player[i].howactive>typesleeping)glColor4f(0,0,0,opac*(1-distcheck/mapviewdist));
1664                                         else if(player[i].dead)glColor4f(.3,.3,.3,opac*(1-distcheck/mapviewdist));
1665                                         else if(player[i].aitype==attacktypecutoff)glColor4f(1,0,0,opac*(1-distcheck/mapviewdist));
1666                                         else if(player[i].aitype==passivetype)glColor4f(0,1,0,opac*(1-distcheck/mapviewdist));
1667                                         else glColor4f(1,1,0,1);
1668                                         glTranslatef(player[i].coords.x/terrain.scale/256*-2+1,player[i].coords.z/terrain.scale/256*2-1,0);
1669                                         glRotatef(player[i].rotation+180,0,0,1);
1670                                         glScalef(.005,.005,.005);
1671                                         glBegin(GL_QUADS);
1672                                         glTexCoord2f(0,0);
1673                                         glVertex3f(-1,          -1,      0.0f);
1674                                         glTexCoord2f(1,0);
1675                                         glVertex3f(1,   -1,      0.0f);
1676                                         glTexCoord2f(1,1);
1677                                         glVertex3f(1,   1, 0.0f);
1678                                         glTexCoord2f(0,1);
1679                                         glVertex3f(-1,  1, 0.0f);
1680                                         glEnd();
1681                                         /*glBegin(GL_TRIANGLES);
1682                                         glTexCoord2f(0,0);
1683                                         glVertex3f(-1,          -1,      0.0f);
1684                                         glTexCoord2f(1,0);
1685                                         glVertex3f(1,   -1,      0.0f);
1686                                         glTexCoord2f(1,1);
1687                                         glVertex3f(0,   1, 0.0f);
1688                                         glEnd();*/
1689                                         glPopMatrix();
1690                                 }
1691                         }
1692                         /*glBegin(GL_QUADS);
1693                         glTexCoord2f(0,0);
1694                         glVertex3f(-1,          -1,      0.0f);
1695                         glTexCoord2f(1,0);
1696                         glVertex3f(1,   -1,      0.0f);
1697                         glTexCoord2f(1,1);
1698                         glVertex3f(1,   1, 0.0f);
1699                         glTexCoord2f(0,1);
1700                         glVertex3f(-1,  1, 0.0f);
1701                         glEnd();*/
1702                         glPopMatrix();
1703                         glDisable(GL_TEXTURE_2D);
1704                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1705                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1706                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1707                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1708                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1709                         glEnable(GL_CULL_FACE);
1710                         glDisable(GL_BLEND);
1711                         glDepthMask(1);
1712                 }
1713
1714                 /*if(loading){
1715                 loading=2;
1716                 drawmode=normalmode;
1717                 }*/
1718
1719
1720                 if(loading&&!stealthloading&&(!campaign||player[0].dead)){
1721                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1722                         glDisable(GL_CULL_FACE);
1723                         glDisable(GL_LIGHTING);
1724                         glDisable(GL_TEXTURE_2D);
1725                         glDepthMask(0);
1726                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1727                         glPushMatrix();                                                                         // Store The Projection Matrix
1728                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1729                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1730                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1731                         glPushMatrix();                                                                         // Store The Modelview Matrix
1732                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1733                         glScalef(screenwidth,screenheight,1);
1734                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1735                         glEnable(GL_BLEND);
1736                         glColor4f(0,0,0,.7);
1737                         glBegin(GL_QUADS);
1738                         glVertex3f(0,           0,       0.0f);
1739                         glVertex3f(256, 0,       0.0f);
1740                         glVertex3f(256, 256, 0.0f);
1741                         glVertex3f(0,   256, 0.0f);
1742                         glEnd();
1743                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1744                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1745                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1746                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1747                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1748                         glEnable(GL_CULL_FACE);
1749                         glDisable(GL_BLEND);
1750                         glDepthMask(1);
1751
1752                         //logo
1753                         glDisable(GL_DEPTH_TEST);
1754                         glColor3f (1.0, 1.0, 1.0); // no coloring
1755
1756                         glEnable(GL_TEXTURE_2D);
1757                         /*glBindTexture( GL_TEXTURE_2D, logotexture);
1758                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1759                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1760                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1761                         glDisable(GL_CULL_FACE);
1762                         glDisable(GL_LIGHTING);
1763                         glDepthMask(0);
1764                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1765                         glPushMatrix();                                                                         // Store The Projection Matrix
1766                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1767                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1768                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1769                         glPushMatrix();                                                                         // Store The Modelview Matrix
1770                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1771                         glScalef((float)screenwidth/2,(float)screenwidth/2,1);
1772                         glTranslatef(1.8,1.25,0);
1773                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1774                         glEnable(GL_BLEND);
1775                         glColor4f(1,1,1,1);
1776                         glPushMatrix();
1777                         glScalef(.25,.25,.25);
1778                         glBegin(GL_QUADS);
1779                         glTexCoord2f(0,0);
1780                         glVertex3f(-1,          -1,      0.0f);
1781                         glTexCoord2f(1,0);
1782                         glVertex3f(1,   -1,      0.0f);
1783                         glTexCoord2f(1,1);
1784                         glVertex3f(1,   1, 0.0f);
1785                         glTexCoord2f(0,1);
1786                         glVertex3f(-1,  1, 0.0f);
1787                         glEnd();
1788                         glPopMatrix();
1789                         glDisable(GL_TEXTURE_2D);
1790                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1791                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1792                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1793                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1794                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1795                         glEnable(GL_CULL_FACE);
1796                         glDisable(GL_BLEND);
1797                         glDepthMask(1);*/
1798
1799                         //Minimap
1800
1801                         if(loading!=4){                         
1802                                 glEnable(GL_TEXTURE_2D);
1803                                 glColor4f(1,1,1,1);
1804                                 sprintf (string, "Loading...");
1805                                 text.glPrint(1024/2-90,768/2,string,1,2,1024,768);
1806                         }
1807                         loading=2;
1808                         //if(ismotionblur)drawmode=motionblurmode;
1809                         drawmode=normalmode;
1810                 }
1811
1812                 if(winfreeze&&!campaign){
1813                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1814                         glDisable(GL_CULL_FACE);
1815                         glDisable(GL_LIGHTING);
1816                         glDisable(GL_TEXTURE_2D);
1817                         glDepthMask(0);
1818                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1819                         glPushMatrix();                                                                         // Store The Projection Matrix
1820                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1821                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1822                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1823                         glPushMatrix();                                                                         // Store The Modelview Matrix
1824                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1825                         glScalef(screenwidth,screenheight,1);
1826                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1827                         glEnable(GL_BLEND);
1828                         glColor4f(0,0,0,.4);
1829                         glBegin(GL_QUADS);
1830                         glVertex3f(0,           0,       0.0f);
1831                         glVertex3f(256, 0,       0.0f);
1832                         glVertex3f(256, 256, 0.0f);
1833                         glVertex3f(0,   256, 0.0f);
1834                         glEnd();
1835                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1836                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1837                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1838                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1839                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1840                         glEnable(GL_CULL_FACE);
1841                         glDisable(GL_BLEND);
1842                         glDepthMask(1);
1843
1844                         //logo
1845                         glDisable(GL_DEPTH_TEST);
1846                         glColor3f (1.0, 1.0, 1.0); // no coloring
1847
1848                         glEnable(GL_TEXTURE_2D);
1849                         /*glBindTexture( GL_TEXTURE_2D, logotexture);
1850                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
1851                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
1852                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
1853                         glDisable(GL_CULL_FACE);
1854                         glDisable(GL_LIGHTING);
1855                         glDepthMask(0);
1856                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1857                         glPushMatrix();                                                                         // Store The Projection Matrix
1858                         glLoadIdentity();                                                                       // Reset The Projection Matrix
1859                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
1860                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1861                         glPushMatrix();                                                                         // Store The Modelview Matrix
1862                         glLoadIdentity();                                                               // Reset The Modelview Matrix
1863                         glScalef((float)screenwidth/2,(float)screenwidth/2,1);
1864                         glTranslatef(1.8,1.25,0);
1865                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1866                         glEnable(GL_BLEND);
1867                         glColor4f(1,1,1,1);
1868                         glPushMatrix();
1869                         glScalef(.25,.25,.25);
1870                         glBegin(GL_QUADS);
1871                         glTexCoord2f(0,0);
1872                         glVertex3f(-1,          -1,      0.0f);
1873                         glTexCoord2f(1,0);
1874                         glVertex3f(1,   -1,      0.0f);
1875                         glTexCoord2f(1,1);
1876                         glVertex3f(1,   1, 0.0f);
1877                         glTexCoord2f(0,1);
1878                         glVertex3f(-1,  1, 0.0f);
1879                         glEnd();
1880                         glPopMatrix();
1881                         glDisable(GL_TEXTURE_2D);
1882                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
1883                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1884                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1885                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
1886                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
1887                         glEnable(GL_CULL_FACE);
1888                         glDisable(GL_BLEND);
1889                         glDepthMask(1);*/
1890
1891                         //Awards
1892                         int numawards;
1893                         int awards[30];
1894                         numawards=0;
1895
1896                         if(damagetaken==0&&player[0].bloodloss==0){
1897                                 awards[numawards]=awardflawless;
1898                                 numawards++;
1899                         }
1900                         bool alldead;
1901                         alldead=1;
1902                         if(numplayers>1)
1903                                 for(i=1;i<numplayers;i++){              
1904                                         if(player[i].dead!=2)alldead=0;
1905                                 }
1906                                 if(alldead){
1907                                         awards[numawards]=awardalldead;
1908                                         numawards++;
1909                                 }
1910                                 alldead=1;
1911                                 if(numplayers>1)
1912                                         for(i=1;i<numplayers;i++){              
1913                                                 if(player[i].dead!=1)alldead=0;
1914                                         }
1915                                         if(alldead){
1916                                                 awards[numawards]=awardnodead;
1917                                                 numawards++;
1918                                         }
1919                                         if(numresponded==0&&!numthrowkill){
1920                                                 awards[numawards]=awardstealth;
1921                                                 numawards++;
1922                                         }
1923                                         if(numattacks==numstaffattack&&numattacks>0){
1924                                                 awards[numawards]=awardbojutsu;
1925                                                 numawards++;
1926                                         }
1927                                         if(numattacks==numswordattack&&numattacks>0){
1928                                                 awards[numawards]=awardswordsman;
1929                                                 numawards++;
1930                                         }
1931                                         if(numattacks==numknifeattack&&numattacks>0){
1932                                                 awards[numawards]=awardknifefighter;
1933                                                 numawards++;
1934                                         }
1935                                         if(numattacks==numunarmedattack&&numthrowkill==0&&weapons.numweapons>0){
1936                                                 awards[numawards]=awardkungfu;
1937                                                 numawards++;
1938                                         }
1939                                         if(numescaped>0){
1940                                                 awards[numawards]=awardevasion;
1941                                                 numawards++;
1942                                         }
1943                                         if(numflipfail==0&&numflipped+numwallflipped*2>20){
1944                                                 awards[numawards]=awardacrobat;
1945                                                 numawards++;
1946                                         }
1947                                         if(numthrowkill==numplayers-1){
1948                                                 awards[numawards]=awardlongrange;
1949                                                 numawards++;
1950                                         }
1951                                         alldead=1;
1952                                         if(numplayers>1)
1953                                                 for(i=1;i<numplayers;i++){              
1954                                                         if(player[i].dead!=2)alldead=0;
1955                                                 }
1956                                                 if(numafterkill>0&&alldead){
1957                                                         awards[numawards]=awardbrutal;
1958                                                         numawards++;
1959                                                 }
1960                                                 if(numreversals>((float)numattacks)*.8&&numreversals>3){
1961                                                         awards[numawards]=awardaikido;
1962                                                         numawards++;
1963                                                 }
1964                                                 if(maxalarmed==1&&numplayers>2){
1965                                                         awards[numawards]=awardstrategy;
1966                                                         numawards++;
1967                                                 }
1968                                                 if(numflipfail>3){
1969                                                         awards[numawards]=awardklutz;
1970                                                         numawards++;
1971                                                 }
1972
1973
1974                                                 //Win Screen Won Victory
1975
1976                                                 glEnable(GL_TEXTURE_2D);
1977                                                 glColor4f(1,1,1,1);
1978                                                 sprintf (string, "Level Cleared!");
1979                                                 text.glPrintOutlined(1024/2-strlen(string)*10,768*7/8,string,1,2,1024,768);
1980
1981                                                 sprintf (string, "Score:     %d",(int)(bonustotal-startbonustotal));
1982                                                 text.glPrintOutlined(1024/30,768*6/8,string,1,2,1024,768);
1983
1984                                                 if(!campaign)sprintf (string, "Press Escape to return to menu or Space to continue");
1985                                                 if(campaign)sprintf (string, "Press Escape or Space to continue");
1986                                                 text.glPrintOutlined(640/2-strlen(string)*5,480*1/16,string,1,1,640,480);
1987
1988                                                 char temp[255];
1989
1990                                                 for(i=0;i<255;i++)string[i]='\0';
1991                                                 sprintf (temp, "Time:      %d:",(int)(((int)leveltime-(int)(leveltime)%60)/60));
1992                                                 strcat(string,temp);
1993                                                 if((int)(leveltime)%60<10)strcat(string,"0");
1994                                                 sprintf (temp, "%d",(int)(leveltime)%60);
1995                                                 strcat(string,temp);
1996                                                 text.glPrintOutlined(1024/30,768*6/8-40,string,1,2,1024,768);
1997
1998                                                 for(i=0;i<numawards;i++){
1999                                                         if(i<6){
2000                                                                 if(awards[i]==awardklutz)sprintf (string, "Suicidal");
2001                                                                 if(awards[i]==awardflawless)sprintf (string, "Flawless!");
2002                                                                 if(awards[i]==awardalldead)sprintf (string, "Take no prisoners");
2003                                                                 if(awards[i]==awardnodead)sprintf (string, "Merciful");
2004                                                                 if(awards[i]==awardstealth)sprintf (string, "One with the shadows!");
2005                                                                 if(awards[i]==awardswordsman)sprintf (string, "Swordsman");
2006                                                                 if(awards[i]==awardkungfu)sprintf (string, "Unarmed!");
2007                                                                 if(awards[i]==awardknifefighter)sprintf (string, "Knife fighter");
2008                                                                 if(awards[i]==awardcoward)sprintf (string, "Coward");
2009                                                                 if(awards[i]==awardevasion)sprintf (string, "Escape artist");
2010                                                                 if(awards[i]==awardacrobat)sprintf (string, "Gymnast");
2011                                                                 if(awards[i]==awardlongrange)sprintf (string, "Blade slinger");
2012                                                                 if(awards[i]==awardbrutal)sprintf (string, "Brutal");
2013                                                                 if(awards[i]==awardhyper)sprintf (string, "Hyper");
2014                                                                 if(awards[i]==awardaikido)sprintf (string, "Aikido master!");
2015                                                                 if(awards[i]==awardrambo)sprintf (string, "Rambo");
2016                                                                 if(awards[i]==awardfast)sprintf (string, "Fast");
2017                                                                 if(awards[i]==awardrealfast)sprintf (string, "Real fast");
2018                                                                 if(awards[i]==awarddamnfast)sprintf (string, "Damn fast");
2019                                                                 if(awards[i]==awardstrategy)sprintf (string, "Divide and conquer");
2020                                                                 if(awards[i]==awardbojutsu)sprintf (string, "Bojutsu");
2021                                                                 text.glPrintOutlined(1024/30,768*6/8-90-40*i,string,1,2,1024,768);
2022                                                         }
2023                                                 }
2024
2025                                                 //drawmode=normalmode;
2026                 }
2027
2028                 if(drawmode!=normalmode){
2029                         glEnable(GL_TEXTURE_2D);
2030                         glFinish();
2031                         if(!drawtoggle||drawmode!=realmotionblurmode||(drawtoggle==2||change==1)){
2032                                 if(screentexture){
2033
2034                                         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
2035                                         GLfloat subtractColor[4] = { 0.5, 0.5, 0.5, 0.0 };
2036                                         glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, subtractColor);
2037                                         //glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_SUBTRACT);
2038                                         glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
2039                                         glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_CONSTANT_EXT);
2040                                         glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
2041
2042                                         glBindTexture( GL_TEXTURE_2D, screentexture);
2043                                         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);         
2044                                 }
2045                         }
2046                         if((drawtoggle||change==1)&&drawmode==realmotionblurmode){
2047                                 if(screentexture2){
2048                                         glBindTexture( GL_TEXTURE_2D, screentexture2);
2049                                         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, texviewwidth, texviewheight);         
2050                                 }
2051                                 if(!screentexture2){
2052                                         glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
2053
2054                                         glGenTextures( 1, &screentexture2 );
2055                                         glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
2056
2057                                         glEnable(GL_TEXTURE_2D);
2058                                         glBindTexture( GL_TEXTURE_2D, screentexture2);
2059                                         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
2060                                         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
2061
2062                                         glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);                
2063                                 }
2064                         }
2065                         //glFlush();
2066                 }
2067
2068                 glClear(GL_DEPTH_BUFFER_BIT);
2069                 ReSizeGLScene(90,.1f);
2070                 glViewport(0,0,screenwidth,screenheight);       
2071
2072                 if(drawmode!=normalmode){
2073                         glDisable(GL_DEPTH_TEST);
2074                         if(drawmode==motionblurmode){
2075                                 glDrawBuffer(GL_FRONT);
2076                                 glReadBuffer(GL_BACK);
2077                                 //myassert(glGetError() == GL_NO_ERROR);
2078                                 //glFlush();
2079                         }
2080                         glColor3f (1.0, 1.0, 1.0); // no coloring
2081
2082                         glEnable(GL_TEXTURE_2D);
2083                         glBindTexture( GL_TEXTURE_2D, screentexture);
2084                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
2085                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
2086                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
2087                         glDisable(GL_CULL_FACE);
2088                         glDisable(GL_LIGHTING);
2089                         glDepthMask(0);
2090                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2091                         glPushMatrix();                                                                         // Store The Projection Matrix
2092                         glLoadIdentity();                                                                       // Reset The Projection Matrix
2093                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
2094                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2095                         glPushMatrix();                                                                         // Store The Modelview Matrix
2096                         glLoadIdentity();                                                               // Reset The Modelview Matrix
2097                         glScalef((float)screenwidth/2,(float)screenheight/2,1);
2098                         glTranslatef(1,1,0);
2099                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2100                         glEnable(GL_BLEND);
2101                         if(drawmode==motionblurmode){
2102                                 if(motionbluramount<.2)motionbluramount=.2;
2103                                 //glColor4f(1,1,1,fast_sqrt(multiplier)*2.9*motionbluramount);
2104                                 glColor4f(1,1,1,motionbluramount);
2105                                 glPushMatrix();
2106                                 glBegin(GL_QUADS);
2107                                 glTexCoord2f(0,0);
2108                                 glVertex3f(-1,          -1,      0.0f);
2109                                 glTexCoord2f(texcoordwidth,0);
2110                                 glVertex3f(1,   -1,      0.0f);
2111                                 glTexCoord2f(texcoordwidth,texcoordheight);
2112                                 glVertex3f(1,   1, 0.0f);
2113                                 glTexCoord2f(0,texcoordheight);
2114                                 glVertex3f(-1,  1, 0.0f);
2115                                 glEnd();
2116                                 glPopMatrix();
2117                         }
2118                         if(drawmode==realmotionblurmode){
2119                                 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
2120                                 glClear(GL_COLOR_BUFFER_BIT);
2121                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
2122                                 glBindTexture( GL_TEXTURE_2D, screentexture);
2123                                 glColor4f(1,1,1,.5);
2124                                 glPushMatrix();
2125                                 glBegin(GL_QUADS);
2126                                 glTexCoord2f(0,0);
2127                                 glVertex3f(-1,          -1,      0.0f);
2128                                 glTexCoord2f(texcoordwidth,0);
2129                                 glVertex3f(1,   -1,      0.0f);
2130                                 glTexCoord2f(texcoordwidth,texcoordheight);
2131                                 glVertex3f(1,   1, 0.0f);
2132                                 glTexCoord2f(0,texcoordheight);
2133                                 glVertex3f(-1,  1, 0.0f);
2134                                 glEnd();
2135                                 glPopMatrix();
2136                                 glBindTexture( GL_TEXTURE_2D, screentexture2);
2137                                 glColor4f(1,1,1,.5);
2138                                 glPushMatrix();
2139                                 glBegin(GL_QUADS);
2140                                 glTexCoord2f(0,0);
2141                                 glVertex3f(-1,          -1,      0.0f);
2142                                 glTexCoord2f(texcoordwidth,0);
2143                                 glVertex3f(1,   -1,      0.0f);
2144                                 glTexCoord2f(texcoordwidth,texcoordheight);
2145                                 glVertex3f(1,   1, 0.0f);
2146                                 glTexCoord2f(0,texcoordheight);
2147                                 glVertex3f(-1,  1, 0.0f);
2148                                 glEnd();
2149                                 glPopMatrix();
2150                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2151                         }
2152                         if(drawmode==doublevisionmode){
2153                                 static float crosseyedness;
2154                                 crosseyedness=abs(player[0].damage-player[0].superpermanentdamage-(player[0].damagetolerance-player[0].superpermanentdamage)*1/2)/30;
2155                                 if(crosseyedness>1)crosseyedness=1;
2156                                 if(crosseyedness<0)crosseyedness=0;
2157                                 glColor4f(1,1,1,1);
2158                                 glDisable(GL_BLEND);
2159                                 glPushMatrix();
2160                                 glScalef(1,1,1);
2161                                 glBegin(GL_QUADS);
2162                                 glTexCoord2f(0,0);
2163                                 glVertex3f(-1,          -1,      0.0f);
2164                                 glTexCoord2f(texcoordwidth,0);
2165                                 glVertex3f(1,   -1,      0.0f);
2166                                 glTexCoord2f(texcoordwidth,texcoordheight);
2167                                 glVertex3f(1,   1, 0.0f);
2168                                 glTexCoord2f(0,texcoordheight);
2169                                 glVertex3f(-1,  1, 0.0f);
2170                                 glEnd();
2171                                 glPopMatrix();
2172                                 if(crosseyedness){
2173                                         glColor4f(1,1,1,.5);
2174                                         glEnable(GL_BLEND);
2175                                         glPushMatrix();
2176                                         glTranslatef(.015*crosseyedness,0,0);
2177                                         glScalef(1,1,1);
2178                                         glBegin(GL_QUADS);
2179                                         glTexCoord2f(0,0);
2180                                         glVertex3f(-1,          -1,      0.0f);
2181                                         glTexCoord2f(texcoordwidth,0);
2182                                         glVertex3f(1,   -1,      0.0f);
2183                                         glTexCoord2f(texcoordwidth,texcoordheight);
2184                                         glVertex3f(1,   1, 0.0f);
2185                                         glTexCoord2f(0,texcoordheight);
2186                                         glVertex3f(-1,  1, 0.0f);
2187                                         glEnd();
2188                                         glPopMatrix();
2189                                 }
2190                         }
2191                         if(drawmode==glowmode){
2192                                 glColor4f(.5,.5,.5,.5);
2193                                 glEnable(GL_BLEND);
2194                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
2195                                 glPushMatrix();
2196                                 glTranslatef(.01,0,0);
2197                                 glBegin(GL_QUADS);
2198                                 glTexCoord2f(0,0);
2199                                 glVertex3f(-1,          -1,      0.0f);
2200                                 glTexCoord2f(texcoordwidth,0);
2201                                 glVertex3f(1,   -1,      0.0f);
2202                                 glTexCoord2f(texcoordwidth,texcoordheight);
2203                                 glVertex3f(1,   1, 0.0f);
2204                                 glTexCoord2f(0,texcoordheight);
2205                                 glVertex3f(-1,  1, 0.0f);
2206                                 glEnd();
2207                                 glPopMatrix();
2208                                 glPushMatrix();
2209                                 glTranslatef(-.01,0,0);
2210                                 glBegin(GL_QUADS);
2211                                 glTexCoord2f(0,0);
2212                                 glVertex3f(-1,          -1,      0.0f);
2213                                 glTexCoord2f(texcoordwidth,0);
2214                                 glVertex3f(1,   -1,      0.0f);
2215                                 glTexCoord2f(texcoordwidth,texcoordheight);
2216                                 glVertex3f(1,   1, 0.0f);
2217                                 glTexCoord2f(0,texcoordheight);
2218                                 glVertex3f(-1,  1, 0.0f);
2219                                 glEnd();
2220                                 glPopMatrix();
2221                                 glPushMatrix();
2222                                 glTranslatef(.0,.01,0);
2223                                 glBegin(GL_QUADS);
2224                                 glTexCoord2f(0,0);
2225                                 glVertex3f(-1,          -1,      0.0f);
2226                                 glTexCoord2f(texcoordwidth,0);
2227                                 glVertex3f(1,   -1,      0.0f);
2228                                 glTexCoord2f(texcoordwidth,texcoordheight);
2229                                 glVertex3f(1,   1, 0.0f);
2230                                 glTexCoord2f(0,texcoordheight);
2231                                 glVertex3f(-1,  1, 0.0f);
2232                                 glEnd();
2233                                 glPopMatrix();
2234                                 glPushMatrix();
2235                                 glTranslatef(0,-.01,0);
2236                                 glBegin(GL_QUADS);
2237                                 glTexCoord2f(0,0);
2238                                 glVertex3f(-1,          -1,      0.0f);
2239                                 glTexCoord2f(texcoordwidth,0);
2240                                 glVertex3f(1,   -1,      0.0f);
2241                                 glTexCoord2f(texcoordwidth,texcoordheight);
2242                                 glVertex3f(1,   1, 0.0f);
2243                                 glTexCoord2f(0,texcoordheight);
2244                                 glVertex3f(-1,  1, 0.0f);
2245                                 glEnd();
2246                                 glPopMatrix();
2247                         }
2248                         if(drawmode==radialzoommode){
2249                                 for(i=0;i<3;i++){
2250                                         //glRotatef((float)i*.1,0,0,1);
2251                                         glColor4f(1,1,1,1/((float)i+1));
2252                                         glPushMatrix();
2253                                         glScalef(1+(float)i*.01,1+(float)i*.01,1);
2254                                         glBegin(GL_QUADS);
2255                                         glTexCoord2f(0,0);
2256                                         glVertex3f(-1,          -1,      0.0f);
2257                                         glTexCoord2f(texcoordwidth,0);
2258                                         glVertex3f(1,   -1,      0.0f);
2259                                         glTexCoord2f(texcoordwidth,texcoordheight);
2260                                         glVertex3f(1,   1, 0.0f);
2261                                         glTexCoord2f(0,texcoordheight);
2262                                         glVertex3f(-1,  1, 0.0f);
2263                                         glEnd();
2264                                         glPopMatrix();
2265                                 }
2266                         }
2267                         glDisable(GL_TEXTURE_2D);
2268                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2269                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
2270                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2271                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
2272                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
2273                         glEnable(GL_CULL_FACE);
2274                         glDisable(GL_BLEND);
2275                         glDepthMask(1);
2276                 }
2277
2278                 if(console){
2279                         glEnable(GL_TEXTURE_2D);
2280                         glColor4f(1,1,1,1);
2281                         if(console){
2282                                 int offset;
2283                                 offset=0;
2284                                 if(consoleselected>=60)offset=consoleselected-60;
2285                                 sprintf (string, " ]");
2286                                 text.glPrint(10,30,string,0,1,1024,768);
2287                                 if(consoleblink){
2288                                         sprintf (string, "_");
2289                                         text.glPrint(30+(float)(consoleselected)*10-offset*10,30,string,0,1,1024,768);
2290                                 }
2291                                 for(i=0;i<15;i++){
2292                                         for(j=0;j<consolechars[i];j++){
2293                                                 glColor4f(1,1,1,1-(float)(i)/16);
2294                                                 if(j<consolechars[i]){
2295                                                         sprintf (string, "%c",consoletext[i][j]);
2296                                                         text.glPrint(30+j*10-offset*10,30+i*20,string,0,1,1024,768);
2297                                                 }
2298                                         }
2299                                 }
2300                         }
2301                 }
2302         }
2303
2304         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)||(mainmenu&&gameon)||(!gameon&&gamestarted)||(!gameon&&gamestarted)){
2305                 multiplier=tempmult;
2306         }
2307
2308         if(mainmenu){
2309
2310         // !!! FIXME: hack: clamp framerate in menu so text input works correctly on fast systems.
2311         SDL_Delay(15);
2312
2313                 glDrawBuffer(GL_BACK);
2314                 glReadBuffer(GL_BACK);
2315                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
2316                 ReSizeGLScene(90,.1f);
2317
2318                 int temptexdetail;
2319                 temptexdetail=texdetail;
2320                 if(texdetail>2)texdetail=2;
2321                 if(mainmenu!=oldmainmenu&&oldmainmenu!=0){
2322                         if(mainmenu==1){
2323                                 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
2324                                 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
2325                                 /*if(oldmainmenu==1||oldmainmenu==0){
2326                                 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
2327                                 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
2328                                 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
2329                                 loaddistrib=0;
2330                                 }*/
2331                         }
2332                         if(mainmenu==2){
2333                                 LoadTexture(":Data:Textures:Resume.png",&Mainmenuitems[1],0,0);
2334                                 LoadTexture(":Data:Textures:Endgame.png",&Mainmenuitems[3],0,0);
2335                                 /*if(oldmainmenu==2||oldmainmenu==0){
2336                                 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
2337                                 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
2338                                 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
2339                                 loaddistrib=0;
2340                                 }*/
2341                         }
2342                 }
2343                 if(lastcheck>.5||oldmainmenu!=mainmenu){
2344                         if(mainmenu==5){
2345                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
2346                                 //campaignnumlevels=0;
2347                                 //accountactive->getCampaignChoicesMade()=0;
2348                                 ipstream.ignore(256,':');
2349                                 ipstream >> campaignnumlevels;
2350                                 for(i=0;i<campaignnumlevels;i++){
2351                                         ipstream.ignore(256,':');
2352                                         ipstream.ignore(256,':');
2353                                         ipstream.ignore(256,' ');
2354                                         ipstream >> campaignmapname[i];
2355                                         ipstream.ignore(256,':');
2356                                         ipstream >> campaigndescription[i];
2357                                         for(j=0;j<256;j++){
2358                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
2359                                         }
2360                                         ipstream.ignore(256,':');
2361                                         ipstream >> campaignchoosenext[i];
2362                                         ipstream.ignore(256,':');
2363                                         ipstream >> campaignnumnext[i];
2364                                         if(campaignnumnext[i])
2365                                                 for(j=0;j<campaignnumnext[i];j++){
2366                                                         ipstream.ignore(256,':');
2367                                                         ipstream >> campaignnextlevel[i][j];
2368                                                         campaignnextlevel[i][j]-=1;
2369                                                 }
2370                                                 ipstream.ignore(256,':');
2371                                                 ipstream >> campaignlocationx[i];
2372                                                 //campaignlocationx[i]-=30;
2373                                                 ipstream.ignore(256,':');
2374                                                 ipstream >> campaignlocationy[i];
2375                                                 //campaignlocationy[i]+=30;
2376                                 }
2377                                 ipstream.close();
2378
2379                                 for(i=0;i<campaignnumlevels;i++){
2380                                         levelvisible[i]=0;
2381                                         levelhighlight[i]=0;
2382                                 }
2383
2384                                 levelorder[0]=0;
2385                                 levelvisible[0]=1;
2386                                 if(accountactive->getCampaignChoicesMade())
2387                                         for(i=0;i<accountactive->getCampaignChoicesMade();i++){
2388                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
2389                                                 levelvisible[levelorder[i+1]]=1;
2390                                         }
2391                                         int whichlevelstart;
2392                                         whichlevelstart=accountactive->getCampaignChoicesMade()-1;
2393                                         if(whichlevelstart<0){
2394                                                 accountactive->setCampaignScore(0);
2395                                                 accountactive->resetFasttime();
2396                                                 campaignchoicenum=1;
2397                                                 campaignchoicewhich[0]=0;
2398                                         }
2399                                         else
2400                                         {
2401                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
2402                                                 if(campaignchoicenum==0){
2403                                                         //if(accountactive->getCampaignFasttime()==0||accountcampaigntime[accountactive]<accountactive->getCampaignFasttime())accountactive->getCampaignFasttime()=accountcampaigntime[accountactive];          
2404                                                 }
2405                                                 if(campaignchoicenum)
2406                                                         for(i=0;i<campaignchoicenum;i++){
2407                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
2408                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
2409                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
2410                                                         }
2411                                         }
2412                                         /*levelorder[0]=0;
2413                                         levelorder[1]=1;
2414                                         levelorder[2]=2;
2415                                         levelorder[3]=3;*/
2416                         }
2417                 }
2418                 if(mainmenu==5){
2419                         lastcheck=0;
2420                 }
2421
2422                 texdetail=temptexdetail;
2423
2424                 /*if(mainmenu!=0)*/oldmainmenu=mainmenu;
2425
2426                 if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==119||mainmenu==13||mainmenu==17||mainmenu==18){
2427                         glClear(GL_DEPTH_BUFFER_BIT);
2428                         glEnable(GL_ALPHA_TEST);
2429                         glAlphaFunc(GL_GREATER, 0.001f);
2430                         glEnable(GL_TEXTURE_2D);
2431                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
2432                         glDisable(GL_CULL_FACE);
2433                         glDisable(GL_LIGHTING);
2434                         glDepthMask(0);
2435                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2436                         glPushMatrix();                                                                         // Store The Projection Matrix
2437                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
2438                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
2439                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2440                                         glPushMatrix();                                                                         // Store The Modelview Matrix
2441                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
2442                                         glTranslatef(screenwidth/2,screenheight/2,0);
2443                                         glPushMatrix();
2444                                                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
2445                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2446                                                 glDisable(GL_BLEND);
2447                                                 glColor4f(0,0,0,1.0);
2448                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2449                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2450                                                 glDisable(GL_TEXTURE_2D);
2451                                                 glPushMatrix();
2452                                                         //glScalef(.25,.25,.25);
2453                                                         glBegin(GL_QUADS);
2454                                                         glTexCoord2f(0,0);
2455                                                         glVertex3f(-1,          -1,      0.0f);
2456                                                         glTexCoord2f(1,0);
2457                                                         glVertex3f(1,   -1,      0.0f);
2458                                                         glTexCoord2f(1,1);
2459                                                         glVertex3f(1,   1, 0.0f);
2460                                                         glTexCoord2f(0,1);
2461                                                         glVertex3f(-1,  1, 0.0f);
2462                                                         glEnd();
2463                                                 glPopMatrix();
2464                                                 glEnable(GL_BLEND);
2465                                                 glColor4f(0.4,0.4,0.4,1.0);
2466                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
2467                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
2468                                                 glEnable(GL_TEXTURE_2D);
2469                                                 glBindTexture( GL_TEXTURE_2D, Mainmenuitems[4]);
2470                                                 glPushMatrix();
2471                                                         //glScalef(.25,.25,.25);
2472                                                         glBegin(GL_QUADS);
2473                                                         glTexCoord2f(0,0);
2474                                                         glVertex3f(-1,          -1,      0.0f);
2475                                                         glTexCoord2f(1,0);
2476                                                         glVertex3f(1,   -1,      0.0f);
2477                                                         glTexCoord2f(1,1);
2478                                                         glVertex3f(1,   1, 0.0f);
2479                                                         glTexCoord2f(0,1);
2480                                                         glVertex3f(-1,  1, 0.0f);
2481                                                         glEnd();
2482                                                 glPopMatrix();
2483                                         glPopMatrix();
2484                                 glPopMatrix();
2485                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
2486                         glPopMatrix();
2487                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
2488
2489                         if(mainmenu==3){                        
2490                                 nummenuitems=14;
2491                                 if((float)newscreenwidth>(float)newscreenheight*1.61||(float)newscreenwidth<(float)newscreenheight*1.59)sprintf (menustring[0], "Resolution: %d*%d",(int)newscreenwidth,(int)newscreenheight);
2492                                 else sprintf (menustring[0], "Resolution: %d*%d (widescreen)",(int)newscreenwidth,(int)newscreenheight);
2493                                 startx[0]=10+20;
2494                                 starty[0]=440;
2495                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2496                                 endy[0]=starty[0]+20;
2497                                 movex[0]=0;
2498                                 movey[0]=0;
2499
2500                                 if(newdetail==2)sprintf (menustring[1], "Detail: High");
2501                                 else if(newdetail==1)sprintf (menustring[1], "Detail: Medium");
2502                                 else sprintf (menustring[1], "Detail: Low");
2503                                 startx[1]=10+60;
2504                                 starty[1]=405;
2505                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2506                                 endy[1]=starty[1]+20;
2507                                 movex[1]=0;
2508                                 movey[1]=0;
2509
2510                                 if(bloodtoggle==2)sprintf (menustring[2], "Blood: On, high detail (slower)");
2511                                 if(bloodtoggle==1)sprintf (menustring[2], "Blood: On, low detail");
2512                                 if(bloodtoggle==0)sprintf (menustring[2], "Blood: Off");
2513                                 startx[2]=10+70;
2514                                 starty[2]=370;
2515                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2516                                 endy[2]=starty[2]+20;
2517                                 movex[2]=0;
2518                                 movey[2]=0;
2519
2520                                 if(difficulty==2)sprintf (menustring[3], "Difficulty: Insane");
2521                                 if(difficulty==1)sprintf (menustring[3], "Difficulty: Difficult");
2522                                 if(difficulty==0)sprintf (menustring[3], "Difficulty: Easier");
2523                                 startx[3]=10+20-1000;
2524                                 starty[3]=335-1000;
2525                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2526                                 endy[3]=starty[3]+20;
2527                                 movex[3]=0;
2528                                 movey[3]=0;
2529
2530                                 if(ismotionblur==1)sprintf (menustring[4], "Blur Effects: Enabled (less compatible)");
2531                                 if(ismotionblur==0)sprintf (menustring[4], "Blur Effects: Disabled (more compatible)");
2532                                 startx[4]=10;
2533                                 starty[4]=335;
2534                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2535                                 endy[4]=starty[4]+20;
2536                                 movex[4]=0;
2537                                 movey[4]=0;
2538
2539                                 if(decals==1)sprintf (menustring[5], "Decals: Enabled (slower)");
2540                                 if(decals==0)sprintf (menustring[5], "Decals: Disabled");
2541                                 startx[5]=10+60;
2542                                 starty[5]=300;
2543                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2544                                 endy[5]=starty[5]+20;
2545                                 movex[5]=0;
2546                                 movey[5]=0;
2547
2548                                 if(musictoggle==1)sprintf (menustring[6], "Music: Enabled");
2549                                 if(musictoggle==0)sprintf (menustring[6], "Music: Disabled");
2550                                 startx[6]=10+70;
2551                                 starty[6]=265;
2552                                 endx[6]=startx[6]+strlen(menustring[6])*10;
2553                                 endy[6]=starty[6]+20;
2554                                 movex[6]=0;
2555                                 movey[6]=0;
2556
2557                                 if(invertmouse==1)sprintf (menustring[9], "Invert mouse: Yes");
2558                                 if(invertmouse==0)sprintf (menustring[9], "Invert mouse: No");
2559                                 startx[9]=10;
2560                                 starty[9]=230;
2561                                 endx[9]=startx[9]+strlen(menustring[9])*10;
2562                                 endy[9]=starty[9]+20;
2563                                 movex[9]=0;
2564                                 movey[9]=0;
2565
2566                                 sprintf (menustring[10], "Mouse Speed: %d", (int)(usermousesensitivity*5));
2567                                 startx[10]=20;
2568                                 starty[10]=195;
2569                                 endx[10]=startx[10]+strlen(menustring[10])*10;
2570                                 endy[10]=starty[10]+20;
2571                                 movex[10]=0;
2572                                 movey[10]=0;
2573                                 
2574                                 sprintf (menustring[11], "Volume: %d%%", (int)(volume*100));
2575                                 startx[11]=10+60;
2576                                 starty[11]=160;
2577                                 endx[11]=startx[11]+strlen(menustring[11])*10;
2578                                 endy[11]=starty[11]+20;
2579                                 movex[11]=0;
2580                                 movey[11]=0;
2581                                 
2582                                 sprintf (menustring[13], "Damage Bar: %s",(showdamagebar?"on":"off"));
2583                                 startx[13]=30;
2584                                 starty[13]=125;
2585                                 endx[13]=startx[13]+strlen(menustring[13])*10;
2586                                 endy[13]=starty[13]+20;
2587                                 movex[13]=0;
2588                                 movey[13]=0;
2589                                 
2590                                 sprintf (menustring[7], "-Configure Controls-");
2591                                 startx[7]=10+15;
2592                                 starty[7]=90;
2593                                 endx[7]=startx[7]+strlen(menustring[7])*10;
2594                                 endy[7]=starty[7]+20;
2595                                 movex[7]=0;
2596                                 movey[7]=0;
2597
2598                                 sprintf (menustring[12], "-Configure Stereo -");
2599                                 startx[12]=10+15;
2600                                 starty[12]=55;
2601                                 endx[12]=startx[12]+strlen(menustring[7])*10;
2602                                 endy[12]=starty[12]+20;
2603                                 movex[12]=0;
2604                                 movey[12]=0;
2605                                 
2606                                 if(newdetail==detail&&newscreenheight==(int)screenheight&&newscreenwidth==(int)screenwidth)sprintf (menustring[8], "Back");
2607                                 else sprintf (menustring[8], "Back (some changes take effect next time Lugaru is opened)");
2608                                 startx[8]=10;
2609                                 endx[8]=startx[8]+strlen(menustring[8])*10;
2610                                 starty[8]=10;
2611                                 endy[8]=starty[8]+20;
2612                                 movex[8]=0;
2613                                 movey[8]=0;
2614                         }
2615
2616                         if(mainmenu==4){                        
2617                                 nummenuitems=10;
2618                                 if(keyselect!=0)sprintf (menustring[0], "Forwards: %s",Input::keyToChar(forwardkey));
2619                                 else sprintf (menustring[0], "Forwards: _");
2620                                 startx[0]=10;
2621                                 starty[0]=400;
2622                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2623                                 endy[0]=starty[0]+20;
2624                                 movex[0]=0;
2625                                 movey[0]=0;
2626
2627                                 if(keyselect!=1)sprintf (menustring[1], "Back: %s",Input::keyToChar(backkey));
2628                                 else sprintf (menustring[1], "Back: _");
2629                                 startx[1]=10+40;
2630                                 starty[1]=360;
2631                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2632                                 endy[1]=starty[1]+20;
2633                                 movex[1]=0;
2634                                 movey[1]=0;
2635
2636                                 if(keyselect!=2)sprintf (menustring[2], "Left: %s",Input::keyToChar(leftkey));
2637                                 else sprintf (menustring[2], "Left: _");
2638                                 startx[2]=10+40;
2639                                 starty[2]=320;
2640                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2641                                 endy[2]=starty[2]+20;
2642                                 movex[2]=0;
2643                                 movey[2]=0;
2644
2645                                 if(keyselect!=3)sprintf (menustring[3], "Right: %s",Input::keyToChar(rightkey));
2646                                 else sprintf (menustring[3], "Right: _");
2647                                 startx[3]=10+30;
2648                                 starty[3]=280;
2649                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2650                                 endy[3]=starty[3]+20;
2651                                 movex[3]=0;
2652                                 movey[3]=0;
2653
2654                                 if(keyselect!=4)sprintf (menustring[4], "Crouch: %s",Input::keyToChar(crouchkey));
2655                                 else sprintf (menustring[4], "Crouch: _");
2656                                 startx[4]=10+20;
2657                                 starty[4]=240;
2658                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2659                                 endy[4]=starty[4]+20;
2660                                 movex[4]=0;
2661                                 movey[4]=0;
2662
2663                                 if(keyselect!=5)sprintf (menustring[5], "Jump: %s",Input::keyToChar(jumpkey));
2664                                 else sprintf (menustring[5], "Jump: _");
2665                                 startx[5]=10+40;
2666                                 starty[5]=200;
2667                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2668                                 endy[5]=starty[5]+20;
2669                                 movex[5]=0;
2670                                 movey[5]=0;
2671
2672                                 if(keyselect!=6)sprintf (menustring[6], "Draw: %s",Input::keyToChar(drawkey));
2673                                 else sprintf (menustring[6], "Draw: _");
2674                                 startx[6]=10+40;
2675                                 starty[6]=160;
2676                                 endx[6]=startx[6]+strlen(menustring[6])*10;
2677                                 endy[6]=starty[6]+20;
2678                                 movex[6]=0;
2679                                 movey[6]=0;
2680
2681                                 if(keyselect!=7)sprintf (menustring[7], "Throw: %s",Input::keyToChar(throwkey));
2682                                 else sprintf (menustring[7], "Throw: _");
2683                                 startx[7]=10+30;
2684                                 starty[7]=120;
2685                                 endx[7]=startx[7]+strlen(menustring[7])*10;
2686                                 endy[7]=starty[7]+20;
2687                                 movex[7]=0;
2688                                 movey[7]=0;
2689
2690                                 if(keyselect!=8)sprintf (menustring[8], "Attack: %s",Input::keyToChar(attackkey));
2691                                 else sprintf (menustring[8], "Attack: _");
2692                                 startx[8]=10+20;
2693                                 starty[8]=80;
2694                                 endx[8]=startx[8]+strlen(menustring[8])*10;
2695                                 endy[8]=starty[8]+20;
2696                                 movex[8]=0;
2697                                 movey[8]=0;
2698
2699
2700
2701                                 sprintf (menustring[9], "Back");
2702                                 startx[9]=10;
2703                                 endx[9]=startx[9]+strlen(menustring[9])*10;
2704                                 starty[9]=10;
2705                                 endy[9]=starty[9]+20;
2706                                 movex[9]=0;
2707                                 movey[9]=0;
2708                         }
2709                         if(mainmenu==5){                        
2710                                 nummenuitems=7+accountactive->getCampaignChoicesMade()+campaignchoicenum;
2711
2712                                 sprintf (menustring[0], "%s",accountactive->getName());
2713                                 startx[0]=5;
2714                                 starty[0]=400;
2715                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2716                                 endy[0]=starty[0]+20;
2717                                 movex[0]=0;
2718                                 movey[0]=0;
2719
2720                                 sprintf (menustring[1], "Tutorial");
2721                                 startx[1]=5;
2722                                 starty[1]=300;
2723                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2724                                 endy[1]=starty[1]+20;
2725                                 movex[1]=0;
2726                                 movey[1]=0;
2727
2728                                 sprintf (menustring[2], "Challenge");
2729                                 startx[2]=5;
2730                                 starty[2]=240;
2731                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2732                                 endy[2]=starty[2]+20;
2733                                 movex[2]=0;
2734                                 movey[2]=0;
2735
2736                                 sprintf (menustring[3], "Delete User");
2737                                 startx[3]=400;
2738                                 starty[3]=10;
2739                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2740                                 endy[3]=starty[3]+20;
2741                                 movex[3]=0;
2742                                 movey[3]=0;
2743
2744                                 sprintf (menustring[4], "Main Menu");
2745                                 startx[4]=5;
2746                                 starty[4]=10;
2747                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2748                                 endy[4]=starty[4]+20;
2749                                 movex[4]=0;
2750                                 movey[4]=0;
2751
2752                                 sprintf (menustring[5], "Change User");
2753                                 startx[5]=5;
2754                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2755                                 starty[5]=180;
2756                                 endy[5]=starty[5]+20;
2757                                 movex[5]=0;
2758                                 movey[5]=0;
2759
2760                                 //World
2761
2762                                 sprintf (menustring[6], "World");
2763                                 startx[6]=30+120;
2764                                 starty[6]=30+480-400-50;
2765                                 endx[6]=startx[6]+400;
2766                                 endy[6]=30+480-50;
2767                                 movex[6]=0;
2768                                 movey[6]=0;
2769
2770                                 if(accountactive->getCampaignChoicesMade())
2771                                         for(i=0;i<accountactive->getCampaignChoicesMade();i++){
2772                                                 sprintf (menustring[7+i], "%s", campaigndescription[levelorder[i]]);
2773                                                 startx[7+i]=30+120+campaignlocationx[levelorder[i]]*400/512;
2774                                                 starty[7+i]=30+30+(512-campaignlocationy[levelorder[i]])*400/512;
2775                                                 endx[7+i]=startx[7+i]+10;
2776                                                 endy[7+i]=starty[7+i]+10;
2777                                                 movex[7+i]=0;
2778                                                 movey[7+i]=0;
2779                                         }
2780
2781                                         if(campaignchoicenum>0)
2782                                                 for(i=accountactive->getCampaignChoicesMade();i<accountactive->getCampaignChoicesMade()+campaignchoicenum;i++){
2783                                                         sprintf (menustring[7+i], "%s", campaigndescription[levelorder[i]]);
2784                                                         startx[7+i]=30+120+campaignlocationx[campaignchoicewhich[i-(accountactive->getCampaignChoicesMade())]]*400/512;
2785                                                         starty[7+i]=30+30+(512-campaignlocationy[campaignchoicewhich[i-(accountactive->getCampaignChoicesMade())]])*400/512;
2786                                                         endx[7+i]=startx[7+i]+10;
2787                                                         endy[7+i]=starty[7+i]+10;
2788                                                         movex[7+i]=0;
2789                                                         movey[7+i]=0;
2790                                                 }
2791
2792                                                 /*sprintf (menustring[7], "Dot");
2793                                                 startx[7]=120+260*400/512;
2794                                                 starty[7]=30+(512-184)*400/512;
2795                                                 endx[7]=startx[7]+10;
2796                                                 endy[7]=starty[7]+10;
2797                                                 movex[7]=0;
2798                                                 movey[7]=0;
2799
2800                                                 sprintf (menustring[8], "Dot");
2801                                                 startx[8]=120+129*400/512;
2802                                                 starty[8]=30+(512-284)*400/512;
2803                                                 endx[8]=startx[8]+10;
2804                                                 endy[8]=starty[8]+10;
2805                                                 movex[8]=0;
2806                                                 movey[8]=0;
2807
2808                                                 sprintf (menustring[9], "Dot");
2809                                                 startx[9]=120+358*400/512;
2810                                                 starty[9]=30+(512-235)*400/512;
2811                                                 endx[9]=startx[9]+10;
2812                                                 endy[9]=starty[9]+10;
2813                                                 movex[9]=0;
2814                                                 movey[9]=0;
2815
2816                                                 sprintf (menustring[10], "Dot");
2817                                                 startx[10]=120+359*400/512;
2818                                                 starty[10]=30+(512-308)*400/512;
2819                                                 endx[10]=startx[10]+10;
2820                                                 endy[10]=starty[10]+10;
2821                                                 movex[10]=0;
2822                                                 movey[10]=0;
2823
2824                                                 sprintf (menustring[11], "Dot");
2825                                                 startx[11]=120+288*400/512;
2826                                                 starty[11]=30+(512-277)*400/512;
2827                                                 endx[11]=startx[11]+10;
2828                                                 endy[11]=starty[11]+10;
2829                                                 movex[11]=0;
2830                                                 movey[11]=0;*/
2831                         }
2832
2833                         if(mainmenu==6){                        
2834                                 nummenuitems=3;
2835
2836                                 sprintf (menustring[0], "Are you sure you want to delete this user?");
2837                                 startx[0]=10;
2838                                 starty[0]=400;
2839                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2840                                 endy[0]=starty[0]+20;
2841                                 movex[0]=0;
2842                                 movey[0]=0;
2843
2844                                 sprintf (menustring[1], "Yes");
2845                                 startx[1]=10;
2846                                 starty[1]=360;
2847                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2848                                 endy[1]=starty[1]+20;
2849                                 movex[1]=0;
2850                                 movey[1]=0;
2851
2852                                 sprintf (menustring[2], "No");
2853                                 startx[2]=10;
2854                                 starty[2]=320;
2855                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2856                                 endy[2]=starty[2]+20;
2857                                 movex[2]=0;
2858                                 movey[2]=0;
2859
2860                                 sprintf (menustring[3], "Extra 4");
2861                                 startx[3]=10;
2862                                 starty[3]=280;
2863                                 endx[3]=startx[3]+strlen(menustring[3])*10;
2864                                 endy[3]=starty[3]+20;
2865                                 movex[3]=0;
2866                                 movey[3]=0;
2867
2868                                 sprintf (menustring[4], "Extra 5");
2869                                 startx[4]=10;
2870                                 starty[4]=240;
2871                                 endx[4]=startx[4]+strlen(menustring[4])*10;
2872                                 endy[4]=starty[4]+20;
2873                                 movex[4]=0;
2874                                 movey[4]=0;
2875
2876                                 sprintf (menustring[5], "Back");
2877                                 startx[5]=10;
2878                                 endx[5]=startx[5]+strlen(menustring[5])*10;
2879                                 starty[5]=10;
2880                                 endy[5]=starty[5]+20;
2881                                 movex[5]=0;
2882                                 movey[5]=0;
2883                         }
2884
2885                         if(mainmenu==7){        
2886                                 nummenuitems=Account::getNbAccounts()+2;
2887
2888                                 int num;
2889
2890                                 if(Account::getNbAccounts()<8)
2891                                         sprintf (menustring[0], "New User");
2892                                 else
2893                                         sprintf (menustring[0], "No More Users");
2894                                 startx[0]=10;
2895                                 starty[0]=400;
2896                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2897                                 endy[0]=starty[0]+20;
2898                                 movex[0]=0;
2899                                 movey[0]=0;
2900
2901                                 if(entername)
2902                                         startx[0]+=10;
2903
2904
2905                                 num=1;
2906                                 for(i=0;i<Account::getNbAccounts();i++){
2907                                         sprintf (menustring[num], "%s",Account::get(i)->getName());
2908                                         startx[num]=10;
2909                                         starty[num]=360-20-20*num;
2910                                         endx[num]=startx[num]+strlen(menustring[num])*10;
2911                                         endy[num]=starty[num]+20;
2912                                         movex[num]=0;
2913                                         movey[num]=0;
2914
2915                                         num++;
2916                                 }
2917
2918                                 sprintf (menustring[num], "Back");
2919                                 startx[num]=10;
2920                                 endx[num]=startx[num]+strlen(menustring[num])*10;
2921                                 starty[num]=10;
2922                                 endy[num]=starty[num]+20;
2923                                 movex[num]=0;
2924                                 movey[num]=0;
2925                         }
2926                         if(mainmenu==8){                        
2927                                 nummenuitems=3;
2928
2929                                 sprintf (menustring[0], "Easier");
2930                                 startx[0]=10;
2931                                 starty[0]=400;
2932                                 endx[0]=startx[0]+strlen(menustring[0])*10;
2933                                 endy[0]=starty[0]+20;
2934                                 movex[0]=0;
2935                                 movey[0]=0;
2936
2937                                 sprintf (menustring[1], "Difficult");
2938                                 startx[1]=10;
2939                                 starty[1]=360;
2940                                 endx[1]=startx[1]+strlen(menustring[1])*10;
2941                                 endy[1]=starty[1]+20;
2942                                 movex[1]=0;
2943                                 movey[1]=0;
2944
2945                                 sprintf (menustring[2], "Insane");
2946                                 startx[2]=10;
2947                                 starty[2]=320;
2948                                 endx[2]=startx[2]+strlen(menustring[2])*10;
2949                                 endy[2]=starty[2]+20;
2950                                 movex[2]=0;
2951                                 movey[2]=0;
2952                         }
2953                         if(mainmenu==9){                        
2954                                 int tempncl;
2955                                 //tempncl=numchallengelevels;
2956                                 //numchallengelevels=9;
2957                                 nummenuitems=2+numchallengelevels;
2958                                 char temp[255];
2959
2960                                 for(j=0;j<numchallengelevels;j++){
2961                                         for(i=0;i<255;i++)menustring[j][i]='\0';
2962                                         sprintf (temp, "Level %d",j+1);
2963                                         strcpy(menustring[j],temp);
2964                                         for(i=0;i<17;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
2965                                         menustring[j][17]='\0';
2966                                         sprintf (temp, "%d",(int)accountactive->getHighScore(j));
2967                                         strcat(menustring[j],temp);
2968                                         for(i=18;i<32;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
2969                                         menustring[j][32]='\0';
2970                                         sprintf (temp, "%d:",(int)(((int)accountactive->getFastTime(j)-(int)(accountactive->getFastTime(j))%60)/60));
2971                                         strcat(menustring[j],temp);
2972                                         if((int)(accountactive->getFastTime(j))%60<10)strcat(menustring[j],"0");
2973                                         sprintf (temp, "%d",(int)(accountactive->getFastTime(j))%60);
2974                                         strcat(menustring[j],temp);
2975
2976                                         startx[j]=10;
2977                                         starty[j]=400-j*25;
2978                                         endx[j]=startx[j]+strlen(menustring[j])*10;
2979                                         endy[j]=starty[j]+20;
2980                                         movex[j]=0;
2981                                         movey[j]=0;
2982                                 }
2983
2984                                 sprintf (menustring[numchallengelevels], "Back");
2985                                 startx[numchallengelevels]=10;
2986                                 endx[numchallengelevels]=startx[numchallengelevels]+strlen(menustring[numchallengelevels])*10;
2987                                 starty[numchallengelevels]=10;
2988                                 endy[numchallengelevels]=starty[numchallengelevels]+20;
2989                                 movex[numchallengelevels]=0;
2990                                 movey[numchallengelevels]=0;
2991
2992                                 sprintf (menustring[numchallengelevels+1], "             High Score      Best Time");
2993                                 startx[numchallengelevels+1]=10;
2994                                 starty[numchallengelevels+1]=440;
2995                                 endx[numchallengelevels+1]=startx[numchallengelevels+1]+strlen(menustring[numchallengelevels+1])*10;
2996                                 endy[numchallengelevels+1]=starty[numchallengelevels+1]+20;
2997                                 movex[numchallengelevels+1]=0;
2998                                 movey[numchallengelevels+1]=0;
2999
3000                                 //numchallengelevels=tempncl;
3001
3002                         }
3003                         if(mainmenu==11){                       
3004                                 nummenuitems=2+numchallengelevels;
3005                                 char temp[255];
3006
3007                                 for(j=0;j<numchallengelevels;j++){
3008                                         for(i=0;i<255;i++)menustring[j][i]='\0';
3009                                         sprintf (temp, "Level %d",j+1);
3010                                         strcpy(menustring[j],temp);
3011                                         for(i=0;i<17;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
3012                                         menustring[j][17]='\0';
3013                                         sprintf (temp, "%d",(int)accountactive->getHighScore(j));
3014                                         strcat(menustring[j],temp);
3015                                         for(i=18;i<32;i++)if(menustring[j][i]=='\0')menustring[j][i]=' ';
3016                                         menustring[j][32]='\0';
3017                                         sprintf (temp, "%d:",(int)(((int)accountactive->getFastTime(j)-(int)(accountactive->getFastTime(j))%60)/60));
3018                                         strcat(menustring[j],temp);
3019                                         if((int)(accountactive->getFastTime(j))%60<10)strcat(menustring[j],"0");
3020                                         sprintf (temp, "%d",(int)(accountactive->getFastTime(j))%60);
3021                                         strcat(menustring[j],temp);
3022
3023                                         startx[j]=10;
3024                                         starty[j]=360-j*40;
3025                                         endx[j]=startx[j]+strlen(menustring[j])*10;
3026                                         endy[j]=starty[j]+20;
3027                                         movex[j]=0;
3028                                         movey[j]=0;
3029                                 }
3030
3031                                 sprintf (menustring[numchallengelevels], "Back");
3032                                 startx[numchallengelevels]=10;
3033                                 endx[numchallengelevels]=startx[numchallengelevels]+strlen(menustring[numchallengelevels])*10;
3034                                 starty[numchallengelevels]=10;
3035                                 endy[numchallengelevels]=starty[numchallengelevels]+20;
3036                                 movex[numchallengelevels]=0;
3037                                 movey[numchallengelevels]=0;
3038
3039                                 sprintf (menustring[numchallengelevels+1], "             High Score      Best Time");
3040                                 startx[numchallengelevels+1]=10;
3041                                 starty[numchallengelevels+1]=400;
3042                                 endx[numchallengelevels+1]=startx[numchallengelevels+1]+strlen(menustring[numchallengelevels+1])*10;
3043                                 endy[numchallengelevels+1]=starty[numchallengelevels+1]+20;
3044                                 movex[numchallengelevels+1]=0;
3045                                 movey[numchallengelevels+1]=0;
3046
3047                         }
3048                         if(mainmenu==10){                       
3049                                 nummenuitems=6;
3050                                 char temp[255];
3051
3052                                 sprintf (menustring[0], "Congratulations!");
3053                                 startx[0]=220;
3054                                 starty[0]=330;
3055                                 endx[0]=startx[0]+strlen(menustring[0])*10;
3056                                 endy[0]=starty[0]+20;
3057                                 movex[0]=0;
3058                                 movey[0]=0;
3059
3060                                 sprintf (menustring[1], "You have avenged your family and");
3061                                 startx[1]=140;
3062                                 starty[1]=300;
3063                                 endx[1]=startx[1]+strlen(menustring[1])*10;
3064                                 endy[1]=starty[1]+20;
3065                                 movex[1]=0;
3066                                 movey[1]=0;
3067
3068                                 sprintf (menustring[2], "restored peace to the island of Lugaru.");
3069                                 startx[2]=110;
3070                                 starty[2]=270;
3071                                 endx[2]=startx[2]+strlen(menustring[2])*10;
3072                                 endy[2]=starty[2]+20;
3073                                 movex[2]=0;
3074                                 movey[2]=0;
3075
3076                                 sprintf (menustring[3], "Back");
3077                                 startx[3]=10;
3078                                 endx[3]=startx[3]+strlen(menustring[3])*10;
3079                                 starty[3]=10;
3080                                 endy[3]=starty[3]+20;
3081                                 movex[3]=0;
3082                                 movey[3]=0;
3083
3084                                 for(i=0;i<255;i++)menustring[4][i]='\0';
3085                                 sprintf (temp, "Your score:");
3086                                 strcpy(menustring[4],temp);
3087                                 for(i=0;i<20;i++)if(menustring[4][i]=='\0')menustring[4][i]=' ';
3088                                 menustring[4][20]='\0';
3089                                 sprintf (temp, "%d",(int)accountactive->getCampaignScore());
3090                                 strcat(menustring[4],temp);
3091                                 startx[4]=190;
3092                                 endx[4]=startx[4]+strlen(menustring[4])*10;
3093                                 starty[4]=200;
3094                                 endy[4]=starty[4]+20;
3095                                 movex[4]=0;
3096                                 movey[4]=0;
3097                                 /*
3098                                 for(i=0;i<255;i++)menustring[5][i]='\0';
3099                                 sprintf (temp, "Your time:");
3100                                 strcpy(menustring[5],temp);
3101                                 for(i=0;i<20;i++)if(menustring[5][i]=='\0')menustring[5][i]=' ';
3102                                 menustring[5][20]='\0';
3103                                 sprintf (temp, "%d",(int)accountcampaigntime[accountactive]);
3104                                 strcat(menustring[5],temp);
3105                                 startx[5]=200;
3106                                 endx[5]=startx[5]+strlen(menustring[5])*10;
3107                                 starty[5]=180;
3108                                 endy[5]=starty[5]+20;
3109                                 movex[5]=0;
3110                                 movey[5]=0;
3111                                 */
3112                                 for(i=0;i<255;i++)menustring[5][i]='\0';
3113                                 sprintf (temp, "Highest score:");
3114                                 strcpy(menustring[5],temp);
3115                                 for(i=0;i<20;i++)if(menustring[5][i]=='\0')menustring[5][i]=' ';
3116                                 menustring[5][20]='\0';
3117                                 sprintf (temp, "%d",(int)accountactive->getCampaignHighScore());
3118                                 strcat(menustring[5],temp);
3119                                 startx[5]=190;
3120                                 endx[5]=startx[5]+strlen(menustring[5])*10;
3121                                 starty[5]=180;
3122                                 endy[5]=starty[5]+20;
3123                                 movex[5]=0;
3124                                 movey[5]=0;
3125                                 /*
3126                                 for(i=0;i<255;i++)menustring[7][i]='\0';
3127                                 sprintf (temp, "Lowest time:");
3128                                 strcpy(menustring[7],temp);
3129                                 for(i=0;i<20;i++)if(menustring[7][i]=='\0')menustring[7][i]=' ';
3130                                 menustring[7][20]='\0';
3131                                 sprintf (temp, "%d",(int)accountactive->getCampaignFasttime());
3132                                 strcat(menustring[7],temp);
3133                                 startx[7]=200;
3134                                 endx[7]=startx[7]+strlen(menustring[7])*10;
3135                                 starty[7]=130;
3136                                 endy[7]=starty[7]+20;
3137                                 movex[7]=0;
3138                                 movey[7]=0;*/
3139                         }
3140                         if (mainmenu==18) {
3141                                 nummenuitems=4;
3142                                 sprintf (menustring[0], "Stereo mode: %s", StereoModeName(newstereomode));
3143                                 startx[0]=70;
3144                                 starty[0]=400;
3145                                 endx[0]=startx[0]+strlen(menustring[0])*10;
3146                                 endy[0]=starty[0]+20;
3147                                 movex[0]=0;
3148                                 movey[0]=0;
3149                                 
3150                                 sprintf (menustring[1], "Stereo separation: %.3f", stereoseparation);
3151                                 startx[1]=10;
3152                                 starty[1]=360;
3153                                 endx[1]=startx[1]+strlen(menustring[1])*10;
3154                                 endy[1]=starty[1]+20;
3155                                 movex[1]=0;
3156                                 movey[1]=0;
3157
3158                                 sprintf (menustring[2], "Reverse stereo: %s", stereoreverse ? "Yes" : "No");
3159                                 startx[2]=40;
3160                                 starty[2]=320;
3161                                 endx[2]=startx[2]+strlen(menustring[2])*10;
3162                                 endy[2]=starty[2]+20;
3163                                 movex[2]=0;
3164                                 movey[2]=0;
3165                                 
3166                                 sprintf (menustring[3], "Back");
3167                                 startx[3]=10;
3168                                 endx[3]=startx[3]+strlen(menustring[3])*10;
3169                                 starty[3]=10;
3170                                 endy[3]=starty[3]+20;
3171                                 movex[3]=0;
3172                                 movey[3]=0;                             
3173                         }
3174                 }
3175
3176                 if(mainmenu==13){       
3177                         nummenuitems=2;
3178                         char temp[255];
3179
3180                         sprintf (menustring[0], "Please enter your name:");
3181                         startx[0]=50;
3182                         starty[0]=250;
3183                         endx[0]=startx[0]+strlen(menustring[0])*10;
3184                         endy[0]=starty[0]+20;
3185                         movex[0]=0;
3186                         movey[0]=0;
3187
3188                         sprintf (menustring[1], "Please enter your name:");
3189                         startx[1]=290;
3190                         starty[1]=250;
3191                         endx[1]=startx[1]+strlen(menustring[1])*10;
3192                         endy[1]=starty[1]+20;
3193                         movex[1]=0;
3194                         movey[1]=0;
3195                 }
3196                 if(mainmenu==1||mainmenu==2){
3197                         nummenuitems=7;
3198                         startx[0]=150;
3199                         starty[0]=480-128;
3200                         endx[0]=150+256;
3201                         endy[0]=480;
3202                         movex[0]=0;
3203                         movey[0]=0;
3204
3205                         startx[1]=18;
3206                         starty[1]=480-152-32;
3207                         endx[1]=18+128;
3208                         endy[1]=480-152;
3209                         movex[1]=0;
3210                         movey[1]=0;
3211
3212                         startx[2]=18;
3213                         starty[2]=480-228-32;
3214                         endx[2]=2+128;
3215                         endy[2]=480-228;
3216                         movex[2]=0;
3217                         movey[2]=0;
3218
3219                         if(mainmenu==1){
3220                                 startx[3]=18;
3221                                 starty[3]=480-306-32;
3222                                 endx[3]=22+64;
3223                                 endy[3]=480-306;
3224                                 movex[3]=0;
3225                                 movey[3]=0;
3226                         }
3227
3228                         if(mainmenu==2){
3229                                 startx[3]=18;
3230                                 starty[3]=480-306-32;
3231                                 endx[3]=22+128;
3232                                 endy[3]=480-306;
3233                                 movex[3]=0;
3234                                 movey[3]=0;
3235                         }
3236
3237                         /*startx[4]=150;
3238                         starty[4]=480-256;
3239                         endx[4]=150+256;
3240                         endy[4]=480;
3241                         */
3242                         if(anim==0){
3243                                 startx[4]=380;
3244                                 starty[4]=480-140-256;
3245                                 endx[4]=380+256;
3246                                 endy[4]=480-140;
3247                                 movex[4]=80;
3248                                 movey[4]=0;
3249
3250                                 startx[5]=145;
3251                                 starty[5]=480-138-256;
3252                                 endx[5]=145+256;
3253                                 endy[5]=480-138;
3254                                 movex[5]=40;
3255                                 movey[5]=0;
3256
3257                                 startx[6]=254;
3258                                 starty[6]=480-144-256;
3259                                 endx[6]=254+256;
3260                                 endy[6]=480-144;
3261                                 movex[6]=20;
3262                                 movey[6]=0;
3263                         }
3264                         if(anim==1){
3265                                 startx[4]=180;
3266                                 starty[4]=480-140-256;
3267                                 endx[4]=180+256;
3268                                 endy[4]=480-140;
3269                                 movex[4]=80;
3270                                 movey[4]=0;
3271
3272                                 startx[5]=500;
3273                                 starty[5]=480-138-256;
3274                                 endx[5]=500+256;
3275                                 endy[5]=480-138;
3276                                 movex[5]=40;
3277                                 movey[5]=0;
3278
3279                                 startx[6]=340;
3280                                 starty[6]=480-144-256;
3281                                 endx[6]=340+256;
3282                                 endy[6]=480-144;
3283                                 movex[6]=20;
3284                                 movey[6]=0;
3285                         }
3286                         if(anim==2){
3287                                 startx[4]=460;
3288                                 starty[4]=480-140-256;
3289                                 endx[4]=460+256;
3290                                 endy[4]=480-140;
3291                                 movex[4]=50;
3292                                 movey[4]=0;
3293
3294                                 startx[5]=295;
3295                                 starty[5]=480-150-256;
3296                                 endx[5]=295+256;
3297                                 endy[5]=480-138;
3298                                 movex[5]=-10;
3299                                 movey[5]=0;
3300
3301                                 startx[6]=204;
3302                                 starty[6]=480-144-256;
3303                                 endx[6]=204+256;
3304                                 endy[6]=480-144;
3305                                 movex[6]=-30;
3306                                 movey[6]=0;
3307                         }
3308                         if(anim==3){
3309                                 startx[4]=150;
3310                                 starty[4]=480-140-256;
3311                                 endx[4]=200+256;
3312                                 endy[4]=480-140;
3313                                 movex[4]=80;
3314                                 movey[4]=0;
3315
3316                                 startx[5]=350;
3317                                 starty[5]=480-150-256;
3318                                 endx[5]=350+256;
3319                                 endy[5]=480-138;
3320                                 movex[5]=5;
3321                                 movey[5]=0;
3322
3323                                 startx[6]=500;
3324                                 starty[6]=480-144-256;
3325                                 endx[6]=500+256;
3326                                 endy[6]=480-144;
3327                                 movex[6]=-10;
3328                                 movey[6]=0;
3329                         }
3330                         if(anim==4){
3331                                 startx[4]=190;
3332                                 starty[4]=480-100-256;
3333                                 endx[4]=190+256;
3334                                 endy[4]=480-100;
3335                                 movex[4]=-30;
3336                                 movey[4]=0;
3337
3338                                 startx[5]=185;
3339                                 starty[5]=480-120-256;
3340                                 endx[5]=185+256;
3341                                 endy[5]=480-120;
3342                                 movex[5]=-5;
3343                                 movey[5]=0;
3344
3345                                 startx[6]=400;
3346                                 starty[6]=480-144-256;
3347                                 endx[6]=400+256;
3348                                 endy[6]=480-144;
3349                                 movex[6]=20;
3350                                 movey[6]=0;
3351                         }
3352                 }
3353
3354                 selected=-1;
3355
3356                 if(mainmenu==1||mainmenu==2)
3357                         for(i=1;i<4;i++){
3358                                 if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
3359                                         selected=i;
3360                                 }
3361                         }
3362
3363                         if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==11||mainmenu==13||mainmenu==17||mainmenu==18)
3364                                 for(i=0;i<nummenuitems;i++){
3365                                         if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]){
3366                                                 if(mainmenu!=5)selected=i;
3367                                                 if(mainmenu==5&&(i!=0&&i!=6))selected=i;
3368                                                 if(mainmenu==9&&(i!=numchallengelevels+1))selected=i;
3369                                                 if(mainmenu==11&&(i!=numchallengelevels+1))selected=i;
3370                                         }
3371                                 }
3372
3373                                 if(nummenuitems>0)
3374                                         for(i=0;i<nummenuitems;i++){
3375                                                 if(selected==i)selectedlong[i]+=multiplier*5;
3376                                                 if(selectedlong[i]>1)selectedlong[i]=1;
3377                                                 if(selected!=i)selectedlong[i]-=multiplier*5;
3378                                                 if(selectedlong[i]<0)selectedlong[i]=0; 
3379                                                 //if(i>=4)selectedlong[i]=.3;           
3380                                                 if(i>=4&&(mainmenu==1||mainmenu==2))selectedlong[i]=0;  
3381                                         }
3382
3383                                         if(nummenuitems>0)
3384                                                 for(i=0;i<nummenuitems;i++){
3385                                                         offsetx[i]=(startx[i]+endx[i])/2-(mousecoordh/screenwidth*640);
3386                                                         offsety[i]=(starty[i]+endy[i])/2-(480-(mousecoordv/screenheight*480));
3387                                                         offsetx[i]*=.06f;
3388                                                         offsety[i]*=.06f;
3389                                                         offsetx[i]=0;
3390                                                         offsety[i]=0;
3391                                                         if(i>=4&&(mainmenu==1||mainmenu==2)){
3392                                                                 offsetx[i]=(startx[i]+endx[i]+movex[i]*transition)/2-(640+190)/2;
3393                                                                 offsety[i]=(starty[i]+endy[i]+movey[i]*transition)/2-(336+150)/2;
3394                                                                 offsetx[i]*=.06f;
3395                                                                 offsety[i]*=.06f;
3396                                                         }
3397                                                 }
3398
3399                                                 if(mainmenu==1||mainmenu==2){
3400                                                         glClear(GL_DEPTH_BUFFER_BIT);
3401                                                         glEnable(GL_ALPHA_TEST);
3402                                                         glAlphaFunc(GL_GREATER, 0.001f);
3403                                                         glEnable(GL_TEXTURE_2D);
3404                                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3405                                                         glDisable(GL_CULL_FACE);
3406                                                         glDisable(GL_LIGHTING);
3407                                                         glDepthMask(0);
3408                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3409                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3410                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3411                                                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3412                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3413                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3414                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3415                                                                         glTranslatef(screenwidth/2,screenheight/2,0);
3416                                                                         glPushMatrix();
3417                                                                                 glScalef((float)screenwidth/2,(float)screenheight/2,1);
3418                                                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3419                                                                                 glDisable(GL_BLEND);
3420                                                                                 glColor4f(0,0,0,1.0);
3421                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3422                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3423                                                                                 glDisable(GL_TEXTURE_2D);
3424                                                                                 glPushMatrix();
3425                                                                                         //glScalef(.25,.25,.25);
3426                                                                                         glBegin(GL_QUADS);
3427                                                                                         glTexCoord2f(0,0);
3428                                                                                         glVertex3f(-1,          -1,      0.0f);
3429                                                                                         glTexCoord2f(1,0);
3430                                                                                         glVertex3f(1,   -1,      0.0f);
3431                                                                                         glTexCoord2f(1,1);
3432                                                                                         glVertex3f(1,   1, 0.0f);
3433                                                                                         glTexCoord2f(0,1);
3434                                                                                         glVertex3f(-1,  1, 0.0f);
3435                                                                                         glEnd();
3436                                                                                 glPopMatrix();
3437                                                                                 glEnable(GL_BLEND);
3438                                                                                 glColor4f(0.4,0.4,0.4,1.0);
3439                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3440                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3441                                                                                 glEnable(GL_TEXTURE_2D);
3442                                                                                 glBindTexture( GL_TEXTURE_2D, Mainmenuitems[4]);
3443                                                                                 glPushMatrix();
3444                                                                                         //glScalef(.25,.25,.25);
3445                                                                                         glBegin(GL_QUADS);
3446                                                                                         glTexCoord2f(0,0);
3447                                                                                         glVertex3f(-1,          -1,      0.0f);
3448                                                                                         glTexCoord2f(1,0);
3449                                                                                         glVertex3f(1,   -1,      0.0f);
3450                                                                                         glTexCoord2f(1,1);
3451                                                                                         glVertex3f(1,   1, 0.0f);
3452                                                                                         glTexCoord2f(0,1);
3453                                                                                         glVertex3f(-1,  1, 0.0f);
3454                                                                                         glEnd();
3455                                                                                 glPopMatrix();
3456                                                                         glPopMatrix();
3457                                                                 glPopMatrix();
3458                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3459                                                         glPopMatrix();
3460
3461                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3462                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3463                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3464                                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3465                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3466                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3467                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3468                                                                         glPushMatrix();
3469                                                                                 glDisable(GL_TEXTURE_2D);
3470                                                                                 glColor4f(1,0,0,1);
3471                                                                                 /*glPushMatrix();
3472                                                                                 glBegin(GL_QUADS);
3473                                                                                 glTexCoord2f(0,0);
3474                                                                                 if(anim!=1)glVertex3f(190,      150,     0.0f);
3475                                                                                 if(anim==1)glVertex3f(190+movex[4]*transition,  150,     0.0f);
3476                                                                                 glTexCoord2f(1,0);
3477                                                                                 glVertex3f(640, 150,     0.0f);
3478                                                                                 glTexCoord2f(1,1);
3479                                                                                 glVertex3f(640, 336, 0.0f);
3480                                                                                 glTexCoord2f(0,1);
3481                                                                                 if(anim!=1)glVertex3f(190, 336, 0.0f);
3482                                                                                 if(anim==1)glVertex3f(190+movex[4]*transition, 336,      0.0f);
3483                                                                                 glEnd();
3484                                                                                 glPopMatrix();*/
3485                                                                         glPopMatrix();
3486                                                                 glPopMatrix();
3487                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3488                                                         glPopMatrix();
3489                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3490
3491                                                 }
3492
3493                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3494                                                 glPushMatrix();                                                                         // Store The Projection Matrix
3495                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3496                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3497                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3498                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3499                                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
3500                                                 glEnable(GL_TEXTURE_2D);
3501                                                 if(nummenuitems>0)
3502                                                 {
3503                                                         for(j=0;j<nummenuitems;j++)
3504                                                         {
3505                                                                 if(j<=3||(mainmenu!=1&&mainmenu!=2))
3506                                                                 {
3507                                                                         //glDisable(GL_BLEND);
3508                                                                         glEnable(GL_ALPHA_TEST);
3509                                                                         glEnable(GL_BLEND);
3510                                                                         //glDisable(GL_ALPHA_TEST);
3511                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3512                                                                         if(mainmenu==1||mainmenu==2)
3513                                                                         {
3514                                                                                 glColor4f(1,1,1,1);
3515                                                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3516                                                                                 glBindTexture( GL_TEXTURE_2D, Mainmenuitems[j]);
3517                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
3518                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
3519                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3520                                                                                 glPushMatrix();
3521                                                                                         glBegin(GL_QUADS);
3522                                                                                         glTexCoord2f(0,0);
3523                                                                                         glVertex3f(startx[j]+movex[j]*transition,       starty[j]+movey[j]*transition,   0.0f);
3524                                                                                         glTexCoord2f(1,0);
3525                                                                                         glVertex3f(endx[j]+movex[j]*transition,         starty[j]+movey[j]*transition,   0.0f);
3526                                                                                         glTexCoord2f(1,1);
3527                                                                                         glVertex3f(endx[j]+movex[j]*transition,         endy[j]+movey[j]*transition, 0.0f);
3528                                                                                         glTexCoord2f(0,1);
3529                                                                                         glVertex3f(startx[j]+movex[j]*transition,       endy[j]+movey[j]*transition, 0.0f);
3530                                                                                         glEnd();
3531                                                                                 glPopMatrix();
3532                                                                                 glEnable(GL_BLEND);
3533                                                                                 //glDisable(GL_ALPHA_TEST);
3534                                                                                 if(j<4)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3535                                                                                 for(i=0;i<10;i++)
3536                                                                                 {
3537                                                                                         if(1-((float)i)/10-(1-selectedlong[j])>0)
3538                                                                                         {
3539                                                                                                 glColor4f(1,1,1,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3540                                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3541                                                                                                 glPushMatrix();
3542                                                                                                         glBegin(GL_QUADS);
3543                                                                                                         glTexCoord2f(0,0);
3544                                                                                                         glVertex3f(startx[j]-((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition,        starty[j]-((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition,    0.0f);
3545                                                                                                         glTexCoord2f(1,0);
3546                                                                                                         glVertex3f(endx[j]+((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition,  starty[j]-((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition,    0.0f);
3547                                                                                                         glTexCoord2f(1,1);
3548                                                                                                         glVertex3f(endx[j]+((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition,  endy[j]+((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition, 0.0f);
3549                                                                                                         glTexCoord2f(0,1);
3550                                                                                                         glVertex3f(startx[j]-((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition, endy[j]+((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition, 0.0f);
3551                                                                                                         glEnd();
3552                                                                                                 glPopMatrix();
3553                                                                                         }
3554                                                                                 }
3555                                                                         }
3556                                                                         if(mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==8||mainmenu==9||mainmenu==10||mainmenu==11||mainmenu==13||mainmenu==17||mainmenu==18)
3557                                                                         {
3558                                                                                 if(mainmenu!=5||j<6)
3559                                                                                 {
3560                                                                                         glColor4f(1,0,0,1);
3561                                                                                         if(mainmenu==9&&j>accountactive->getProgress()&&j<numchallengelevels)glColor4f(0.5,0,0,1);
3562                                                                                         if(mainmenu==11&&j>accountactive->getProgress()&&j<numchallengelevels)glColor4f(0.5,0,0,1);
3563                                                                                         //if(1-((float)i)/10-(1-selectedlong[j])>0){
3564                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3565                                                                                         glPushMatrix();
3566                                                                                                 if(mainmenu!=7||j!=0||!entername)
3567                                                                                                         text.glPrint(startx[j],starty[j],menustring[j],0,1,640,480);
3568                                                                                                 else
3569                                                                                                 {
3570                                                                                                         if(displayblink){
3571                                                                                                                 sprintf (string, "_");
3572                                                                                                                 text.glPrint(startx[j]+(float)(displayselected)*10,starty[j],string,0,1,640,480);
3573                                                                                                         }
3574                                                                                                         for(l=0;l<displaychars[0];l++){
3575                                                                                                                 sprintf (string, "%c",displaytext[0][l]);
3576                                                                                                                 text.glPrint(startx[j]+l*10,starty[j],string,0,1,640,480);
3577                                                                                                         }
3578                                                                                                 }
3579                                                                                         glPopMatrix();
3580                                                                                         glEnable(GL_BLEND);
3581                                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3582                                                                                         for(i=0;i<15;i++)
3583                                                                                         {
3584                                                                                                 if(1-((float)i)/15-(1-selectedlong[j])>0)
3585                                                                                                 {
3586                                                                                                         glColor4f(1,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3587                                                                                                         if(mainmenu==9&&j>accountactive->getProgress()&&j<numchallengelevels)glColor4f(0.5,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3588                                                                                                         if(mainmenu==11&&j>accountactive->getProgress()&&j<numchallengelevels)glColor4f(0.5,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3589                                                                                                         if(mainmenu==3)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4-((/*1*/+((float)i)/70)*strlen(menustring[j]))*3,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3590                                                                                                         if(mainmenu==4)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3591                                                                                                         if(mainmenu==5)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3592                                                                                                         if(mainmenu==6)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3593                                                                                                         if(mainmenu==7&&(j!=0||!entername)) text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4,starty[j]+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3594                                                                                                         if(mainmenu==8)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3595                                                                                                         if(mainmenu==9)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3596                                                                                                         if(mainmenu==11)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3597                                                                                                         if(mainmenu==10)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3598                                                                                                         if(mainmenu==17)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3599                                                                                                         if(mainmenu==13&&j!=1)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3600                                                                                                         if(mainmenu==18)text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4/*-((((float)i)/70)*strlen(menustring[j]))*3*/,starty[j]/*-i*1/2*/+offsety[j]*((float)i)/4,menustring[j],0,1+((float)i)/70,640,480);
3601                                                                                                         /*else{
3602                                                                                                         if(displayblink){
3603                                                                                                         sprintf (string, "_");
3604                                                                                                         text.glPrint(startx[j]-((float)i)+offsetx[j]*((float)i)/4+(float)(displayselected)*10*(1+((float)i)/70),starty[j]+offsety[j]*((float)i)/4,string,0,1+((float)i)/70,640,480);
3605                                                                                                         }
3606                                                                                                         k=0;
3607                                                                                                         for(l=0;l<displaychars[k];l++){
3608                                                                                                         if(l<displaychars[k]){
3609                                                                                                         sprintf (string, "%c",displaytext[k][l]);
3610                                                                                                         text.glPrint(startx[j]-((float)k)+offsetx[j]*((float)k)/4+l*10*(1+((float)i)/70),starty[j]+offsety[j]*((float)i)/4,string,0,1+((float)i)/70,640,480);
3611                                                                                                         }
3612                                                                                                         }
3613                                                                                                         }*/
3614                                                                                                 }
3615                                                                                         }
3616                                                                                 }
3617                                                                                 else
3618                                                                                 {
3619                                                                                         glClear(GL_DEPTH_BUFFER_BIT);
3620                                                                                         glEnable(GL_ALPHA_TEST);
3621                                                                                         glAlphaFunc(GL_GREATER, 0.001f);
3622                                                                                         glEnable(GL_TEXTURE_2D);
3623                                                                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3624                                                                                         glDisable(GL_CULL_FACE);
3625                                                                                         glDisable(GL_LIGHTING);
3626                                                                                         if(j==6)glColor4f(1,1,1,1);
3627                                                                                         else glColor4f(1,0,0,1);
3628
3629                                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3630                                                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3631                                                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3632                                                                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3633                                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3634                                                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3635                                                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3636                                                                                                         glPushMatrix();
3637
3638                                                                                                                 //Draw world, draw map
3639                                                                                                                 glTranslatef(2,-5,0);
3640
3641                                                                                                                 if(j>6&&j<nummenuitems-1)
3642                                                                                                                 {
3643                                                                                                                         XYZ linestart,lineend,offset;
3644                                                                                                                         XYZ fac;
3645                                                                                                                         float startsize;
3646                                                                                                                         float endsize;
3647                                                                                                                         linestart=0;
3648                                                                                                                         lineend=0;
3649                                                                                                                         offset=0;
3650                                                                                                                         //float linestartx,lineendx,linestarty,lineendy,offsetx,offsety;
3651                                                                                                                         linestart.x=(startx[j]+endx[j])/2;
3652                                                                                                                         linestart.y=(starty[j]+endy[j])/2;
3653                                                                                                                         if(j>=6+accountactive->getCampaignChoicesMade()){
3654                                                                                                                                 linestart.x=(startx[6+accountactive->getCampaignChoicesMade()]+endx[6+accountactive->getCampaignChoicesMade()])/2;
3655                                                                                                                                 linestart.y=(starty[6+accountactive->getCampaignChoicesMade()]+endy[6+accountactive->getCampaignChoicesMade()])/2;
3656                                                                                                                         }
3657                                                                                                                         lineend.x=(startx[j+1]+endx[j+1])/2;
3658                                                                                                                         lineend.y=(starty[j+1]+endy[j+1])/2;
3659                                                                                                                         offset=lineend-linestart;
3660                                                                                                                         fac=offset;
3661                                                                                                                         Normalise(&fac);
3662                                                                                                                         offset=DoRotation(offset,0,0,90);
3663                                                                                                                         Normalise(&offset);
3664                                                                                                                         glDisable(GL_TEXTURE_2D);                                                       
3665
3666                                                                                                                         if(j<6+accountactive->getCampaignChoicesMade()){
3667                                                                                                                                 glColor4f(0.5,0,0,1);
3668                                                                                                                                 startsize=.5;
3669                                                                                                                                 endsize=.5;
3670                                                                                                                         }
3671                                                                                                                         if(j>=6+accountactive->getCampaignChoicesMade()){
3672                                                                                                                                 glColor4f(1,0,0,1);
3673                                                                                                                                 endsize=1;
3674                                                                                                                                 startsize=.5;
3675                                                                                                                         }
3676
3677                                                                                                                         linestart+=fac*4*startsize;
3678                                                                                                                         lineend-=fac*4*endsize;
3679
3680                                                                                                                         if(!(j>7+accountactive->getCampaignChoicesMade()+campaignchoicenum)){
3681                                                                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3682                                                                                                                                 glPushMatrix();
3683                                                                                                                                         glBegin(GL_QUADS);
3684                                                                                                                                         glTexCoord2f(0,0);
3685                                                                                                                                         glVertex3f(linestart.x-offset.x*startsize,      linestart.y-offset.y*startsize,          0.0f);
3686                                                                                                                                         glTexCoord2f(1,0);
3687                                                                                                                                         glVertex3f(linestart.x+offset.x*startsize,      linestart.y+offset.y*startsize,          0.0f);
3688                                                                                                                                         glTexCoord2f(1,1);
3689                                                                                                                                         glVertex3f(lineend.x+offset.x*endsize,          lineend.y+offset.y*endsize, 0.0f);
3690                                                                                                                                         glTexCoord2f(0,1);
3691                                                                                                                                         glVertex3f(lineend.x-offset.x*endsize,          lineend.y-offset.y*endsize, 0.0f);
3692                                                                                                                                         glEnd();
3693                                                                                                                                 glPopMatrix();
3694                                                                                                                         }
3695                                                                                                                         glEnable(GL_TEXTURE_2D);
3696                                                                                                                 }
3697
3698
3699                                                                                                                 if(j==6)glBindTexture( GL_TEXTURE_2D, Mainmenuitems[7]);
3700                                                                                                                 else glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
3701                                                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
3702                                                                                                                 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
3703                                                                                                                 if(j-7<accountactive->getCampaignChoicesMade())glColor4f(0.5,0,0,1);
3704                                                                                                                 if(j-7>=accountactive->getCampaignChoicesMade())glColor4f(1,0,0,1);
3705                                                                                                                 if(j==6)glColor4f(1,1,1,1);
3706                                                                                                                 XYZ midpoint;
3707                                                                                                                 float itemsize;
3708                                                                                                                 itemsize=abs(startx[j]-endx[j])/2;
3709                                                                                                                 midpoint=0;
3710                                                                                                                 midpoint.x=(startx[j]+endx[j])/2;
3711                                                                                                                 midpoint.y=(starty[j]+endy[j])/2;
3712                                                                                                                 if(j>6&&(j-7<accountactive->getCampaignChoicesMade()))itemsize*=.5;
3713                                                                                                                 if(!(j-7>accountactive->getCampaignChoicesMade()+campaignchoicenum))
3714                                                                                                                 {
3715                                                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3716                                                                                                                         glPushMatrix();
3717                                                                                                                                 glBegin(GL_QUADS);
3718                                                                                                                                 glTexCoord2f(0,0);
3719                                                                                                                                 glVertex3f(midpoint.x-itemsize+movex[j]*transition,     midpoint.y-itemsize+movey[j]*transition,         0.0f);
3720                                                                                                                                 glTexCoord2f(1,0);
3721                                                                                                                                 glVertex3f(midpoint.x+itemsize+movex[j]*transition,             midpoint.y-itemsize+movey[j]*transition,         0.0f);
3722                                                                                                                                 glTexCoord2f(1,1);
3723                                                                                                                                 glVertex3f(midpoint.x+itemsize+movex[j]*transition,             midpoint.y+itemsize+movey[j]*transition, 0.0f);
3724                                                                                                                                 glTexCoord2f(0,1);
3725                                                                                                                                 glVertex3f(midpoint.x-itemsize+movex[j]*transition,     midpoint.y+itemsize+movey[j]*transition, 0.0f);
3726                                                                                                                                 glEnd();
3727                                                                                                                         glPopMatrix();
3728                                                                                                                         glEnable(GL_BLEND);
3729                                                                                                                         //glDisable(GL_ALPHA_TEST);
3730                                                                                                                         if(j<4)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
3731                                                                                                                         for(i=0;i<10;i++)
3732                                                                                                                         {
3733                                                                                                                                 if(1-((float)i)/10-(1-selectedlong[j])>0)
3734                                                                                                                                 {
3735                                                                                                                                         glColor4f(1,0,0,(1-((float)i)/10-(1-selectedlong[j]))*.25);
3736                                                                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3737                                                                                                                                         glPushMatrix();
3738                                                                                                                                                 glBegin(GL_QUADS);
3739                                                                                                                                                 glTexCoord2f(0,0);
3740                                                                                                                                                 glVertex3f(midpoint.x-itemsize-((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition,      midpoint.y-itemsize-((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition,          0.0f);
3741                                                                                                                                                 glTexCoord2f(1,0);
3742                                                                                                                                                 glVertex3f(midpoint.x+itemsize+((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition,      midpoint.y-itemsize-((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition,          0.0f);
3743                                                                                                                                                 glTexCoord2f(1,1);
3744                                                                                                                                                 glVertex3f(midpoint.x+itemsize+((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition,      midpoint.y+itemsize+((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition, 0.0f);
3745                                                                                                                                                 glTexCoord2f(0,1);
3746                                                                                                                                                 glVertex3f(midpoint.x-itemsize-((float)i)*1/2+offsetx[j]*((float)i)/2+movex[j]*transition, midpoint.y+itemsize+((float)i)*1/2+offsety[j]*((float)i)/2+movey[j]*transition, 0.0f);
3747                                                                                                                                                 glEnd();
3748                                                                                                                                         glPopMatrix();
3749                                                                                                                                 }
3750                                                                                                                         }
3751                                                                                                                 }
3752                                                                                                         glPopMatrix();
3753                                                                                                 glPopMatrix();
3754                                                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3755                                                                                         glPopMatrix();
3756                                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3757
3758                                                                                         if(j-7>=accountactive->getCampaignChoicesMade()){
3759                                                                                                 //glColor4f(0,0,0,1);
3760                                                                                                 //text.glPrintOutline(startx[j]+10-1.5,starty[j]-4-1.5,menustring[j],0,0.6*1.25,640,480);
3761                                                                                                 //glColor4f(1,0,0,1);
3762                                                                                                 //text.glPrint(startx[j]+10,starty[j]-4,menustring[j],0,0.6,640,480);
3763                                                                                                 text.glPrintOutlined(0.9,0,0,startx[j]+10,starty[j]-4,menustring[j],0,0.6,640,480);
3764                                                                                                 glDisable(GL_DEPTH_TEST);
3765                                                                                         }
3766                                                                                 }
3767                                                                         }
3768                                                                 }
3769                                                         }
3770                                                 }
3771                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3772                                                 glPopMatrix();
3773                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3774                                                 glPopMatrix();
3775
3776                                                         if(mainmenu==1||mainmenu==2)
3777                                                                 if(transition<.1||transition>.9){
3778                                                                         glClear(GL_DEPTH_BUFFER_BIT);
3779                                                                         glEnable(GL_ALPHA_TEST);
3780                                                                         glAlphaFunc(GL_GREATER, 0.001f);
3781                                                                         glEnable(GL_TEXTURE_2D);
3782                                                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3783                                                                         glDisable(GL_CULL_FACE);
3784                                                                         glDisable(GL_LIGHTING);
3785                                                                         glDepthMask(0);
3786                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3787                                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3788                                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3789                                                                                 glOrtho(0,640,0,480,-100,100);                                          // Set Up An Ortho Screen
3790                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3791                                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3792                                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3793                                                                                         glPushMatrix();
3794                                                                                                 glDisable(GL_TEXTURE_2D);
3795                                                                                                 if(transition<.1)glColor4f(1,0,0,1-(transition*10));
3796                                                                                                 if(transition>.9)glColor4f(1,0,0,1-((1-transition)*10));
3797                                                                                                 /*glPushMatrix();
3798                                                                                                 glBegin(GL_QUADS);
3799                                                                                                 glTexCoord2f(0,0);
3800                                                                                                 glVertex3f(190, 150,     0.0f);
3801                                                                                                 glTexCoord2f(1,0);
3802                                                                                                 glVertex3f(640, 150,     0.0f);
3803                                                                                                 glTexCoord2f(1,1);
3804                                                                                                 glVertex3f(640, 336, 0.0f);
3805                                                                                                 glTexCoord2f(0,1);
3806                                                                                                 glVertex3f(190, 336, 0.0f);
3807                                                                                                 glEnd();
3808                                                                                                 glPopMatrix();*/
3809                                                                                         glPopMatrix();
3810                                                                                 glPopMatrix();
3811                                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3812                                                                         glPopMatrix();
3813                                                                 }
3814
3815                                                                 glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3816                                                                 glPushMatrix();                                                                         // Store The Projection Matrix
3817                                                                         glLoadIdentity();                                                                       // Reset The Projection Matrix
3818                                                                         glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3819                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3820                                                                         glPushMatrix();                                                                         // Store The Modelview Matrix
3821                                                                                 glLoadIdentity();                                                               // Reset The Modelview Matrix
3822                                                                                 glTranslatef(screenwidth/2,screenheight/2,0);
3823                                                                                 glPushMatrix();
3824                                                                                         glScalef((float)screenwidth/2,(float)screenheight/2,1);
3825                                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3826                                                                                         glEnable(GL_BLEND);
3827                                                                                         glEnable(GL_TEXTURE_2D);
3828                                                                                         glColor4f(1,1,1,1);
3829                                                                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
3830                                                                                         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
3831                                                                                 glPopMatrix();
3832                                                                                 if(!waiting) { // hide the cursor while waiting for a key
3833                                                                                         glPushMatrix();
3834                                                                                                 glTranslatef(mousecoordh-screenwidth/2,mousecoordv*-1+screenheight/2,0);
3835                                                                                                 glScalef((float)screenwidth/64,(float)screenwidth/64,1);
3836                                                                                                 glTranslatef(1,-1,0);
3837                                                                                                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3838                                                                                                 glColor4f(1,1,1,1);
3839                                                                                                 glBindTexture( GL_TEXTURE_2D, cursortexture);
3840                                                                                                 glPushMatrix();
3841                                                                                                         //glScalef(.25,.25,.25);
3842                                                                                                         glBegin(GL_QUADS);
3843                                                                                                         glTexCoord2f(0,0);
3844                                                                                                         glVertex3f(-1,          -1,      0.0f);
3845                                                                                                         glTexCoord2f(1,0);
3846                                                                                                         glVertex3f(1,   -1,      0.0f);
3847                                                                                                         glTexCoord2f(1,1);
3848                                                                                                         glVertex3f(1,   1, 0.0f);
3849                                                                                                         glTexCoord2f(0,1);
3850                                                                                                         glVertex3f(-1,  1, 0.0f);
3851                                                                                                         glEnd();
3852                                                                                                 glPopMatrix();
3853                                                                                         glPopMatrix();
3854                                                                                 }
3855                                                                         glPopMatrix();
3856                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3857                                                                 glPopMatrix();
3858
3859
3860                                                                 if(flashamount>0)
3861                                                                 {
3862                                                                         //printf("Flash amount: %f, delay %i\n", flashamount, flashdelay);
3863                                                                         if(flashamount>1)flashamount=1;
3864                                                                         if(flashdelay<=0)flashamount-=multiplier;
3865                                                                         flashdelay--;
3866                                                                         if(flashamount<0)flashamount=0;
3867                                                                         glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
3868                                                                         glDisable(GL_CULL_FACE);
3869                                                                         glDisable(GL_LIGHTING);
3870                                                                         glDisable(GL_TEXTURE_2D);
3871                                                                         glDepthMask(0);
3872                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3873                                                                         glPushMatrix();                                                                         // Store The Projection Matrix
3874                                                                                 glLoadIdentity();                                                                       // Reset The Projection Matrix
3875                                                                                 glOrtho(0,screenwidth,0,screenheight,-100,100);                                         // Set Up An Ortho Screen
3876                                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3877                                                                                 glPushMatrix();                                                                         // Store The Modelview Matrix
3878                                                                                         glLoadIdentity();                                                               // Reset The Modelview Matrix
3879                                                                                         glScalef(screenwidth,screenheight,1);
3880                                                                                         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
3881                                                                                         glEnable(GL_BLEND);
3882                                                                                         glColor4f(flashr,flashg,flashb,flashamount);
3883                                                                                         glBegin(GL_QUADS);
3884                                                                                         glVertex3f(0,           0,       0.0f);
3885                                                                                         glVertex3f(256, 0,       0.0f);
3886                                                                                         glVertex3f(256, 256, 0.0f);
3887                                                                                         glVertex3f(0,   256, 0.0f);
3888                                                                                         glEnd();
3889                                                                                         glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
3890                                                                                 glPopMatrix();                                                                          // Restore The Old Projection Matrix
3891                                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
3892                                                                         glPopMatrix();                                                                          // Restore The Old Projection Matrix
3893                                                                         glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
3894                                                                         glEnable(GL_CULL_FACE);
3895                                                                         glDisable(GL_BLEND);
3896                                                                         glDepthMask(1);
3897                                                                 }       
3898         }
3899
3900         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)||(!gameon&&gamestarted)){
3901                 tempmult=multiplier;
3902                 multiplier=0;
3903         }
3904
3905         //glFlush();
3906         if ( side == stereoRight || side == stereoCenter ) {
3907                 if(drawmode!=motionblurmode||mainmenu){
3908                         swap_gl_buffers();
3909                 }
3910         }
3911
3912         //myassert(glGetError() == GL_NO_ERROR);
3913         glDrawBuffer(GL_BACK);
3914         glReadBuffer(GL_BACK);
3915         //glFlush();
3916
3917         weapons.DoStuff();
3918
3919         if(drawtoggle==2)drawtoggle=0;
3920
3921         if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)){
3922                 multiplier=tempmult;
3923         }
3924         //Jordan fixed your warning!
3925         return 0;
3926 }
3927