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