SDL for RISC OS
Please note that before trying to compile any examples you will need the Castle 32bit SharedCLibrary installed on your computer.
Well, after failing badly to set up a cross compiler and then much bugging of Mr Alan Buckley, I now have a set of up to date (though now probably out of date) SDL Libraries for RISC OS. Many thanks to Alan.
With this bi-months episode is the gcc c compiler, tools and utilities version 3.46, a version of UnixLib, SDL, SDL_mixer, SDL_image, SDL_gfx and others, all of which are subject to their licences. The code for the xpm and png routines has been cunningly crammed into this months example. First please read the disclaimer in article 1 of this series.
Looking in the makefile you will see that the method for identifying the libraries has changed from the first example. Looking in the !SDL help file will tell you what you might want to know about how to use it.
If you have used any of the BASIC plotting routines you should easily be able to learn how to use the gfx primitives library. The library consists of a number of functions to draw various shapes using either a numbered colour or using RGB and Alpha. Antialiasing is is also supported in some functions but may not be very efficient. Browsing through SDL_gfxPrimitives.h will tell you the full list of available functions but few of the more interesting ones are as follows.
Note that all ___Color routines expect the colour to be in format 0xRRGGBBAA which is a hex number from 00 to FF for each channel.
PixelColor ( surface , x , y , colour ); pixelRGBA( surface , x , y , r , g , b , a );
hlineRGBA ( surface , start x , end x , y , r , b , a );
vlineColor( surface , x , start y , end y , color );
lineColor( surface , start x , start y , end x , end y , color );
Shapes such as rectangles, pies and polygons are also supported in a similar fashion. In the code example I have included a few as a test screen for you to play around with. I encourage you to try changing a few of the variables or adding a few different shapes listed in SDL_gfxPrimitives.h and recompiling the code to see the results.
Well, from what I can gather from the supplied example and the limited documentation of the rotozoom library (read the disclaimer again) the rotozoom function will create a new surface of the correct size for the image and blit the image into that. It is probably best to create any rotated surfaces you want to use before you use them rather that do it on the fly as this will eat up cpu time.
rotozoomSurface ( surface , angle , zoom , smooth );
Rotates and zooms a 32bit or 8bit surface to newly created surface. 'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1 then the destination 32bit surface is anti-aliased. If the surface is not 8bit or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
rotozoomSurfaceXY ( surface , angle , zoomx , zoomy , smooth );
Rotates and zooms a 32bit or 8bit surface to newly created surface. 'angle' is the rotation in degrees. 'zoomx' and 'zoomy' are scaling factors that can also be negative. In this case the corresponding axis is flipped. If 'smooth' is 1 then the destination 32bit surface is anti-aliased. If the surface is not 8bit or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
Note: Flipping currently only works with antialiasing turned off.
zoomSurface ( surface , zoomx , zoomy , smooth );
Zooms a 32bit or 8bit surface to newly created surface. 'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1 then the destination 32bit surface is anti-aliased. If the surface is not 8bit or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
The example I have supplied uses some slightly chopped up code from the test programs in the roto zoom source folder. Again, try changing a few of the numbers, all the best programs are created by simply banging the keyboard randomly.
The rotate picture function in the example accepts 5 variables, the destination surface, the surface to rotate, and a number to tell it to rotate, a number to tell it to use smooting or not. Changing these will result in a different effect on the RISC World logo when you recompile. This function is self contained and does all the screen redrawing and rotating and blitting inside the function.
The next part of the code simply draws a selection of shapes available form the primitives part of the library, then waits for a second, redraws the screen and uses the checkkeys() function to intercept any quit commands.
Hopefully I will find some reason to use the SDL_gfx libraries in one of my games, which i'm sure if I ever finish any will be included in the software section of this magazine.