I had submitted a few alpha blending draw routeens for JEDI-SDL some time ago... submitted it to savage for inclusion into the final 1.0 release. Though, they didn't quite make it there yet. [size=9px]("He's a busy bloke", I believe thats proper UK-nese?)[/size]

But here is a copy of my personal 'special edition' of sdlutils.pas in JEDI-SDL.


EDIT: Here is a clip from my own personal copy of sdlutils.pas.

[pascal]var
{--- Trig Lookup Tables ---}
degSIN,
degCOS,
degTAN,
degArcCOS,
degArcSIN,
degArcTAN: Array[-360 .. 360] of Extended;


{Pre-Calculate SIN and COS Tables}
procedure PreCalculate_Trig;[/pascal]

The above to be placed in the interface portion of your unit.

Then you'll need this procedure:
[pascal]{Pre-Calculate SIN and COS Tables}
procedure PreCalculate_Trig;
var i: Integer;
begin
for i := Low(degSIN) to High(degSIN) do
degSIN[i] := sin(i * Pi_Div_180);
for i := Low(degCOS) to High(degCOS) do
degCOS[i] := cos(i * Pi_Div_180);
for i := Low(degTAN) to High(degTAN) do
degTAN[i] := tan(i * Pi_Div_180);
end;
[/pascal]

and be sure to either add this to your unit's main code block or execute it somewhere in your project's code before trying to use the function.

[pascal]begin
PreCalculate_Trig;
end.[/pascal]

Now you can add this function that will allow you to draw a sprite rotated[size=9px](in degrees)[/size] and alpha blended.

[pascal]procedure SDL_RotateDeg_Alpha(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);

DstColor := SDL_GetPixel(DstSurface, DX, DY);
SDL_GetRGB(DstColor, DstSurface.format, @dstRR, @dstGG, @dstBB);

SDL_PutPixel(DstSurface, DX, DY,
SDL_MapRGB(DstSurface.format,
(Alpha * (srcRR - dstRR)) shr 8 + dstRR,
(Alpha * (srcGG - dstGG)) shr 8 + dstGG,
(Alpha * (srcBB - dstBB)) shr 8 + dstBB));
end;
end;
end;
end;
inc(SY);
end;
end;
end;
[/pascal]

Obviously I'm using pre-calculations for this, which is a smart move considering that you might end up using a function like this, depending on the type of game your coding, a lot durring EACH frame.