unit intro;
interface
uses math,types3d,opengl,math3d;

const XRes = 80;
      YRes = 80;
      CirCnt = 16;
type TCir = RECORD
      P_: Array[0..3] of TCoord2D;
      P: TCoord2D;
      Size: GLfloat;
     END;

var Def: Array[0..XRes,0..YRes] of TCoord2D;
    Cir: Array[0..CirCnt-1] of TCir;
    I_,I_Last: GLfloat;

procedure stuffinit(_Width_,_Height_: GLint);
procedure introanim(T: GLuint; Tex,TexPres,TexLogo,TexHalo,  _Width_,_Height_: GLint);

procedure glBindTexture(target: GLenum; texture: GLuint); stdcall; external 'opengl32.dll';
implementation

procedure blurit(ZO,Size: GLfloat);
var C: GLint;
begin

 if ZO<0 then ZO:=0;

  glBegin(GL_QUADS);
 for C:=1 to 15 do begin

 glColor4f(1,1,1,(1-C/15)*ZO);

    glTexCoord2f(0,0); glVertex2f(-C*7*ZO  -Size*2,-Size);
    glTexCoord2f(1,0); glVertex2f(-C*7*ZO  +Size*2,-Size);
    glTexCoord2f(1,1); glVertex2f(-C*7*ZO  +Size*2,+Size);
    glTexCoord2f(0,1); glVertex2f(-C*7*ZO  -Size*2,+Size);

    glTexCoord2f(0,0); glVertex2f(+C*7*ZO  -Size*2,-Size);
    glTexCoord2f(1,0); glVertex2f(+C*7*ZO  +Size*2,-Size);
    glTexCoord2f(1,1); glVertex2f(+C*7*ZO  +Size*2,+Size);
    glTexCoord2f(0,1); glVertex2f(+C*7*ZO  -Size*2,+Size);

 end;
  glEnd();

end;

procedure Deformation(X,X1: GLfloat; Deform: GLbyte);
var C,E: Integer; Dst,Tmp1: GLfloat; V2D: TCoord2D;
begin

CASE Deform OF

5: begin //flower
 For C:=0 to XRes-1 do
  For E:=0 to YRes-1 do begin
   V2D.X:=(C - (XRes shr 1));
   V2D.Y:=(E - (YRes shr 1));
   Dst:=SQRT(  SQR(V2D.X)+SQR(V2D.Y)  );

   Tmp1:=ArcTan2(V2D.Y,V2D.X) - ArcTan2(0,0);


   Def[C,E].X:=V2D.X*Sin(Tmp1*10+X*2*PI)*PI*X1;
   Def[C,E].Y:=V2D.Y*Cos(Tmp1*10+X*2*PI)*PI*X1;
  end;
end;

6: begin //flower
 For C:=0 to XRes-1 do
  For E:=0 to YRes-1 do begin
   V2D.X:=(C - (XRes shr 1));
   V2D.Y:=(E - (YRes shr 1));
   Dst:=SQRT(  SQR(V2D.X)+SQR(V2D.Y)  );

   Tmp1:=ArcTan2(V2D.Y,V2D.X) - ArcTan2(0,0);


   Def[C,E].X:=V2D.X*Sin(Tmp1*10+X*2*PI)*PI*X1;
   Def[C,E].Y:=V2D.Y*Sin(Tmp1*10+X*2*PI)*PI*X1;
  end;
end;


END;

end;


procedure DrawItAsGrid(Size: GLfloat);
const BaseSize = 150;
var C,E: Glint;
begin
 glColor4f(1,1,1,1);
 glBegin(GL_QUADS);
  for C:=0 to XRes-1 do begin
   for E:=0 to YRes-1 do begin
    //glColor3f(Random(100)/100,Random(100)/100,Random(100)/100);
     glTexCoord2f((C+0)/XRes,(E+0)/YRes); glVertex2f(((C+0)/XRes*BaseSize*4-BaseSize*2 + Def[C+0,E+0].X)*Size  ,  ((E+0)/YRes*BaseSize*2-BaseSize + Def[C+0,E+0].Y)*Size  );
     glTexCoord2f((C+1)/XRes,(E+0)/YRes); glVertex2f(((C+1)/XRes*BaseSize*4-BaseSize*2 + Def[C+1,E+0].X)*Size  ,  ((E+0)/YRes*BaseSize*2-BaseSize + Def[C+1,E+0].Y)*Size  );
     glTexCoord2f((C+1)/XRes,(E+1)/YRes); glVertex2f(((C+1)/XRes*BaseSize*4-BaseSize*2 + Def[C+1,E+1].X)*Size  ,  ((E+1)/YRes*BaseSize*2-BaseSize + Def[C+1,E+1].Y)*Size  );
     glTexCoord2f((C+0)/XRes,(E+1)/YRes); glVertex2f(((C+0)/XRes*BaseSize*4-BaseSize*2 + Def[C+0,E+1].X)*Size  ,  ((E+1)/YRes*BaseSize*2-BaseSize  + Def[C+0,E+1].Y)*Size  );
   end;
  end;
 glEnd();
end;




procedure Snare(T,Time: GLuint; _Width_,_Height_: GLint);
begin
  if (T>=Time) and (T<Time+400) then begin
   glPushMatrix();
   glLoadIdentity();
   glDisable(GL_TEXTURE_2D);

   glColor4f(1,1,1,1-(T-Time)/400);
   glBegin(GL_QUADS);
    glVertex2f(0,0);
    glVertex2f(_Width_,0);
    glVertex2f(_Width_,_Height_);
    glVertex2f(0,_Height_);
   glEnd();

   glEnable(GL_TEXTURE_2D);
   glPopMatrix();
  end;
end;

procedure TomTom(T,Time: GLuint; _Width_,_Height_: GLint);
begin
  if (T>=Time) and (T<Time+500) then begin
   glPushMatrix();
   glLoadIdentity();
   //glDisable(GL_TEXTURE_2D);

   glColor4f(1,1,1,1-(T-Time)/500);
   glBegin(GL_QUADS);
    glTexCoord2f(0,0);glVertex2f(0,_Height_ shr 2);
    glTexCoord2f(1,0);glVertex2f(_Width_,_Height_ shr 2);
    glTexCoord2f(1,1);glVertex2f(_Width_,_Height_-_Height_ shr 2);
    glTexCoord2f(0,1);glVertex2f(0,_Height_-_Height_ shr 2);
   glEnd();

   //glEnable(GL_TEXTURE_2D);
   glPopMatrix();
  end;
end;

procedure Kick(T,Time: GLuint; _Width_,_Height_: GLint);
begin
  if (T>=Time) and (T<Time+920) then begin
   glPushMatrix();
   glLoadIdentity();
   glDisable(GL_TEXTURE_2D);

   glBegin(GL_QUADS);

       glColor4f(1,1,1,0);
    glVertex2f(0,0);
       glColor4f(1,1,1,1-(T-Time)/920);
    glVertex2f(_Width_ shr 1,0);
    glVertex2f(_Width_ shr 1,_Height_);
       glColor4f(1,1,1,0);
    glVertex2f(0,_Height_);

       glColor4f(1,1,1,1-(T-Time)/920);
    glVertex2f(_Width_ shr 1,0);
       glColor4f(1,1,1,0);
    glVertex2f(_Width_,0);
    glVertex2f(_Width_,_Height_);
       glColor4f(1,1,1,1-(T-Time)/920);
    glVertex2f(_Width_ shr 1,_Height_);

   glEnd();

   glEnable(GL_TEXTURE_2D);
   glPopMatrix();
  end;
end;

procedure Tone(Ton: GLbyte;_Width_,_Height_: GLint);
begin

glPushMatrix();glLoadIdentity();
glDisable(GL_TEXTURE_2D);

glColor4f(1,1,1,0.32);

glBegin(GL_QUADS);
 case Ton of
  1: begin

   glVertex2f(_Width_ shr 1-20-45,_Height_-70);
   glVertex2f(_Width_ shr 1+20-45,_Height_-70);
   glVertex2f(_Width_ shr 1+20-45,_Height_-30);
   glVertex2f(_Width_ shr 1-20-45,_Height_-30);

  end;
  2: begin

   glVertex2f(_Width_ shr 1-20+45,_Height_-70);
   glVertex2f(_Width_ shr 1+20+45,_Height_-70);
   glVertex2f(_Width_ shr 1+20+45,_Height_-30);
   glVertex2f(_Width_ shr 1-20+45,_Height_-30);

  end;
  3: begin

   glVertex2f(_Width_ shr 1-20,_Height_-70);
   glVertex2f(_Width_ shr 1+20,_Height_-70);
   glVertex2f(_Width_ shr 1+20,_Height_-30);
   glVertex2f(_Width_ shr 1-20,_Height_-30);

  end;

{  1: begin

glColor4f(1,1,1,0.3);
    glVertex2f(0,      0);
    glVertex2f(_Width_,0);
glColor4f(1,1,1,0);
    glVertex2f(_Width_,20);
    glVertex2f(0,      20);

glColor4f(1,1,1,0.3);
    glVertex2f(0,      _Height_-0);
    glVertex2f(_Width_,_Height_-0);
glColor4f(1,1,1,0);
    glVertex2f(_Width_,_Height_-20);
    glVertex2f(0,      _Height_-20);

  end;
  2: begin

glColor4f(1,1,1,0.2);
    glVertex2f(0,      0);
    glVertex2f(_Width_,0);
glColor4f(1,1,1,0);
    glVertex2f(_Width_,40);
    glVertex2f(0,      40);

glColor4f(1,1,1,0.2);
    glVertex2f(0,      _Height_-0);
    glVertex2f(_Width_,_Height_-0);
glColor4f(1,1,1,0);
    glVertex2f(_Width_,_Height_-40);
    glVertex2f(0,      _Height_-40);

  end;
  3: begin

glColor4f(1,1,1,0.1);
    glVertex2f(0,      0);
    glVertex2f(_Width_,0);
glColor4f(1,1,1,0);
    glVertex2f(_Width_,60);
    glVertex2f(0,      60);

glColor4f(1,1,1,0.1);
    glVertex2f(0,      _Height_-0);
    glVertex2f(_Width_,_Height_-0);
glColor4f(1,1,1,0);
    glVertex2f(_Width_,_Height_-60);
    glVertex2f(0,      _Height_-60);

  end;}
 end;
glEnd();

glEnable(GL_TEXTURE_2D);
glPopMatrix();

end;

procedure drawcircles(T: LongWord; _Width_,_Height_: GLint; HaloID: GLuint);
var C: GLint;
begin
  glLoadIdentity();
  glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,HaloID);

  glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA,GL_ONE{_MINUS_SRC_ALPHA});
  glBegin(GL_QUADS);
  glColor4f(0.04,0.1,0.23,0.45);
  for C:=0 to CirCnt-1 do begin
   Cir[C].P.X:=CubicIPol(Cir[C].P_[0].X,Cir[C].P_[1].X,Cir[C].P_[2].X,Cir[C].P_[3].X,I_);
   Cir[C].P.Y:=CubicIPol(Cir[C].P_[0].Y,Cir[C].P_[1].Y,Cir[C].P_[2].Y,Cir[C].P_[3].Y,I_);

   {Cir[C].P.X:=CosIPol( Cir[C].P_[1].X, Cir[C].P_[2].X, (T mod 1000)/1000 );
   Cir[C].P.Y:=CosIPol( Cir[C].P_[1].Y, Cir[C].P_[2].Y, (T mod 1500)/1500 );}

   glTexCoord2f(0,0);glVertex2f( Cir[C].P.X-(280*Cir[C].Size) , Cir[C].P.Y-(280*Cir[C].Size) );
   glTexCoord2f(1,0);glVertex2f( Cir[C].P.X+(280*Cir[C].Size) , Cir[C].P.Y-(280*Cir[C].Size) );
   glTexCoord2f(1,1);glVertex2f( Cir[C].P.X+(280*Cir[C].Size) , Cir[C].P.Y+(280*Cir[C].Size) );
   glTexCoord2f(0,1);glVertex2f( Cir[C].P.X-(280*Cir[C].Size) , Cir[C].P.Y+(280*Cir[C].Size) );
  end;
  glEnd();

  I_:=(T mod 2200)/2200;
   if I_<I_Last then begin
     for C:=0 to CirCnt-1 do begin
      Cir[C].P_[0]:=Cir[C].P_[1];
      Cir[C].P_[1]:=Cir[C].P_[2];
      Cir[C].P_[2]:=Cir[C].P_[3];

      Cir[C].P_[3].X:=_Width_*Random(1000)/1000;
      Cir[C].P_[3].Y:=_Height_*Random(1000)/1000;
     end;
   end;
  I_Last:=I_;
end;

procedure stuffinit(_Width_,_Height_: GLint);
var C: GLint;
begin
  for C:=0 to CirCnt-1 do begin
   Cir[C].P_[0].X:=_Width_*Random(1000)/1000;
   Cir[C].P_[0].Y:=_Height_*Random(1000)/1000;

   Cir[C].P_[1].X:=_Width_*Random(1000)/1000;
   Cir[C].P_[1].Y:=_Height_*Random(1000)/1000;

   Cir[C].P_[2].X:=_Width_*Random(1000)/1000;
   Cir[C].P_[2].Y:=_Height_*Random(1000)/1000;

   Cir[C].P_[3].X:=_Width_*Random(1000)/1000;
   Cir[C].P_[3].Y:=_Height_*Random(1000)/1000;

   Cir[C].Size:=0.5+Random(500)/1000;
  end;
end;

procedure introanim(T: GLuint; Tex,TexPres,TexLogo,TexHalo,  _Width_,_Height_: GLint);
var Size,Siz,Tmp: GLfloat; QT: GLint;
begin
//priprava na najhorsie
  Size:=150; Siz:=Size*(1+T/17000);

  glClearColor(0,0,0,0.5);
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  glTranslatef(_Width_ shr 1,_Height_ shr 1,0);
  glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,Tex);

//deformacie napisu
  if T<3000 then Blurit((1+Cos(T/3000*PI))/2,Siz) else begin
   if T<4000 then Deformation((T mod 2100)/2100,0,5) else
   if T<14000 then Deformation((T mod 2100)/2100,((T-4000) mod 10000)/10000,5) else
   if T<17000 then Deformation((T mod 2100)/2100,1,5) else

   Deformation((T mod 1210)/1210,((T-20000) mod 10000)/10000,6);

   if T<17000 then DrawItAsGrid(1+T/17000) else
   if (T>=20000) and (T<30000) then DrawItAsGrid(1);
  end;


  if (T>=30000) then begin
   glLoadIdentity();
   glBindTexture(GL_TEXTURE_2D,TexLogo);
   glColor4f(1,1,1,1);
   glBegin(GL_QUADS);
    glTexCoord2f(0,0);glVertex2f(_Width_ shr 1-300,_Height_ shr 1-75);
    glTexCoord2f(1,0);glVertex2f(_Width_ shr 1+300,_Height_ shr 1-75);
    glTexCoord2f(1,1);glVertex2f(_Width_ shr 1+300,_Height_ shr 1+75);
    glTexCoord2f(0,1);glVertex2f(_Width_ shr 1-300,_Height_ shr 1+75);
   glEnd();

   DrawCircles(T,_Width_,_Height_,TexHalo);
  end;

  if (T>26000) and (T<34000) then begin
   glLoadIdentity(); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
   glDisable(GL_TEXTURE_2D);
   glColor4f(0,0,0,1-(1+Cos( (T-26000)/8000*2*PI))/2 );
   glBegin(GL_QUADS);
    glVertex2f(0,0);
    glVertex2f(_Width_,0);
    glVertex2f(_Width_,_Height_);
    glVertex2f(0,_Height_);
   glEnd();
   glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D,TexPres);
   glColor4f(1,1,1,1-(1+Cos( (T-26000)/8000*2*PI))/2 );
   glBegin(GL_QUADS);
    glTexCoord2f(0,0);glVertex2f(_Width_ shr 1-200,_Height_ shr 1-50);
    glTexCoord2f(1,0);glVertex2f(_Width_ shr 1+200,_Height_ shr 1-50);
    glTexCoord2f(1,1);glVertex2f(_Width_ shr 1+200,_Height_ shr 1+50);
    glTexCoord2f(0,1);glVertex2f(_Width_ shr 1-200,_Height_ shr 1+50);
   glEnd();
  end;



//fade out flower efektu
  if (T>15000) and (T<17000) then begin
   glPushMatrix();
   glLoadIdentity();
   glDisable(GL_TEXTURE_2D);

   glColor4f(0,0,0,(T-15000)/2000);
   glBegin(GL_QUADS);
    glVertex2f(0,0);
    glVertex2f(_Width_,0);
    glVertex2f(_Width_,_Height_);
    glVertex2f(0,_Height_);
   glEnd();

   glEnable(GL_TEXTURE_2D);
   glPopMatrix();
  end;


//the napis
  if (T<3000) or ((T>15000) and (T<20000)) then begin
  glColor4f(1,1,1,1);
  if (T>15000) and (T<19000) then glColor4f(1,1,1,(T-15000)/4000);
  if (T>15000) then Siz:=Size;
  glBegin(GL_QUADS);
    glTexCoord2f(0,0); glVertex2f(-Siz*2,-Siz);
    glTexCoord2f(1,0); glVertex2f(+Siz*2,-Siz);
    glTexCoord2f(1,1); glVertex2f(+Siz*2,+Siz);
    glTexCoord2f(0,1); glVertex2f(-Siz*2,+Siz);
  glEnd();
  end;

//zvacseny priesvitny duch napisu
  if (T>15000) and (T<20000) then begin
   if T<16000 then Tmp:=(T-15000)/1000 else Tmp:=1;

   glColor4f(1,1,1,(1-(T-15000)/5000)*0.3*Tmp);
   Siz:=Size*(2.1+(T-15000)/3000);
   glBegin(GL_QUADS);
     glTexCoord2f(0,0); glVertex2f(-Siz*2,-Siz);
     glTexCoord2f(1,0); glVertex2f(+Siz*2,-Siz);
     glTexCoord2f(1,1); glVertex2f(+Siz*2,+Siz);
     glTexCoord2f(0,1); glVertex2f(-Siz*2,+Siz);
   glEnd();
  end;


//trojtonie

  {QT:=T mod 750;
  if QT<250 then begin
   Tone(1,_Width_,_Height_);
  end else
  if QT<500 then begin
   Tone(2,_Width_,_Height_);
  end else
  begin
   Tone(3,_Width_,_Height_);
  end;}



//fade in/out
  glLoadIdentity();
  if (T<2000) or (T>40000) then begin
   glBlendFunc(GL_SRC_ALPHA,GL_ONE);
   glDisable(GL_TEXTURE_2D);

   glColor4f(1,1,1,1-T/2000);

   if T>40000 then glColor4f(1,1,1,(T-40000)/3000);

   glBegin(GL_QUADS);
    glVertex2f(0,0);
    glVertex2f(_Width_,0);
    glVertex2f(_Width_,_Height_);
    glVertex2f(0,_Height_);
   glEnd();
   glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  end;

//bubny odrana
(*
  {TomTom(T,9516,_Width_,_Height_);}
  {TomTom(T,9765,_Width_,_Height_);}

  {TomTom(T,10264,_Width_,_Height_);}
  {TomTom(T,10505,_Width_,_Height_);}                                  Kick(T,10505,_Width_,_Height_);

  {TomTom(T,11020,_Width_,_Height_);} Snare(T,11020,_Width_,_Height_);
  {TomTom(T,11270,_Width_,_Height_);}
  {TomTom(T,11520,_Width_,_Height_);}                                  Kick(T,11520,_Width_,_Height_);
  {TomTom(T,11770,_Width_,_Height_);} Snare(T,11770,_Width_,_Height_); Kick(T,11770,_Width_,_Height_);


  Kick(T,14986,_Width_,_Height_);
  Kick(T,17986,_Width_,_Height_);


  {TomTom(T,20014,_Width_,_Height_);}
  {TomTom(T,20271,_Width_,_Height_);}

  {TomTom(T,20770,_Width_,_Height_);}
  {TomTom(T,21011,_Width_,_Height_);}                                   Kick(T,21011,_Width_,_Height_);

  {TomTom(T,21518,_Width_,_Height_);}
  {TomTom(T,21768,_Width_,_Height_);}
  {TomTom(T,22018,_Width_,_Height_);}
  {TomTom(T,22268,_Width_,_Height_);}
*)
end;

end.
