Results 1 to 2 of 2

Thread: Drawing a TBitmpa onto a Surface

  1. #1
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Drawing a TBitmpa onto a Surface

    How do I draw an off screen bitmap (stored in TBitmap - as I ant to use the canvas) onto a surface?
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  2. #2
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Drawing a TBitmpa onto a Surface

    [pascal]procedure TS2DLImage.CopyBitmap(X, Y: Integer; BMP: TBitmap;
    TransparentColor: UInt32);
    var
    bits : Pointer;
    I,J, bpp, r, g, b : Uint8;
    Color : UInt32;
    begin
    if ( SDL_LockSurface( ImageSurface ) < 0 ) then
    exit;
    bpp := ImageSurface.format.BytesPerPixel;
    For I := 0 to BMP.Width-1 do
    For J := 0 to BMP.Height-1 do
    Begin
    Color := BMP.Canvas.Pixels[I,J];
    If Color <> TransparentColor then
    Begin
    bits := @(PixelArray(ImageSurface.Pixels^)[((Y+I) * ImageSurface.pitch) + ((X+J) * bpp)]);
    // Set the pixel
    case bpp of
    1:
    begin
    PUint8( bits )^ := Uint8(Color);
    end;
    2:
    begin
    PUint16(bits)^ := Uint16(Color);
    end;
    3:
    begin // Format/endian independent
    r := (Color shr ImageSurface.format.Rshift ) and $FF;
    g := (Color shr ImageSurface.format.Gshift ) and $FF;
    b := (Color shr ImageSurface.format.Bshift ) and $FF;
    PixelFormat(bits^)[(ImageSurface.format.Rshift div ] := r;
    PixelFormat(bits^)[(ImageSurface.format.Gshift div ] := g;
    PixelFormat(bits^)[(ImageSurface.format.Bshift div ] := b;
    end;
    4:
    begin
    PUInt32(bits)^ := Uint32( Color );
    end;
    end;
    End;
    End;
    // Update the display
    SDL_UnlockSurface(ImageSurface);
    SDL_UpdateRect(ImageSurface, X, Y, BMP.Width, BMP.Height);
    end;
    [/pascal]

    Dont think it will be great performance, but it does work
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •