Drobe :: The archives
About Drobe | Contact | RSS | Twitter | Tech docs | Downloads | BBC Micro

Using SDL natively

By Chris Williams. Published: 6th Oct 2004, 09:18:10 | Permalink | Printable

Neil White makes his move

The SDL library has helped RISC OS programmers bring various games and utilities from the open source world to the platform. Although not everything these days is about porting software: Neil White has begun using SDL in his own native puzzle games, such as Crazeeman and Conveysdl.

Neil's main reasons for using SDL for native games are that you can now play the games in the desktop, the software can use the graphics features of the SDL library and also, interestingly, the games can be ported to other platforms more easily.

We asked Neil to explain how he moved over to using SDL for his games, as Convey was originally written in BASIC and used the FastSpr library to plot graphics to the screen.

"Most of my BASIC games were always written with a view to converting them to C, so it actually only took me a few hours," explained Neil. "For example, the FastSpr routines take the x,y origin from the top left, and so does SDL. The only difference is that FastSpr defaults to plotting from the center of the image, which is quite useful sometimes. So I printed out my Convey BASIC code for easy reference and pretty much copied the code only using C functions instead of the BASIC ones.

"The main play area apart from the hoods at each end of the conveyer belt and the main character still use the same plot co-ordinates as the basic FastSpr version, and because all the collision detection is done in an array, the graphics you see on the screen are really just a representation of the game workings."

"Generally, like most of my games, Convey was a 'self improving' programming exercise. One little thing I was playing with was packing all the main
images in one file and splitting them up in the code, because keeping
all the images needed in a game as separate bitmaps in a directory could
get very silly."

One problem that Neil faced was the methods required to update the screen using SDL, which is different to how you would normally go about it with BASIC and FastSpr.

"Clearing the screen and completely redrawing the frame isn't all that efficient, so everything is plotted onto what was there before. So for example, when the score changes it plots a black rectangle before updating the score, and there is another black rectangle plotted 'under' the left edge of the belt to cover up where the character jumps into the black background. If there was a graphical background you'd have to grab the piece of background before anything moves into it and put it back after, so having a black background is a bit of a slack out."

The source code to the SDL games are also available for download, if you're feeling nosey. The Conveysdl also uses the same original data files that the BASIC version used. Neil, who also approved of Alan Buckley's SDL port of xrick, hopes to eventually cross-compile his games on his Linux PC, for speed reasons.


SDL library website

Previous: Midlands show ready for December
Next: Middleton: 'Select 32' due 2005


Viewing threaded comments | View comments unthreaded, listed by date | Skip to the end

Very useful, anything that puts RISC OS on a more even standing with other OSes is another step towards victory.

All these porting tools working both ways make RISC OS better as a place to develop, as well as a place to use the programs developed elsewhere.

When programming with FastSpr it suggests you redraw the whole screen every time, is the problem with SDL just that it's too slow for this?

 is a RISC OS Usermavhc on 10/10/04 2:49AM
[ Reply | Permalink | Report ]

fastspr has it's own screen bank routine, and is very fast anyway, so there is no real need to be tight about what where and when you draw, SDL windowed on a StrongARM is just about bareable as long as you are carefull what you redraw, using SDL_Flip(screen); ( updating the entire visible area ) can slow things down alot, and it is good practise only to update the screen where and when neccesary anyway. but.. SDL_Flip does not wipe everything then redraw it, which is what the FstSpr stuff does, you would have to draw a big rectangle to acheive this if it were neccesary. as conveysdl isn't exactly proccesor stretching and a large percentage of the screen is changed each frame, it just uses SDL_Flip, tho in some other progects i am working on, i am only updating the rectangles of the screen that have changed. which messes with my head a bit.

 is a RISC OS Usernex on 17/10/04 10:52AM
[ Reply | Permalink | Report ]

Please login before posting a comment. Use the form on the right to do so or create a free account.

Search the archives

Today's featured article

  • Wakefield 2006 show report
    All the thrills and spills from the weekend [Updated]
     90 comments, latest by bucksboy on 23/05/06 5:57PM. Published: 15 May 2006

  • Random article

  • RISC OS in Japan
    Who, where, what, when, how?
     13 comments, latest by Sawadee on 14/4/05 10:01PM. Published: 4 Apr 2005

  • Useful links

    News and media:

    Top developers:
    RISCOS LtdRISC OS OpenMW SoftwareR-CompAdvantage SixVirtualAcorn

    CJE MicrosAPDLCastlea4X-AmpleLiquid SiliconWebmonster


    RISCOS.org.ukRISCOS.orgRISCOS.infoFilebaseChris Why's Acorn/RISC OS collectionNetSurf

    Non-RISC OS:
    The RegisterThe InquirerApple InsiderBBC NewsSky NewsGoogle Newsxkcddiodesign

    © 1999-2009 The Drobe Team. Some rights reserved, click here for more information
    Powered by MiniDrobeCMS, based on J4U | Statistics
    "You are just users, irresponsible and overly sarcastic"
    Page generated in 0.0783 seconds.