[cairo] 'erasing' a surface

Jonathan Roewen jonathan.roewen at gmail.com
Mon Apr 18 22:57:48 PDT 2005


> That should be as simple as:
> 
>        cairo_rectangle (cr, x, y, width, height);
>        cairo_set_source_rgb (cr, 0, 0, 0);
>        cairo_fill (cr);

Should be that simple. However, I'm still having rendering issues--not
sure if it's because of the ocaml-cairo bindings, or whether it is
something more obtuse in my code.

I'll fill out all of what I'm doing:

1) create a buffer into which to draw
2) do all the necessary drawing to the buffer
3) draw buffer into my linear frame buffer

creating the buffer:
let double_buffer () =
  let cr = Cairo.create () in
  let surface =
    Cairo.image_surface_create Cairo.FORMAT_ARGB32 width height in
  Cairo.set_target_surface cr surface;
  Cairo.rectangle cr 0. 0. width height;
  Cairo.set_rgb_color cr 0. 0. 0.;
  Cairo.fill cr;
  cr (* this last bit returns the Cairo.t *)

then drawing into the buffer is just normal cairo operations (in this
instance, my 'port' of fdclock drawn over a background image).

then, finally, drawing the result into the linear framebuffer.
let buffer_to_screen cr =
  let surface = Cairo.current_target_surface cr in
  Cairo.show_surface cairo surface width height

where 'cairo' is a global instance representing the framebuffer.

On the first time drawing to the framebuffer, everything is rendered
correctly. However, successive redraws result in the output at
http://www.purevoid.org/~jroewen/rendering_bug.png

Any help with this would be appreciated. I'm still trying to figure
out the best way to do redrawing with cairo and translucent layers--so
if anyone can shine a light on something better than what I'm
currently doing, please tell me!

Jonathan



More information about the cairo mailing list