#include "project.h"

int tehen,gereblye,vajkopulo,traktor,kasza,rajz1,rajz2,rajz3,fly,and,redneck;
int scroll1,scroll2,scroll3,scroll4;

int celk1,celk2;

void kepek_drawegyet(int num)
{
	glDepthMask(false);
	glEnable(GL_BLEND);
	//glBlendFunc(GL_SRC_ALPHA,GL_ONE);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	glBindTexture(GL_TEXTURE_2D,num);
	glBegin(GL_QUADS);
		glTexCoord2f(0,0); glVertex2f(-1, 1);
		glTexCoord2f(0,1); glVertex2f(-1,-1);
		glTexCoord2f(1,1); glVertex2f( 1,-1);
		glTexCoord2f(1,0); glVertex2f( 1, 1);
	glEnd();

	glDisable(GL_BLEND);
	glDepthMask(true);
}

void kepek_init()
{
	glEnable(GL_TEXTURE_2D);
		tehen=JPG_UploadJPG3("data/tehen.jpg");
		gereblye=JPG_UploadJPG3("data/gereblye.jpg");
		vajkopulo=JPG_UploadJPG3("data/vajkopulo.jpg");
		traktor=JPG_UploadJPG3("data/traktor.jpg");
		kasza=JPG_UploadJPG3("data/kasza.jpg");

		rajz1=JPG_UploadJPG3("data/kep1.jpg"); //800*600
		rajz2=JPG_UploadJPG3("data/kep2.jpg"); //450*600
		rajz3=JPG_UploadJPG3("data/kep3.jpg"); //800*471

		celk1=JPG_UploadJPG4("data/celk1.jpg","data/celk1_a.jpg");
		celk2=JPG_UploadJPG4("data/celk2.jpg","data/celk2_a.jpg");

		fly=JPG_UploadJPG3("data/fly.jpg");
		and=JPG_UploadJPG3("data/and.jpg");
		redneck=JPG_UploadJPG3("data/redneck.jpg");

    scroll1=JPG_UploadJPG3("data/scroll1.jpg");
    scroll2=JPG_UploadJPG3("data/scroll2.jpg");
    scroll3=JPG_UploadJPG3("data/scroll3.jpg");
    scroll4=JPG_UploadJPG3("data/scroll4.jpg");
	glDisable(GL_TEXTURE_2D);



}

void kepek_deinit()
{

}

void kepek_draw(int sync)
{
	glClearColor(1,1,1,1);
	glTranslatef(0,0,-5);

	glEnable(GL_TEXTURE_2D);

	float syncszorzo = (sync%1000)/1000.0f;

	glTranslatef(2*syncszorzo,syncszorzo,3*syncszorzo);
	glRotatef(90*syncszorzo,0.6f,0.8f,-1);
	glColor4f(1,1,1,1-syncszorzo);
	kepek_drawegyet(vajkopulo);	

	glDisable(GL_TEXTURE_2D);
}

//13978
void kepek_fenykepek(int sync)
{
  set3d(wm_fov,wm_width/(float)wm_height,wm_zNear,wm_zFar);
  glTranslatef(0,0,-6);

  glBindTexture(GL_TEXTURE_2D,rajz1);
  glBegin(GL_QUADS);
    glTexCoord2f(0,0); glVertex2f(-4, 3);
    glTexCoord2f(0,1); glVertex2f(-4,-3);
    glTexCoord2f(1,1); glVertex2f( 4,-3);
    glTexCoord2f(1,0); glVertex2f( 4, 3);
  glEnd();
  glDisable(GL_TEXTURE_2D);

  glEnable(GL_TEXTURE_2D);
	if ((sync>=0) && (sync<1000))
  {
    FadeIn(sync,1000,0.1f,0,0);
  }
}

void kepek_title(int sync)
{
	set3d(wm_fov,wm_width/(float)wm_height,wm_zNear,wm_zFar);

  glEnable(GL_TEXTURE_2D);
	glTranslatef(0,0,-8);

    glDepthMask(false);
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE,GL_ONE);
		
      glBindTexture(GL_TEXTURE_2D,fly);
		  glBegin(GL_QUADS);
			  glTexCoord2f(0,0); glVertex2f(-1.5f, 2);
			  glTexCoord2f(0,1); glVertex2f(-1.5f,-2);
			  glTexCoord2f(1,1); glVertex2f( 0.5f,-2);
			  glTexCoord2f(1,0); glVertex2f( 0.5f, 2);
		  glEnd();
		  glBindTexture(GL_TEXTURE_2D,and);
		  glBegin(GL_QUADS);
			  glTexCoord2f(0,0); glVertex2f(   0,0.5f);
			  glTexCoord2f(0,1); glVertex2f(   0,0);
			  glTexCoord2f(1,1); glVertex2f(0.5f,0);
			  glTexCoord2f(1,0); glVertex2f(0.5f,0.5f);
		  glEnd();
      glBindTexture(GL_TEXTURE_2D,redneck);
		  glBegin(GL_QUADS);
			  glTexCoord2f(0,0); glVertex2f(0,0);
			  glTexCoord2f(0,1); glVertex2f(0,-0.5f);
			  glTexCoord2f(1,1); glVertex2f(1,-0.5f);
			  glTexCoord2f(1,0); glVertex2f(1,0);
		  glEnd();

    glDisable(GL_BLEND);
    glDepthMask(true);
    
	//glDisable(GL_TEXTURE_2D);


  if (sync<500) FadeIn(sync,500,1,1,1);
  if ((sync>=1000) && (sync<1500))
  {
    float syncszorzo = (sync%500)/500.0f;

    glDisable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

    glTranslatef(2*syncszorzo,syncszorzo,3*syncszorzo);
	  glRotatef(45*syncszorzo,0.6f,0.8f,-1);
	  glColor4f(1,1,1,0.7f-0.7f*syncszorzo);
	  kepek_drawegyet(vajkopulo);

    glDisable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);
  }
}

void kepek_celkereszt(int sync)
{
	set3d(wm_fov,wm_width/(float)wm_height,wm_zNear,wm_zFar);
	glPushMatrix();

	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA,GL_ONE);

		glLoadIdentity();
		glTranslatef(0,0,-5);
		glPushMatrix();
			glRotatef(180*(sync/8919.0f),0,0,1);
			glBindTexture(GL_TEXTURE_2D,celk1);
			glBegin(GL_QUADS);
				glTexCoord2f(0,0); glVertex2f(-1, 1);
				glTexCoord2f(0,1); glVertex2f(-1,-1);
				glTexCoord2f(1,1); glVertex2f( 1,-1);
				glTexCoord2f(1,0); glVertex2f( 1, 1);
			glEnd();
		glPopMatrix();

		glPushMatrix();
			glRotatef(-360*(sync/8919.0f),0,0,1);
			glBindTexture(GL_TEXTURE_2D,celk2);
			glBegin(GL_QUADS);
				glTexCoord2f(0,0); glVertex2f(-1, 1);
				glTexCoord2f(0,1); glVertex2f(-1,-1);
				glTexCoord2f(1,1); glVertex2f( 1,-1);
				glTexCoord2f(1,0); glVertex2f( 1, 1);
			glEnd();
		glPopMatrix();
	
	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);
	glPopMatrix();
}


void kepek_bacsi(int sync)
{
  if (sync<7105)
  {
    set3d(wm_fov,wm_width/(float)wm_height,wm_zNear,wm_zFar);
    glDisable(GL_LIGHTING);
    glEnable(GL_TEXTURE_2D);

    glTranslatef(0,0,-1-5*(sync/7105.0f));

    glBindTexture(GL_TEXTURE_2D,rajz3);
    glBegin(GL_QUADS);
      glTexCoord2f(0,0); glVertex2f(-4, 3);
      glTexCoord2f(0,0.785f); glVertex2f(-4,-3);
      glTexCoord2f(1,0.785f); glVertex2f( 4,-3);
      glTexCoord2f(1,0); glVertex2f( 4, 3);
    glEnd();

    glDisable(GL_TEXTURE_2D);


    if (sync<5105)
    {
      FadeIn(sync,5105,0,0,0);
    } else if ((sync>=5605) && (sync<6105))
    {
      FadeOut(sync-5605,500,1,1,1);
    } else if (sync>6105) {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }
    /*set2d(0,wm_height,wm_width,0);
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
      glColor4f(0,0,0,1-(sync/7105.0f));

      glBegin(GL_QUADS);
        glVertex2f(0,0);
        glVertex2f(0,wm_height);
        glVertex2f(wm_width,wm_height);
        glVertex2f(wm_width,0);
      glEnd();

      glColor4f(1,1,1,1);  
    glDisable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);*/
  }
}

void kepek_endscroller(int sync)
{
  glEnable(GL_TEXTURE_2D);
  glDisable(GL_LIGHTING);

  set3d(wm_fov,wm_width/(float)wm_height,wm_zNear,wm_zFar);
  glTranslatef(0,0,-3);

  glEnable(GL_BLEND);
  glBlendFunc(GL_ONE,GL_ONE);

  glColor4f(1,1,1,0.5f);
  if (sync<3436)
  {
    glBindTexture(GL_TEXTURE_2D,scroll1);
    glBegin(GL_QUADS);
      glTexCoord2f(0,0); glVertex2f(-1, 1);
      glTexCoord2f(0,1); glVertex2f(-1,-1);
      glTexCoord2f(1,1); glVertex2f( 1,-1);
      glTexCoord2f(1,0); glVertex2f( 1, 1);
    glEnd();
  }
  if ((sync>=3436) && (sync<6873))
  {
    glBindTexture(GL_TEXTURE_2D,scroll2);
    glBegin(GL_QUADS);
      glTexCoord2f(0,0); glVertex2f(-1, 1);
      glTexCoord2f(0,1); glVertex2f(-1,-1);
      glTexCoord2f(1,1); glVertex2f( 1,-1);
      glTexCoord2f(1,0); glVertex2f( 1, 1);
    glEnd();
    //if (sync<6373) FadeIn(sync-6373,500,0,0,0);
  }
  if ((sync>=6873) && (sync<34643))
  {
    glBindTexture(GL_TEXTURE_2D,scroll3);
    glBegin(GL_QUADS);
      glTexCoord2f(0,0); glVertex2f(-1,-2+9*(sync-6873)/27770.0f);
      glTexCoord2f(0,1); glVertex2f(-1,-8+9*(sync-6873)/27770.0f);
      glTexCoord2f(1,1); glVertex2f( 1,-8+9*(sync-6873)/27770.0f);
      glTexCoord2f(1,0); glVertex2f( 1,-2+9*(sync-6873)/27770.0f);
    glEnd();
    //if (sync<7373) FadeIn(sync-6873,500,0,0,0);
  }
  if ((sync>=34643) && (sync<41425))
  {
    glBindTexture(GL_TEXTURE_2D,scroll4);
    glBegin(GL_QUADS);
      glTexCoord2f(0,0); glVertex2f(-1, 1);
      glTexCoord2f(0,1); glVertex2f(-1,-1);
      glTexCoord2f(1,1); glVertex2f( 1,-1);
      glTexCoord2f(1,0); glVertex2f( 1, 1);
    glEnd();
    //if (sync<35143) FadeIn(sync-34643,500,0,0,0);
  }

  glColor4f(1,1,1,1);
  glEnable(GL_BLEND);


  //if (sync<500) FadeIn(sync,500,0,0,0);
  //if ((sync>=5873) && (sync<6373)) FadeIn(sync,500,0,0,0);
}