In this chapter we will look at how to use pixel effects in Perl.
Pixel effects are operations that are done directly on the bank of a
These effects are used to do visual effects in games and applications,
most notably by
These effects can be done in purely in Perl, for 1 passes and non real time applications. Effects that need to be done real time will have to be done in C via XS. This chapter will show two methods of doing this.
For our first pixel effect we will be doing is a ripple effect from a well known SDL resource,
This effects uses
SDL::get_ticks to animate a ripple effect across the surface as seen in the following figure.
First lets make the effect in pure Perl.
To do any operations with a
SDL::Surface we must do
SDL::Video::lock_surface() call as seen below.
Locking the surface prevents other process in SDL from accessing the surface.
The surface pixels can be accessed several ways from Perl.
Here we are using the
SDL::Surface::set_pixels which takes an offset for the
SDL_Surface pixels array,
and sets a value there for us.
The actual pixel effect is just a time dependent (using
SDL::get_ticks for time) render of a function.
See HTTP://Sol.Gfxile.Net/gp/ch02.html for a deeper explanation.
One you run this program you will find it pretty much maxing out the CPU and not running very smoothly.
At this point running a loop through the entire pixel bank of a
640x480 sized screen is too much for Perl.
We will need to move the intensive calculations to
In the below example we use
Inline to write Inline
C code to handle the pixel effect for us.
SDL now provides support to work with
render callback is now moved to
When the program first runs it will compile the code and link it in for us.
Hey! The above document had some coding errors, which are explained below: