Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Perl 6 SDL2 example - continued

by holyghost (Beadle)
on Jul 09, 2016 at 12:28 UTC ( [id://1167501]=CUFP: print w/replies, xml ) Need Help??

In my previous example I said you could draw images on the screen of an SDL2 window. Here's how you create a texture (or surface) which has width 320 and height 200. Think of it as a rectangle where you can draw on :
use SDL2::Raw; my $tile = SDL_CreateTexture($renderer, RGBA8888, STREAMING, 320, 200);
To put pixels on the $tile texture, you can update the texture with an array of pixels (pixelpoints on the surface) Each pixel is 32 bits wide in SDL2, there is red, green blue and an alpha (transparent) channel (RGBA8888, where 8+8+8+8=32 bits).
my $data = 0; ### pixelbuffer is empty sub render { SDL_UpdateTexture($tile, NULL, $data, 320*32); ### update 32 bits of 3 +20 pixels }

Replies are listed 'Best First'.
Re: Perl 6 SDL2 example - continued
by holyghost (Beadle) on Jul 10, 2016 at 06:36 UTC
    To correct:
    my @data; my $tile = SDL_CreateTexture($render, %PIXELFORMAT<ARGB8888>, TARGET, +320, 200);
    Then posting the tile to the viewport (this belongs in the render function):
    my SDL_Rect $src .= new: x => 0, y => 0, w => 320, h => 200; SDL_RenderCopy($render, $tile, $src, SDL_Rect); ### blits the data arr +ay of, in this case 32 bit wide pixels (ARGB8888)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://1167501]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found