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