SDL Tutorials

Here you can talk about anything related to BBC BASIC, not covered in another category
JWB
Posts: 10
Joined: Mon 16 Jan 2023, 09:41

SDL Tutorials

Post by JWB »

Hi, are there any SDL tutorials specifically for BBC Basic SDL ?
I've found a couple that appear to explain SDL well,
but unfortunately they are using C and C++ as examples, which makes them hard for me to follow.

I tried to follow the BBC Basic SDL examples provided (which are amazingly good),
but I feel over-whelmed trying to understand them, without first doing a good tutorial.
I've got plenty of information on BBC Basic itself, but using it coupled with SDL is what I'm lacking.

Much appreciated.
Hated Moron

Re: SDL Tutorials

Post by Hated Moron »

JWB wrote: Thu 26 Jan 2023, 04:32 I've found a couple that appear to explain SDL well, but unfortunately they are using C and C++ as examples, which makes them hard for me to follow.
If you could provide a link to one of those tutorials I would certainly consider creating a version in which the C or C++ code is translated into BBC BASIC, if it's not too huge (if it is big perhaps you could identify which sections are of particular interest). I did something similar with a Direct3D 11 tutorial some years ago.
I've got plenty of information on BBC Basic itself, but using it coupled with SDL is what I'm lacking.
The intention is that, as far as possible, you are isolated from the low-level complexity of the SDL2 API by means of supplied BBC BASIC libraries. So for example the graphics capabilities of SDL2 are exposed by the gfxlib, aagfxlib and imglib libraries, the audio capabilities by the audiolib library and the networking capabilities (of SDL2_net) by the socklib library.

So it would be helpful to know what kinds of things you might want to do that would require direct access to SDL2.
JWB
Posts: 10
Joined: Mon 16 Jan 2023, 09:41

Re: SDL Tutorials

Post by JWB »

Thanks for your reply and offer to look into this - very much appreciated.

A couple of example sites for learning SDL (but with C, C++) are:-
https://www.youtube.com/playlist?list=P ... pU-n_2eyNt <<-- this is a whole series on SDL Made Easy (well so it says anyway)
http://lazyfoo.net/tutorials/SDL/

My aim is to be able to fully understand say, the Lotto example, or the game AlienEliminator.
Don't I need to interface BBC Basic with SDL ?

Looking forward to your reply.

Justin
Hated Moron

Re: SDL Tutorials

Post by Hated Moron »

JWB wrote: Thu 26 Jan 2023, 09:53 http://lazyfoo.net/tutorials/SDL/
I'm familiar with the LazyFoo tutorial. The great majority of the topics it covers are handled by the existing BBC BASIC libraries and would not require direct access to the SDL2 API. There are bound to be a few where that is not the case, so if there's anything you want to do which you cannot find in the libraries let me know.
My aim is to be able to fully understand say, the Lotto example, or the game AlienEliminator.
Don't I need to interface BBC Basic with SDL ?
For Lotto, no; it uses only the supplied BBC BASIC libraries. Indeed Lotto isn't even specific to BBC BASIC for SDL 2.0, it will run in BBC BASIC for Windows too, which is one of the benefits of using libraries (not all the libraries have direct equivalents in both BBCSDL and BB4W, but the ones used by Lotto do).

In the case of Alien Eliminator it does use a lot of direct calls to the SDL2 API. But the reason for that is largely because it was translated from David Williams's original before the gfxlib library was written; I wouldn't do it that way now. Although it's on a much smaller scale, cowboy.bbc (in examples/games) was originally written by David to illustrate the main techniques used in writing 2D (non-scrolling) games.

One of the reasons for calling SDL2 API functions directly is, of course, speed; they will always be a little faster than calling a library 'wrapper'. But I've tried to address that issue in gfxlib by suggesting that if you want the best possible performance you can always copy-and-paste the body of a library routine into your own program. This is what it says in gfxlib_docs.pdf:

"Although the library routines may be called in-situ, the overhead of the procedure calls and the saving of LOCAL variables, creation of LOCAL structures etc. may be significant in critical applications. In that event transfer the contents of the library routines into your program inline, and relocate the structure declarations, LOCAL statements etc. to the parent procedure."
JWB
Posts: 10
Joined: Mon 16 Jan 2023, 09:41

Re: SDL Tutorials

Post by JWB »

Thank you very much for your comprehensive reply.
This clears it up for me - now just a matter of a learning curve.
Hated Moron

Re: SDL Tutorials

Post by Hated Moron »

I received an email from (I think) a member of this forum, to which I replied in detail. However their email provider rejected my reply, saying: "This message does not pass authentication checks (SPF and DKIM both do not pass). SPF check for [rtrussell.co.uk] does not pass with ip: [77.92.64.161]. To best protect our users from spam, the message has been blocked".

I would suggest that a forum post (or a Private Message if it's not for general consumption) might be a better choice of communication than email.
JWB
Posts: 10
Joined: Mon 16 Jan 2023, 09:41

Re: SDL Tutorials

Post by JWB »

Can you please point me to where I can get a manual or some guidance about the BBC Libraries,
to help me understand the Examples.

After much online searching, all I could find was:-
http://www.petesqbsite.com/sections/exp ... ib015b.txt
"gfxlib - A 2D Game Graphics Library for BBCSDL".
But it doesn't seem to have everything I saw, in say, the Lotto game.

Thanks
Hated Moron

Re: SDL Tutorials

Post by Hated Moron »

JWB wrote: Mon 30 Jan 2023, 00:08 Can you please point me to where I can get a manual or some guidance about the BBC Libraries,
to help me understand the Examples.
The principal BBCSDL libraries are, of course, documented in the Help manual, what couldn't you find there?
But it doesn't seem to have everything I saw, in say, the Lotto game.
Lotto, and the other programs using the Box2D physics engine, are something of a special case because the associated libraries (box2dlib.bbc, box2dgfx.bbc and box2ddbg.bbc) are not documented in the Help manual. This is because the complexity of Box2D is such that the manual couldn't do it justice.

Perhaps the other members who have written Box2D-based programs (e.g. DDRM, Svein) could say where they found the information they needed.
JWB
Posts: 10
Joined: Mon 16 Jan 2023, 09:41

Re: SDL Tutorials

Post by JWB »

Thanks for your reply.
Maybe I just don't know how to go about finding things in the Help Manual.
You asked me what couldn't I find there.
Well, just as only one example, how to find say, "gfxMultiply" ?

I'm glad you explained the box2d libs are not documented or I'd be wondering why I can't find those either.

Cheers
Justin
Hated Moron

Re: SDL Tutorials

Post by Hated Moron »

JWB wrote: Mon 30 Jan 2023, 10:28 Well, just as only one example, how to find say, "gfxMultiply" ?
There is no such function in BBCSDL or any of its libraries, it doesn't exist! If you have seen references to PROC_gfxMultiply they will have been in a context such as this:

Code: Select all

      IF INKEY$(-256) = "W" PROC_gfxMultiply(...)
As you can see, the call to PROC_gfxMultiply is conditional on it running in BBC BASIC for Windows, not BBC BASIC for SDL 2.0. ;)

If you are interested, the reason the procedure exists at all is because Windows, in general, uses pre-multiplied images, whereas SDL2 doesn't. So to make the program compatible, it is necessary to pre-multiply the image with its alpha channel in BB4W, but not in BBCSDL.