hi felix!

On Thu, Jun 26, 2008 at 05:03:32PM +0200, Felix Winkelmann wrote:
> 
> This is probably a typical newbie's question, but can someone provide
> me a simple example of drawing an image with transparent background?
> I have a PNG with transparency and invoke RenderTo to blit the image
> to the screen. Running with --dfb:system=X11 (the only backend I
> tried so far), shows a black blackground instead of a transparent
> one.
> 
> I tried setting DSBLIT_BLEND_ALPHACHANNEL on the screen surface, and
> various other things, but I simply can't get it to work.
> 
> Any hints?

it works when you first render the image into an intermediate surface.
i think because the screen surface doesn't have an alpha channel, so
the image provider cannot render it.  if you render into a surface
with alpha channel and then blit it to the screen with
DSBLIT_BLEND_ALPHACHANNEL it works.

for example: (i suppose you don't mind it's written in scheme :)

(require-extension directfb srfi-18)

(define (trans-test image-file)
  (with-dfb-objects ((dfb (dfb-initialize coop-level: 'FULLSCREEN))
                     (primary (dfb-create-surface dfb caps: '(PRIMARY FLIPPING)
                                                  width: 800 height: 600))
                     (img (dfb-load-image-to-surface dfb image-file)))
    (let-values (((screen-w screen-h) (dfbs-get-size primary))
                 ((img-w img-h) (dfbs-get-size img)))
      (thread-sleep! .1)
      (dfbs-set-color primary 255 0 0 255)
      (dfbs-fill-rectangle primary 0 0 screen-w screen-h)
      (dfbs-set-blitting-flags primary '(BLEND-ALPHACHANNEL))
      (dfbs-blit primary img #f
                 (fx/ (fx- screen-w img-w) 2)
                 (fx/ (fx- screen-h img-h) 2))
      (dfbs-flip primary #f '())
      (thread-sleep! 5))))


dfb-load-image-to-surface is defined like this (but is provided by the
chicken directfb binding):

(define (dfb-load-image-to-surface dfb filename)
  (with-dfb-objects ((ip (dfb-create-image-provider dfb filename))
                     (s (dfb-create-surface dfb (dfbip-get-surface-description 
ip))))
    (dfbip-render-to ip s #f)
    (dfb-give s)))

hth&bye,
hans.

_______________________________________________
directfb-users mailing list
directfb-users@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users

Reply via email to