Matt Welland <m...@kiatoa.com> 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)))

_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to