I figured that this would be the best place to post this as it relates to my own sdlutils.pas added draw functions.

In my Cyber-Crisis post I was trying to do an explosion effect and needed a function that would allow me to take a texture and rotate, ADD, scale and fade all at once. It seems that even with my added functions, JEDI-SDL just doesn't cut the mustard. :?

So I went looking for the best way I could at least work my way to such a function. I came to my own [size=9px](as yet un-added)[/size] SDL_RotateDeg_Alpha() function. It was the only one to allow mor than one effect at once. Rotate and Alpha. I figured I'd start with changing simple Alpha to Add with the ability to adjust the level for fading.

This is the result:
[pascal]procedure SDL_RotateDeg_AddAlpha(DstSurface, SrcSurface: PSDL_Surface; SrcRect: PSDL_Rect;
DestX, DestY, OffsetX, OffsetY: Integer; Angle: Integer;
Alpha: UInt;
var
aSin, aCos: Single;
MX, MY, DX, DY, NX, NY, SX, SY, OX, OY, Width, Height, TX, TY, RX, RY, ROX, ROY: Integer;
SrcColor, DstColor: UInt32;
srcRR, srcGG, srcBB, dstRR, dstGG, dstBB: UInt8;
TempTransparentColour: UInt32;
MAXX, MAXY: Integer;
begin
// Rotate the surface to the target surface.
TempTransparentColour := SrcSurface.format.colorkey;

maxx := DstSurface.w;
maxy := DstSurface.h;
aCos := degCOS[Angle];
aSin := degSIN[Angle];

Width := round(abs(srcrect.h * acos) + abs(srcrect.w * asin));
Height := round(abs(srcrect.h * asin) + abs(srcrect.w * acos));

OX := Width shr 1;
OY := Height shr 1;
MX := (srcRect.x + (srcRect.x + srcRect.w)) shr 1;
MY := (srcRect.y + (srcRect.y + srcRect.h)) shr 1;
ROX := (-(srcRect.w shr 1)) + Offsetx;
ROY := (-(srcRect.h shr 1)) + OffsetY;
Tx := ox + round(ROX * aSin - ROY * aCos);
Ty := oy + round(ROY * aSin + ROX * aCos);
SX := 0;
for DX := DestX - TX to DestX - TX + (width) do
begin
inc(SX);
SY := 0;
for DY := DestY - TY to DestY - TY + (Height) do
begin
if ((DX > 0) and (DX < MAXX)) and
((DY > 0) and (DY < MAXY)) then
begin
RX := SX - OX;
RY := SY - OY;
NX := mx + Round(RX * aSin + RY * aCos); //
NY := my + Round(RY * aSin - RX * aCos); //

if (NX >= srcRect.x) and (NX <= srcRect.x + srcRect.w) then
begin
if (NY >= srcRect.y) and (NY <= srcRect.y + srcRect.h) then
begin
SrcColor := SDL_GetPixel(SrcSurface, NX, NY);
if (SrcColor <> TempTransparentColour) then
begin
SDL_GetRGB(SrcColor, SrcSurface.format, @srcRR, @srcGG, @srcBB);


SDL_AddPixel(DstSurface, DX, DY,
SDL_MapRGB(DstSurface.format,
(Alpha * srcRR) shr 8,
(Alpha * srcGG) shr 8,
(Alpha * srcBB) shr );
end;
end;
end;
end;
inc(SY);
end;
end;
end;[/pascal]

Works fairly well and the effect looks nice too. But there are two things that really bother me about both of these functions still.

1) It's slow! Stick try to use this function in your game loop and you'll notice the FPS drop.

2) That darn border around where the texture's edge is.


I'd like to find a way to improve (1) and remove (2) for both these functions. Anyone capable willing to lend some time to this?