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