chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] I'm trying to use the cairo egg with the sdl2 egg bu


From: kooda
Subject: Re: [Chicken-users] I'm trying to use the cairo egg with the sdl2 egg but not making much progress. An
Date: Mon, 28 Jan 2019 08:12:01 +0100

Matt Welland <address@hidden> wrote:
> Assuming it is possible, I'd like to use cairo to draw on sdl2
> surfaces. I've read the demos and other available code but I'm not yet
> seeing how to bolt them together. Does anyone have some example code
> they can share to help me get going?

It is absolutly possible! I’ve done it countless times, with surfaces as well 
as textures (in the renderers API).

Here is the code I’ve wrote to use cairo on surfaces:
It’s old code and I’ve not tested it in a whire though.

(define (sdl-colorspace->cairo bytes-per-pixel)
  (case (* 8 bytes-per-pixel)
    ((8) CAIRO_FORMAT_A8)
    ((24) CAIRO_FORMAT_RGB24)
    ((32) CAIRO_FORMAT_ARGB32)
    (else CAIRO_FORMAT_ARGB32)))

(define (create-sdl2-cairo-context window)
  (let-values
    (((width height) (window-size window))
     ((window-surface) (window-surface window))
     ((cairo-surface)
      (cairo-image-surface-create-for-data
        (surface-pixels-raw window-surface)
        (sdl-colorspace->cairo
          (pixel-format-bytes-per-pixel (surface-format window-surface)))
        width
        height
        (surface-pitch window-surface))))
    (cairo-create cairo-surface)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]