Skip to content

Instantly share code, notes, and snippets.

@FROGGS
Created September 23, 2012 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FROGGS/3772701 to your computer and use it in GitHub Desktop.
Save FROGGS/3772701 to your computer and use it in GitHub Desktop.
PDL to Surface
#!/usr/bin/perl
use strict;
use warnings;
use SDL;
use SDL::Surface;
use SDLx::App;
use SDLx::Surface;
use PDL;
use Data::Dumper;
my $app = SDLx::App->new(
title => "PDL and SDL aplication",
width => 640, height => 640, eoq => 1
);
sub make_surface_piddle {
my $piddle = rpic('SDL/test/data/picture.jpg');
my ($bytes_per_pixel,$width,$height) = $piddle->dims;
my $surface = SDLx::Surface->new( width => $width, height => $height, depth => 32 );
SDL::Video::lock_surface($surface);
my @pix = $piddle->list;
my $y = $height;
my $x = 0;
while( my @p = splice( @pix, 0, 3 ) ) {
unless( $x % $width ) {
$x = 0;
$y--;
}
$surface->set_pixel( $y, $x++, \@p );
}
SDL::Video::unlock_surface($surface);
warn "Made surface of $width, $height and ". $surface->format->BytesPerPixel;
return ( $piddle, $surface );
}
my ( $piddle, $surface ) = make_surface_piddle();
$app->add_show_handler( sub {
$surface->blit( $app, [0,0,$surface->w,$surface->h], [10,10,0,0] );
$app->update();
} );
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment