use strict; no warnings; use SDL v2.3; use SDL::Video; use SDL::Surface; use Cairo; SDL::init(SDL_INIT_VIDEO); my $screen = SDL::Video::set_video_mode(400, 300, 32, SDL_SWSURFACE); SDL::Video::lock_surface($screen) if SDL::Video::MUSTLOCK($screen); my $surface = Cairo::ImageSurface->create_for_data ( $screen->get_pixels_ptr, 'argb32', $screen->w, $screen->h, $screen->pitch ); my $cr = Cairo::Context->create($surface); $cr->rectangle(10, 10, 40, 40); $cr->set_source_rgb(255, 0, 0); $cr->fill; SDL::Video::unlock_surface($screen) if SDL::Video::MUSTLOCK($screen); SDL::Video::flip($screen); SDL::delay(2000); SDL::quit(); #### #include #include int main () { SDL_Init(SDL_INIT_VIDEO); SDL_Surface *screen = SDL_SetVideoMode(400, 300, 32, SDL_SWSURFACE); if (SDL_MUSTLOCK(screen)) { SDL_LockSurface(screen); } cairo_surface_t *cairosurf = cairo_image_surface_create_for_data ( screen->pixels, CAIRO_FORMAT_ARGB32, screen->w, screen->h, screen->pitch ); cairo_t *cr = cairo_create(cairosurf); cairo_rectangle(cr, 10, 10, 40, 40); cairo_set_source_rgb(cr, 255, 0, 0); cairo_fill(cr); if (SDL_MUSTLOCK(screen)) { SDL_UnlockSurface(screen); } SDL_Flip(screen); SDL_Delay(2000); SDL_Quit(); return 0; }