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