[cairo] cairo to sdl surface

Gadi Dor gadido30 at gmail.com
Sat Jan 12 18:02:43 PST 2013


Hi all,

I did some progress but still I got blank window, here is my code:

Display *dpy;

    dpy = XOpenDisplay(NULL);

   //stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB32 , width);
   //SDL_Surface *sdl=SDL_SetVideoMode(width,height,24,SDL_HWSURFACE);
    //SDL_Surface *sdl;
     Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
        rmask = 0xff000000;
        gmask = 0x00ff0000;
        bmask = 0x0000ff00;
        amask = 0x00000000;
#else
        rmask = 0x000000ff;
        gmask = 0x0000ff00;
        bmask = 0x00ff0000;
        amask = 0x00000000;
#endif

SDL_Surface *sdl = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
                                      24, rmask, gmask, bmask, amask);




   cairo_surface_t *surface_source =
cairo_xlib_surface_create(dpy,DefaultRootWindow(dpy), DefaultVisual(dpy,
DefaultScreen(dpy)),height, width);

   cairo_surface_t *surface_dest =
cairo_image_surface_create_for_data((unsigned char *)sdl->pixels,
CAIRO_FORMAT_RGB24, sdl->w, sdl->h, sdl->pitch);
   cairo_t *cr_dest = cairo_create(surface_dest);
   //cairo_scale(cr_dest, (double)width, (double)height );

   cairo_set_source_surface(cr_dest, surface_source, (double)height,
(double)width);
   cairo_paint(cr_dest);

   cairo_set_source_rgba (cr_dest, 0.5, 0.5, 0.5, 1.0);
    SDL_SaveBMP(sdl,"test.bmp");
    //cairo_surface_write_to_png(surface_dest,"test.png");

   cairo_paint(cr_dest);
   cairo_surface_destroy(surface_source);
   cairo_surface_destroy(surface_dest);

I want to copy from cairo surface into sdl surface, any idea please? also
will it work fast? or is there other way?

Best Regards,
Gadi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130113/bd1e12b1/attachment.html>


More information about the cairo mailing list