smarthaert / phoenixlib

Automatically exported from code.google.com/p/phoenixlib
0 stars 0 forks source link

TPhxImage.DrawAre with 4 Colors and Blending Mode #132

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please add this to phxImage.

procedure TPHXImage.DrawArea(const X, Y: Integer; const Area: TRecti;
  const PatternIndex: Cardinal; const ColorTopLeft, ColorTopRight, ColorBottomRight, ColorBottomLeft: TColor4f;
  Blend: TPHXBlendMode);
var TexCoord: TRectf;
var Index   : Integer;
var IW, IH  : Integer;
  begin
  {$HINTS OFF}
  TexCoord.Left  :=(FPatterns[PatternIndex].X + Area.Left  ) / Width;
  TexCoord.Top   :=(FPatterns[PatternIndex].Y + Area.Top   ) / Height;
  TexCoord.Right :=(FPatterns[PatternIndex].X + Area.Right ) / Width;
  TexCoord.Bottom:=(FPatterns[PatternIndex].Y + Area.Bottom) / Height;
  {$HINTS ON}
  IW:= Area.Right  - Area.Left;
  IH:= Area.Bottom - Area.Top;

  Index:= Buffer.Alloc(4);

  // Top - left
  Buffer.List^[Index].Position.X:= X ;
  Buffer.List^[Index].Position.Y:= Y;
  Buffer.List^[Index].Position.Z:= 0;

  Buffer.List^[Index].TexCoord.X:= TexCoord.Left;
  Buffer.List^[Index].TexCoord.Y:= TexCoord.Top;

  Buffer.List^[Index].Color:= ColorTopLeft;

  Inc(Index);

  // Top - right
  Buffer.List^[Index].Position.X:= X + IW;
  Buffer.List^[Index].Position.Y:= Y;
  Buffer.List^[Index].Position.Z:= 0;

  Buffer.List^[Index].TexCoord.X:= TexCoord.Right;
  Buffer.List^[Index].TexCoord.Y:= TexCoord.Top;

  Buffer.List^[Index].Color:= ColorTopRight;

  Inc(Index);

  // Bottom - right
  Buffer.List^[Index].Position.X:= X + IW;
  Buffer.List^[Index].Position.Y:= Y + IH;
  Buffer.List^[Index].Position.Z:= 0;

  Buffer.List^[Index].TexCoord.X:= TexCoord.Right;
  Buffer.List^[Index].TexCoord.Y:= TexCoord.Bottom;

  Buffer.List^[Index].Color:= ColorBottomRight;

  Inc(Index);

  // Bottom - Left
  Buffer.List^[Index].Position.X:= X ;
  Buffer.List^[Index].Position.Y:= Y + IH;
  Buffer.List^[Index].Position.Z:= 0;

  Buffer.List^[Index].TexCoord.X:= TexCoord.Left;
  Buffer.List^[Index].TexCoord.Y:= TexCoord.Bottom;

  Buffer.List^[Index].Color:= ColorBottomLeft;

  if not FBatching then
  begin
    FDevice.SetRenderState(PHX_BLENDMODE, Blend);
    FDevice.SetRenderState(PHX_DEPTHTEST, PHX_DEPTHTEST_OFF);

    FDevice.SetTexture(Texture);

    FDevice.Render(PHX_QUADS, Buffer);

    Buffer.Clear;
  end;
end;

Original issue reported on code.google.com by wagenhei...@gmail.com on 11 Feb 2011 at 12:12

GoogleCodeExporter commented 9 years ago
HUmm... I need to add Angle here also... Is possible?

Original comment by wagenhei...@gmail.com on 16 Feb 2011 at 2:17

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
For each vertex;

Buffer.List^[Index].Position:= Matrix_Multiply( Matrix_RotationZ(Angle), 
Matrix_Translation(X,Y,0);

And you have to change each coordinate to:

  Buffer.List^[Index].Position.X:= + IW / 2;
  Buffer.List^[Index].Position.Y:= - IH / 2;
  Buffer.List^[Index].Position.Z:= 0;

So they form a rectangle around origo.

Original comment by andreas....@gmail.com on 17 Feb 2011 at 6:47

GoogleCodeExporter commented 9 years ago
MatrixMultiply returns TVector4f but possition need TVector3f!  I could not 
make it works...

If possible, please complete the function for me! =)

Original comment by wagenhei...@gmail.com on 20 Feb 2011 at 6:05

GoogleCodeExporter commented 9 years ago

Original comment by andreas....@gmail.com on 8 Aug 2013 at 2:11