Results 1 to 3 of 3

Thread: Draw a TW3ImageData instance to canvas with Alphablending?

  1. #1

    Draw a TW3ImageData instance to canvas with Alphablending?

    Hey all,
    I am experimenting with displaying "images" defined in a TW3ImageData instance in SMS that I have created in code, but I can't seem to get them to be drawn using alphablending...

    I have images using a palette that I cycle so I copy the colours from the cBallPalette over to an internal Palette of 16 TW3RGBA values.

    Code:
      cBallPalette: array[0..(16 * 4) - 1] of Integer = (
        $00,$00,$00,$00,    // $00 transparent colour
        $66,$66,$66,$80,    // $01 shadow colour
        $FF,$FF,$FF,$FF,    // $02
        $FF,$FF,$FF,$FF,    // $03
        $FF,$FF,$FF,$FF,    // $04
        $FF,$FF,$FF,$FF,    // $05
        $FF,$00,$00,$FF,    // $06
        $FF,$00,$00,$FF,    // $07
        $FF,$00,$00,$FF,    // $08
        $FF,$00,$00,$FF,    // $09
        $FF,$00,$00,$FF,    // $0A
        $FF,$00,$00,$FF,    // $0B
        $FF,$00,$00,$FF,    // $0C
        $FF,$DD,$DD,$FF,    // $0D
        $FF,$FF,$FF,$FF,    // $0E
        $FF,$FF,$FF,$FF     // $0F
      );
    
    
    type
      TRetroBall = class
      private
    
    {...}
        FPalette     : array[0..16 - 1] of TW3RGBA;
    
    
        FImage       : TW3ImageData;
        // handle to image pixels
        FImagePixels : Variant;
    
    {...}
      FImage  := FCanvas.CreateImageData(FWidth, FHeight);
    
    
      FImagePixels := FImage.Handle;
    
    
      for i := 0 to High(FPalette) do
      begin
        FPalette[i].r := cBallPalette[i*4 + 0];
        FPalette[i].g := cBallPalette[i*4 + 1];
        FPalette[i].b := cBallPalette[i*4 + 2];
        FPalette[i].a := cBallPalette[i*4 + 3];
      end;
    
    
    {...}
      // create the image using indices into the palette
    
      sy := 0;
      for dy := 0 to FHeight - 1 do
      begin
        sx := 0;
        for dx := 0 to FWidth - 1 do
        begin
          bIndex := Trunc(sy) * cBallW + Trunc(sx);
          aColor := cBallData[bIndex];
    
    
          mIndex := 4 * (FWidth * dy + dx);
    
    
          FImagePixels.data[mIndex + 0] := FPalette[aColor].r;
          FImagePixels.data[mIndex + 1] := FPalette[aColor].g;
          FImagePixels.data[mIndex + 2] := FPalette[aColor].b;
          FImagePixels.data[mIndex + 3] := FPalette[aColor].a;
          sx := sx + IncX;
        end;
        sy := sy + IncY;
      end;
    
    
      // draw the image
      FCanvas.PutImageData(FImage, Trunc(FPosX - FWidth div 2), Trunc(FPosY - FHeight div 2));
    The image draws just fine, but any time I use a colour that has an Alpha value < 255, it is coming out like it was solid colours with an alpha of 255.

    In the screenshot below, the black should be transparent (and is in my palette), and the shadow grey should be partially transparent...as you can see, they are not:
    notalphablending.jpg

    Here is the paint routine:
    Code:
    procedure TApplication.PaintView(Canvas: TW3Canvas);
    var
      x, y, w : Integer;
      c : Integer;
      aColor : Integer;
      mHandle: Variant;
      mIndex: Integer;
      bIndex: Integer;
    begin
      FCenter.X := (GameView.Width div 2) - (cBallW div 2);
      FCenter.Y := (GameView.Height div 2) - (cBallH div 2);
    
    
      // Clear background
      Canvas.FillStyle := 'rgb(102,102,102';
      Canvas.FillRectF(0,0,GameView.Width,GameView.Height);
    
    
      // Clear background
      Canvas.FillStyle := 'rgb(255,0,99)';
      Canvas.FillRectF(10,10,60,12);
      Canvas.Font := '10pt verdana';
    
    
      FRetroBall.Render;
    
    
      if GameView.FrameRate > 0 then
        FRetroBall.Update(1/GameView.FrameRate);
      // Canvas.PutImageData(FBuffer, 0, 0, 0, 0, CImageWidth, CImageHeight);
    
    
      // Draw our framerate on the screen
      Canvas.FillStyle := 'rgb(255,255,255)';
      Canvas.FillTextF('FPS:' + IntToStr(GameView.FrameRate), 10, 20, MAX_INT);
    end;
    Any ideas?

    cheers,
    Paul

  2. #2
    Have you checked that the picture object containing FCanvas has 32bits per pixel set?

  3. #3
    I don't know, I will see if I can find out, cheers

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
  •