unit credits;

interface
uses math,types3d,opengl,math3d;

const XRes = 100;
      YRes = 100;
var Def: Array[0..XRes,0..YRes] of TCoord2D;

procedure creditsanim(T: GLuint; Tex: GLint; _Width_,_Height_: GLint);

implementation



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

CASE Deform OF

0: begin
 For C:=0 to XRes-1 do
  For E:=0 to YRes-1 do begin
   Def[C,E].X:=0;
   Def[C,E].Y:=0;
  end;
end;

1: begin //zoom in/zoom out
 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)  );

   Def[C,E].X:=-V2D.X*(XRes shr 1-Dst)*(Cos(X*2*PI)*2*X1);
   Def[C,E].Y:=-V2D.Y*(YRes shr 1-Dst)*(Cos(X*2*PI)*2*X1);
  end;
end;

2: 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:=LinIPol(0, (V2D.X*Cos(Tmp1*10+X*2*PI)*PI*X1), Dst/XRes );
   Def[C,E].Y:=LinIPol(0, (V2D.Y*Sin(Tmp1*10+X*2*PI)*PI*X1), Dst/XRes );
  end;
end;


END;

end;

procedure DrawItAsGrid(Size: GLfloat);
const BaseSize = 400;
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*2-BaseSize + 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*2-BaseSize + 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*2-BaseSize + 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*2-BaseSize + 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 creditsanim(T: GLuint; Tex: GLint; _Width_,_Height_: GLint);
var Size,Tmp: GLfloat;
    X,Y: Array[0..2] of GLfloat;
    C: GLuint;
begin

  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);

  if T<6000 then glRotatef( CosIPol(-60,25,T/6000),0,0,1 ) else if T<14000 then glRotatef( CosIPol(25,0,(T-6000)/8000),0,0,1 );

  glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,Tex);

  Size:=300+Sin((T mod 10000)/10000*2*PI)*30;

  glColor4f(1,1,1,1);

  if (T>3000) and (T<14000) then Tmp:=LinIPol(0.4,0.05,(T-3000)/11000) else Tmp:=0.05;
  if (T<=3000) then Deformation(0,0.4,1) else Deformation((T mod 3000)/3000,Tmp,1);
  DrawItAsGrid(1);

  if (T<1000) then begin
  glCOlor4f(0,0,0,1-T/1000);
  glLoadIdentity();
  glDisable(GL_TEXTURE_2D);
  glBegin(GL_QUADS);
   glVertex2f(0,0);
   glVertex2f(_Width_,0);
   glVertex2f(_Width_,_Height_);
   glVertex2f(0,_Height_);
  glEnd();
  end;

  {For C:=0 to 2 do begin
  glColor4f(1,1,1,0.2+C*0.4);
    Case C of
     0: begin
      X[C]:=Sin( (T mod 17000)/17000 * 2 * PI +0.0)*150;
      Y[C]:=Cos( (T mod 17000)/17000 * 2 * PI +0.0)*150;
     end;
     1: begin
      X[C]:=Sin( (T mod 17000)/17000 * 2 * PI +0.2)*150;
      Y[C]:=Cos( (T mod 17000)/17000 * 2 * PI +0.2)*150;
     end;
     2: begin
      X[C]:=Sin( (T mod 17000)/17000 * 2 * PI +0.4)*150;
      Y[C]:=Cos( (T mod 17000)/17000 * 2 * PI +0.4)*150;
     end;
    end;

    glBegin(GL_QUADS);
      glTexCoord2f(0,0);glVertex2f(-Size+X[C],-Size+Y[C]);
      glTexCoord2f(1,0);glVertex2f(+Size+X[C],-Size+Y[C]);
      glTexCoord2f(1,1);glVertex2f(+Size+X[C],+Size+Y[C]);
      glTexCoord2f(0,1);glVertex2f(-Size+X[C],+Size+Y[C]);
    glEnd();
  end;}

end;

end.
