Skip to content
Newer
Older
100644 59 lines (42 sloc) 1.11 KB
59b6ea6 @kthakore Cleaned up Inline C Effects with new SDL from github
kthakore authored
1 use strict;
2 use warnings;
3 use Inline with => 'SDL';
eafb829 @kthakore Made Inline XS effect
kthakore authored
4 use SDL;
5 use SDLx::App;
59b6ea6 @kthakore Cleaned up Inline C Effects with new SDL from github
kthakore authored
6
7
8 my $app = SDLx::App->new( width => 640, height => 480, eoq => 1, title => "Grovvy XS Effects" );
9
d1f7e12 @kthakore No need to make an anon callback
kthakore authored
10 $app->add_show_handler( \&render );
59b6ea6 @kthakore Cleaned up Inline C Effects with new SDL from github
kthakore authored
11
12 $app->run();
13
14 use Inline C => <<'END';
eafb829 @kthakore Made Inline XS effect
kthakore authored
15
d1f7e12 @kthakore No need to make an anon callback
kthakore authored
16 void render( float delta, SDL_Surface *screen )
eafb829 @kthakore Made Inline XS effect
kthakore authored
17 {
b9cb33c @kthakore Added image file for xs effects
kthakore authored
18 // Lock surface if needed
19 if (SDL_MUSTLOCK(screen))
20 if (SDL_LockSurface(screen) < 0)
21 return;
22
23 // Ask SDL for the time in milliseconds
24 int tick = SDL_GetTicks();
25
26 // Declare a couple of variables
27 int i, j, yofs, ofs;
28
29 // Draw to screen
30 yofs = 0;
d1f7e12 @kthakore No need to make an anon callback
kthakore authored
31 for (i = 0; i < screen->h; i++)
b9cb33c @kthakore Added image file for xs effects
kthakore authored
32 {
d1f7e12 @kthakore No need to make an anon callback
kthakore authored
33 for (j = 0, ofs = yofs; j < screen->w; j++, ofs++)
b9cb33c @kthakore Added image file for xs effects
kthakore authored
34 {
da1148b @kthakore Showing maping of color
kthakore authored
35
36 Uint32 value = i * i + j * j + tick;
37 Uint8 a = value >> 2;
38 Uint8 b = value >> 4;
39 Uint8 g = value >> 8;
40 Uint8 r = value >> 16;
41
42 Uint32 map_val = SDL_MapRGBA( screen->format, r, g, b, a);
43 ((unsigned int*)screen->pixels)[ofs] = map_val;
b9cb33c @kthakore Added image file for xs effects
kthakore authored
44 }
45 yofs += screen->pitch / 4;
46 }
47
48 // Unlock if needed
49 if (SDL_MUSTLOCK(screen))
50 SDL_UnlockSurface(screen);
51
52 // Tell SDL to update the whole screen
d1f7e12 @kthakore No need to make an anon callback
kthakore authored
53 SDL_UpdateRect(screen, 0, 0, screen->w,screen->h);
eafb829 @kthakore Made Inline XS effect
kthakore authored
54 }
55
59b6ea6 @kthakore Cleaned up Inline C Effects with new SDL from github
kthakore authored
56 END
eafb829 @kthakore Made Inline XS effect
kthakore authored
57
58
Something went wrong with that request. Please try again.