#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include "fmod.h"
#include "glsystem.h"
#include "system.h"
#include "fmod.h"
//#include "fmod_errors.h"    /* optional */
FMUSIC_MODULE *mod = NULL;
#define MAX_PARTICLES 512
#define SIZEOFPARTICLE 1
#define GRAVITY 1
TEXTURE TextureHandler; //the texturemap handler.
GLuint Font;
GLuint TextCube[6];
#include "explosions.h" //mostly for making the source easy reading.

int main(void)
{
	MSG msg;
	int faketimer=-1500,i,j,k,l;
	float sinangle=0;
	int character=0;	
	bool done=FALSE;
	CreateGLWindow("::!pussy style!::",640,480,16,true);
	float angle=0;int dist1=0,dist2=100;
//	char text[20],text2[20];
	EXPLOSION explosions[5];	
	SetupParticles(explosions[0].particles,0,0,0);
	SetupParticles(explosions[1].particles,0,0,0);
	explosions[0].duration=100;
	explosions[1].duration=0;    
    //if (FSOUND_GetVersion() < FMOD_VERSION){printf("Error : You are using the wrong DLL version!  You should be using FMOD %.02f\n", FMOD_VERSION);exit(1);}   
    FSOUND_Init(44100, 64, 0);
    mod = FMUSIC_LoadSong("domni.xm");
    //if (!mod){printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));exit(1);}   
//        printf("order = %d/%d, row = %d/%d channels playing = %d cpu usage = %.02f%%     \r", FMUSIC_GetOrder(mod), FMUSIC_GetNumOrders(mod), FMUSIC_GetRow(mod), FMUSIC_GetPatternLength(mod, FMUSIC_GetOrder(mod)), FSOUND_GetChannelsPlaying(), FSOUND_GetCPUUsage());  
	CUBELETTER letter[6];
			//setup starting letters (PUSSY),
			letter[0].letter=0;letter[0].x=-8;letter[0].y=0;letter[0].z=-20;
			letter[0].rotox=rand()%360;letter[0].rotoy=rand()%360;letter[0].rotoz=rand()%360;
			letter[1].letter=1;letter[1].x=-4;letter[1].y=0;letter[1].z=-20;
			letter[1].rotox=rand()%360;letter[1].rotoy=rand()%360;letter[1].rotoz=rand()%360;
			letter[2].letter=2;letter[2].x=0;letter[2].y=0;letter[2].z=-20;
			letter[2].rotox=rand()%360;letter[2].rotoy=rand()%360;letter[2].rotoz=rand()%360;
			letter[3].letter=2;letter[3].x=4;letter[3].y=0;letter[3].z=-20;
			letter[3].rotox=rand()%360;letter[3].rotoy=rand()%360;letter[3].rotoz=rand()%360;
			letter[4].letter=3;letter[4].x=8;letter[4].y=0;letter[4].z=-20;
			letter[4].rotox=rand()%360;letter[4].rotoy=rand()%360;letter[4].rotoz=rand()%360;

//***Load textures and maps here! only suporting mipmapped textures.  :)
	GLuint start1,start2;
	GLuint HitlerBild;
	GLuint DildoBild;	
	GLuint Texture[3];
	GLuint codeimage;
	GLuint CubE;
	GLuint Cunt,presents;
	GLuint Backrund;
	GLuint sosbidrag;
	GLuint evilsmoke;
	evilsmoke=TextureHandler.LoadTexture("data/evilsmoke.bmp");
	start1=TextureHandler.LoadTexture("data/start1.bmp");
	start2=TextureHandler.LoadTexture("data/start2.bmp");
	sosbidrag=TextureHandler.LoadTexture("data/sos.bmp");
	Backrund=TextureHandler.LoadTexture("data/flum.bmp");
	HitlerBild=TextureHandler.LoadTexture("data/hitler.bmp");
	DildoBild=TextureHandler.LoadTexture("data/dildo.bmp");
	Cunt=TextureHandler.LoadTexture("data/flak.bmp");
	presents=TextureHandler.LoadTexture("data/logo1.bmp");
	codeimage=TextureHandler.LoadTexture("data/code.bmp");
	TextCube[0]=TextureHandler.LoadTexture("data/p.bmp");
	TextCube[1]=TextureHandler.LoadTexture("data/u.bmp");
	TextCube[2]=TextureHandler.LoadTexture("data/s.bmp");
	TextCube[3]=TextureHandler.LoadTexture("data/y.bmp");
	TextCube[4]=TextureHandler.LoadTexture("data/t.bmp");	
	TextCube[5]=TextureHandler.LoadTexture("data/e.bmp");
	Texture[0]=TextureHandler.LoadTexture("data/star.bmp"); //this is how the load texture workds.
	Texture[1]=TextureHandler.LoadTexture("data/new.bmp"); //this is how the load te
	Texture[2]=TextureHandler.LoadTexture("data/sugar.bmp"); //this is how the load te
	Font=TextureHandler.LoadTexture("data/font.bmp"); //this is how the load font
CubE=TextureHandler.LoadTexture("data/temp.bmp");
 FMUSIC_PlaySong(mod);   	
while(!done){
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
		if (msg.message==WM_QUIT){done=TRUE;}
		else{TranslateMessage(&msg);DispatchMessage(&msg);}}
		else{if (active){
			if (keys[VK_ESCAPE]){done=TRUE;} //k3ey ESC to QuIt
		else{				
//***************THIS IS WHERE ALL THE CODE COMES IN!(loop)*******************
faketimer++; // ha really lame,. yeay, but you have to have some sort of sync jah?
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	//SetupParticles(particles1,rand()%10,rand()%10,0);	
	if (faketimer>=-500 && faketimer<250){
	glLoadIdentity();
		glTranslatef(0,0,-3);
	TextureHandler.UseTexture(start1,FALSE,FALSE);
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  0.0f);	// Top Left Of The Texture and Quad
	glEnd();
	}

	if (faketimer>=-250 && faketimer<0){
	glLoadIdentity();
		glTranslatef(0,0,-3);
	TextureHandler.UseTexture(start2,FALSE,FALSE);
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  0.0f);	// Top Left Of The Texture and Quad
	glEnd();
	}
	if (faketimer>=0 && faketimer<1000){
	glLoadIdentity();	

	glTranslatef(0,0,-3);
	TextureHandler.UseTexture(Cunt,FALSE,FALSE);
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  0.0f);	// Top Left Of The Texture and Quad
	glEnd();
	
	glTranslatef(((float) ((rand()%10) -5) /500)  ,((float) ((rand()%10) -5) /500),0);
	TextureHandler.UseTexture(presents,TRUE,FALSE);	
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  0.0f);	// Top Left Of The Texture and Quad
	glEnd();
	}
	if (faketimer>1000 && faketimer <=2000){
	glLoadIdentity();	
	//glTranslatef(0,0,-2);
	glTranslatef(cos(-sinangle),sin(-sinangle*2),-2);
	glRotatef(roto+=1,0,0,1);
	TextureHandler.UseTexture(Backrund,TRUE,FALSE);
	glColor4f(0,1,1,.4);
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  0.0f);	// Top Left Of The Texture and Quad
	glEnd();

	glLoadIdentity();	
	glTranslatef(sin(sinangle+=.01),cos(sinangle/2),-2);
	glRotatef(roto+=1,0,0,-1);
	TextureHandler.UseTexture(Backrund,TRUE,FALSE);
	glColor4f(0,0,1,.4);
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  0.0f);	// Top Left Of The Texture and Quad
	glEnd();

	glLoadIdentity();	
	glTranslatef(cos(sinangle+=.01),cos(-sinangle/2),-2);
	glRotatef(roto+=1,0,0,-1);
	TextureHandler.UseTexture(Backrund,TRUE,FALSE);	
	glColor4f(1,0,0,.4);
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  0.0f);	// Top Left Of The Texture and Quad
	glEnd();

	glLoadIdentity();	
	glTranslatef(0,-.26,-3);
	TextureHandler.UseTextureBlend(HitlerBild,TRUE,FALSE,0);	
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  0.0f);	// Top Left Of The Texture and Quad
	glEnd();

	glLoadIdentity();	
	glTranslatef(-5.8,-4,-12);
	TextureHandler.UseTextureBlend(Texture[2],TRUE,FALSE,0);
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  0.0f);	// Top Left Of The Texture and Quad
	glEnd();

	glLoadIdentity();	
	glTranslatef(0.0,3.0,-10);
	TextureHandler.UseTexture(sosbidrag,TRUE,FALSE);	
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f*3.93, -1.0f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f*3.93, -1.0f,  0.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f*3.93,  1.0f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f*3.93,  1.0f,  0.0f);	// Top Left Of The Texture and Quad
	glEnd();

	}
	if( faketimer >2000 && faketimer <=3000){
	glLoadIdentity();	
	glTranslatef(-.40,.6,-3.1);
	TextureHandler.UseTextureBlend(DildoBild,TRUE,FALSE,0);
	glColor4f(1,1,1,1);
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, -0.2f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, -0.2f,  0.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f,  0.2f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f,  0.2f,  0.0f);	// Top Left Of The Texture and Quad
	glEnd();
	}
	
	if(faketimer==3000){roto=0;	sinangle=0;}
	if (faketimer >3000	&&faketimer<4000){
	
	glLoadIdentity();
	TextureHandler.UseTexture(Texture[0],true,false);
	roto+=2;
	if(roto>=360)roto=0;
	glPushMatrix();
	if(explosions[0].duration>0){ MoveParticles(explosions[0].particles,roto,0,1,0,-16,explosions[0].duration*.005 );explosions[0].duration--;}
	//glLoadIdentity();
	glPopMatrix();
	if(explosions[1].duration>0){ MoveParticles(explosions[1].particles,-roto,1,0,1,-16,explosions[1].duration*.005 );explosions[1].duration--;}

	if(explosions[0].duration<=0){
		SetupParticles(explosions[0].particles,rand()%10,rand()%10,0);
		explosions[0].duration=200;
	}
	if(explosions[1].duration<=0){
		SetupParticles(explosions[1].particles,rand()%10,rand()%10,0);
		explosions[1].duration=200;
	}
	glLoadIdentity();
letter[0].z=cos(sinangle)*2 -20;	
letter[1].z=cos(sinangle-1)*2 -20;
letter[2].z=cos(sinangle-2)*2 -20;
letter[3].z=cos(sinangle-3)*2 -20;
letter[4].z=cos(sinangle-4)*2 -20;

letter[0].y=sin(sinangle+=.04)*2;
letter[1].y=sin(sinangle+1)*2;
letter[2].y=sin(sinangle+2)*2;
letter[3].y=sin(sinangle+3)*2;
letter[4].y=sin(sinangle+4)*2;
//printf("active x degrees: %d",letter[0].rotox);
draw_letter(&letter[0]);
draw_letter(&letter[1]);
draw_letter(&letter[2]);
draw_letter(&letter[3]);
draw_letter(&letter[4]);
	}
	if(faketimer>4000){
	glLoadIdentity();
		glTranslatef(0,0,-3);
	TextureHandler.UseTexture(evilsmoke,FALSE,FALSE);
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  0.0f);	// Top Left Of The Texture and Quad
	glEnd();
}
	if (faketimer==5000)done=1;

SwapBuffers(hDC);
}}}

}
    FMUSIC_FreeSong(mod);
    FSOUND_Close();

KillGLWindow();					
return(0);
}
