Cairo+glitz/Setup cairo

From Sidvind
Jump to: navigation, search
Note: glitz support in cairo-1.8 is broken!

See cairo+glitz/Setup glitz with glx for details about getting glitz to work.

Cairo surface[edit]

One the glitz surface is created it is actually quite simple to have cairo use it as backend.

Code:

  1. // Create a cairo surface with glitz as backend.
  2. cairo_surface_t* pCairoSurface = cairo_glitz_surface_create (surface);
  3.  
  4. // Create the cairo context as usual.
  5. cairo_t* cr = cairo_create (pCairoSurface);

Rendering sample[edit]

Code:

  1. // Clear the surface.
  2. cairo_scale(cr, 2.5, 2.5);
  3. cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
  4. cairo_paint (cr);
  5.  
  6. // Use default operator and color.
  7. cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
  8. cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 1.0f);
  9.  
  10. // This is one of the samples provided by the cairo documentation, see http://www.cairographics.org/samples/curve_to/
  11. double x=25.6,  y=128.0;
  12. double x1=102.4, y1=230.4,
  13.        x2=153.6, y2=25.6,
  14.        x3=230.4, y3=128.0;
  15.  
  16. cairo_move_to (cr, x, y);
  17. cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
  18.  
  19. cairo_set_line_width (cr, 10.0);
  20. cairo_stroke (cr);
  21.  
  22. cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6);
  23. cairo_set_line_width (cr, 6.0);
  24. cairo_move_to (cr,x,y);   cairo_line_to (cr,x1,y1);
  25. cairo_move_to (cr,x2,y2); cairo_line_to (cr,x3,y3);
  26. cairo_stroke (cr);
  27.  
  28. // Swap buffers using glitz.
  29. glitz_drawable_swap_buffers(drawable);