Atacama has asked for the wisdom of the Perl Monks concerning the following question:
Hi.
I'm trying to get SDL and Cairo working together using the code below.
I expect Cairo to draw a red square inside the SDL window.
The program segfaults instead.
This page cairographics.org/SDL says that libraries should work fine together if they "agree on the pixel format"
I tried to change pixel format to 24/rgb24 and other permutations of available formats without success.
Am I missing something?
Thank you for your time.
use strict; use warnings; use SDL v2.3; use SDL::Video; use SDL::Event; use SDL::Events; use SDL::Surface; use Cairo; my $WIDTH = 400; my $HEIGHT = 300; # relevant part starts: my $screen = SDL::Video::set_video_mode($WIDTH, $HEIGHT, 32, SDL_SWSUR +FACE); SDL::Video::lock_surface($screen); my $surface = Cairo::ImageSurface->create_for_data ( $screen->get_pixels_ptr, 'argb32', $screen->w, $screen->h, $screen->pitch ); my $cairo = Cairo::Context->create($surface); $cairo->rectangle(0, 0, 100, 100); $cairo->set_source_rgb(255, 0, 0); $cairo->fill; SDL::Video::unlock_surface($screen); SDL::Video::update_rect($screen, 0, 0, $WIDTH, $HEIGHT); # relevant part ends LOOP: while (1) { my $event = SDL::Event->new(); while (SDL::Events::poll_event($event)) { last LOOP if $event->type == SDL_KEYDOWN || $event->type == SDL_QUIT; } SDL::Events::pump_events(); } SDL::quit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SDL and Cairo segfault
by Khen1950fx (Canon) on Jan 08, 2011 at 07:17 UTC | |
by Atacama (Sexton) on Jan 09, 2011 at 20:46 UTC | |
by Khen1950fx (Canon) on Jan 10, 2011 at 11:23 UTC |