///////////////////////////////////////////////////////////////////////
// Copyright (C) Andru 2007                                          //
// mail: dr.andru@gmail.com                                          //
// site: http://andru.2x4.ru                                         //
//                                                                   //
// OMEGA Engine is free software.                                    //
//                                                                   //
// You may redistribute it and/or modify it under the terms of the   //
// GNU General Public License, as published by the Free Software     //
// Foundation; either version 2 of the License, or (at your option)  //
// any later version.                                                //
//                                                                   //
// this module is distributed in the hope that it will be useful,    //
// but WITHOUT ANY WARRANTY; without even the implied warranty of    //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.              //
// See the GNU General Public License for more details.              //
//                                                                   //
// You should have received a copy of the GNU General Public License //
// along with this module.  If not, write to:                        //
// The Free Software Foundation, Inc.,                               //
// 51 Franklin Street, Fifth Floor                                   //
// Boston, MA  02110-1301, USA.                                      //
///////////////////////////////////////////////////////////////////////
unit G2D_FX;

{$I DEFINES.pas}

interface
uses OpenGL;

const
  FX_BLEND    = $000001;
  FX_FLIPX    = $000002;
  FX_FLIPY    = $000004;
  FX_COLORMIX = $000008;
  FX_SCALE    = $000010;
  FX_VCHANGE  = $000020;
  FX_VCA      = $000040;

  FX_BLEND_NORMAL = $000000;
  FX_BLEND_ADD    = $000001;
  FX_BLEND_MULT   = $000002;
  FX_BLEND_BLACK  = $000003;
  FX_BLEND_WHITE  = $000004;
  FX_BLEND_MASK   = $000005;

var
  // FX_ColorMix
  FX_R : Byte = 255;
  FX_G : Byte = 255;
  FX_B : Byte = 255;

  // ScaleX, ScaleY
  FX_SX : Single = 1.0;
  FX_SY : Single = 1.0;

  // FX_VertexesX/Y
  FX_VX1, FX_VY1 : Single;
  FX_VX2, FX_VY2 : Single;
  FX_VX3, FX_VY3 : Single;
  FX_VX4, FX_VY4 : Single;

  // FX_VertexesColor/Alpha
  FX_VR1, FX_VG1, FX_VB1, FX_VA1 : Byte;
  FX_VR2, FX_VG2, FX_VB2, FX_VA2 : Byte;
  FX_VR3, FX_VG3, FX_VB3, FX_VA3 : Byte;
  FX_VR4, FX_VG4, FX_VB4, FX_VA4 : Byte;

procedure FX_SetColorMix( Color : Integer ); stdcall;
procedure FX_SetBlendMode( Mode : Integer ); stdcall;
procedure FX_SetScale( ScaleX, ScaleY : Single ) stdcall;
procedure FX_SetVertexes(
                          X1, Y1 : Single;
                          X2, Y2 : Single;
                          X3, Y3 : Single;
                          X4, Y4 : Single
                        ); stdcall;
procedure FX_SetVCA(
                     C1, C2, C3, C4 : Integer;
                     A1, A2, A3, A4 : Byte
                   ); stdcall;

//----------------------------------------------------------------------------//
                                 IMPLEMENTATION
//----------------------------------------------------------------------------//

procedure FX_SetColorMix;
Begin

FX_R :=   Color and $FF;
FX_G := ( Color and $FF00 ) shr 8;
FX_B :=   Color             shr 16;

End;

procedure FX_SetBlendMode;
Begin
case Mode of
FX_BLEND_NORMAL : glBlendFunc( GL_SRC_ALPHA,           GL_ONE_MINUS_SRC_ALPHA );
FX_BLEND_ADD    : glBlendFunc( GL_SRC_ALPHA,           GL_ONE                 );
FX_BLEND_MULT   : glBlendFunc( GL_ZERO,                GL_SRC_COLOR           );
FX_BLEND_BLACK  : glBlendFunc( GL_SRC_COLOR,           GL_ONE_MINUS_SRC_COLOR );
FX_BLEND_WHITE  : glBlendFunc( GL_ONE_MINUS_SRC_COLOR, GL_SRC_COLOR           );
FX_BLEND_MASK   : glBlendFunc( GL_ZERO,                GL_SRC_COLOR           );
end;
End;

procedure FX_SetScale;
Begin

FX_SX := ScaleX;
FX_SY := ScaleY;

End;

procedure FX_SetVertexes;
Begin

FX_VX1 := X1; FX_VY1 := Y1;
FX_VX2 := X2; FX_VY2 := Y2;
FX_VX3 := X3; FX_VY3 := Y3;
FX_VX4 := X4; FX_VY4 := Y4;

End;

procedure FX_SetVCA;
Begin

FX_VR1 :=   C1 and $FF;
FX_VG1 := ( C1 and $FF00   ) shr 8;
FX_VB1 := ( C1 and $FF0000 ) shr 16;
FX_VA1 := A1;

FX_VR2 :=   C2 and $FF;
FX_VG2 := ( C2 and $FF00   ) shr 8;
FX_VB2 := ( C2 and $FF0000 ) shr 16;
FX_VA2 := A2;

FX_VR3 :=   C3 and $FF;
FX_VG3 := ( C3 and $FF00   ) shr 8;
FX_VB3 := ( C3 and $FF0000 ) shr 16;
FX_VA3 := A3;

FX_VR4 :=   C4 and $FF;
FX_VG4 := ( C4 and $FF00   ) shr 8;
FX_VB4 := ( C4 and $FF0000 ) shr 16;
FX_VA4 := A4;

End;

end.
