Well this does something ... But I don't think thats what we want ... I
still don't know how to get color data from dataref.
use SDL;
BEGIN{
delete $main::{in};
}
use PDL;
use PDL::NiceSlice;
use SDL::Video;
use SDL::Event;
use SDL::Surface;
use SDL::Constants;
use Carp;
# Allocate a 10x10 array for rgb. I think that only the zeroes function
allows
# # you to declare a piddle with a specific data type
my $pdl = zeroes(byte, 3, 10, 10);
#
#
# # Set values. Use in place to be sure we don't get another allocation,
which may be the wrong type.
# # Note that the sequence wraps back to zero after hitting 256, because
they're bytes!
$pdl->inplace->sequence;
#
# # Now for a really silly animation - turn all the pixels white
carp 'Unable to init SDL: '.SDL::get_error() if( SDL::init(SDL_INIT_VIDEO) <
0);
my $screen = SDL::Video::set_video_mode( 640, 480, 32, SDL_SWSURFACE);
carp 'Unable to set 640x480x32 video'.SDL::get_error() if(!$screen);
my $offset = $screen->pitch / 4;
sub putpixel
{
my($x, $y, $color) = @_;
my $lineoffset = $y * ($screen->pitch / 4);
$screen->set_pixels( $lineoffset+ $x, $color);
}
sub render
{
if( SDL::Video::MUSTLOCK( $screen) )
{
return if (SDL::Video::lock_surface( $screen ) < 0)
}
for (my $i = 0; $i < 300; $i++) {
$pdl()->clump(-1)->($i) = 255;
$iv = $pdl->get_dataref();
putpixel( $i, $i, $iv );
}
SDL::Video::unlock_surface($screen) if (SDL::Video::MUSTLOCK($screen));
SDL::Video::update_rect($screen, 0, 0, 640, 480);
}
while(1)
{
render();
my $event = SDL::Event->new();
while( SDL::Events::poll_event($event) )
{
my $type = $event->type;
if( $type == SDL_QUIT)
{
SDL::quit();
exit();
}
}
SDL::Events::pump_events();
}
On Mon, Nov 16, 2009 at 6:36 PM, David Mertens <[email protected]> wrote:
> On Mon, Nov 16, 2009 at 4:51 PM, Kartik Thakore
> <[email protected]>wrote:
>
>> How do I update this? like animation?
>>
>> while(1)
>> {
>>
>> $pdl_memory->get_dataref();
>>
>> }
>>
>
> Yeah, you know, I used a terrible variable name for that piddle. Let's try
> this:
>
> --------%<--------
>
> use PDL;
> use PDL::NiceSlice;
>
>
> # Allocate a 10x10 array for rgb. I think that only the zeroes function
> allows
> # you to declare a piddle with a specific data type
> my $pdl = zeroes(byte, 3, 10, 10);
>
>
> # Set values. Use in place to be sure we don't get another allocation,
> which may be the wrong type.
> # Note that the sequence wraps back to zero after hitting 256, because
> they're bytes!
> $pdl->inplace->sequence;
>
> # Now for a really silly animation - turn all the pixels white
> for (my $i = 0; $i < 300; $i++) {
> $pdl()->clump(-1)->($i) = 255;
> # Do something with piddle data here.
> }
>
> --------%<--------
>
> Is that a bit clearer? Does anybody have a better sample?
>
> David
>