SDL Community Project

BlitzMax Forums/BlitzMax Programming/SDL Community Project

Robert Cummings(Posted 2005) [#1]
Dear community,

SDL's renderer represents the opportunity to take Blitzmax to the next level with robust software fallback. While there isn't scale and rotation, it gives you the power to support win, linux and mac cards which either have bad drivers or no 3D capability - and they are far more common than you might think!

To this end, I am proposing this thread be made sticky and we work together to create a definitive max 2D rendering solution. Lets get started!

The libs - precompiled is most convenient and no GPL issues but modules also welcome:

windows:
http://www.libsdl.org/release/SDL-1.2.8-win32.zip

linux:
http://www.libsdl.org/release/SDL-1.2.8-1.i386.rpm

mac:
http://www.libsdl.org/release/SDL-1.2.8.pkg.tar.gz

source in c:
http://www.libsdl.org/download-1.2.php

Please note these are all precompiled which is easier (unless someone wants to make a mod! Some brave soul...) And we are going for a windows version first.

Docs:
http://www.libsdl.org/cgi/docwiki.cgi/

Homepage:
http://www.libsdl.org/

Source code so far:

Contributed by noel cower (this is a very limited bit of source that just shows us some of the keywords, types and constants - perhaps it will help us get started:


And here's some alternative code - linking to a DLL but I don't know where to go from here as there isn't much documentation on this (thanks to Sarge on IRC):
global lib = LoadLibraryA("SDL.dll")
Extern...
End Extern...


The goal is to do all the software rendering externs and calls so we can with ease, fall back to SDL software rendering (bmax provides the hardware rendering).

To this end we might need SDL's mouse handling if it has it, and the rect class as it's animated surfaces require that.

I look forwards to your replies and any help you can give towards this open source blitzmax project. I will share everything I learn from it with you all, so all may benefit. Lets grow blitzmax beyond by working as a team!

Your contributions are valued and greatly appreciated.


Mr. Write Errors Man(Posted 2005) [#2]
Software fallback is a great idea.

I wonder, though, if it would be easier to just go DirectDraw under DirectX7?


N(Posted 2005) [#3]
I wonder, though, if it would be easier to just go DirectDraw under DirectX7?


It wouldn't.


Sarge(Posted 2005) [#4]
This is the SDL_cpuinfo file, i will do some more later.
Extern "win32"

	'SDL_cpuinfo
	Function SDL_HasMMX() = "SDL_HasMMX"
	Function SDL_HasRDTSC() = "SDL_HasRDTSC"
	Function SDL_HasMMXExt() = "SDL_HasMMXExt"
	Function SDL_Has3DNow() = "SDL_Has3DNow"
	Function SDL_Has3DNowExt() = "SDL_Has3DNowExt"
	Function SDL_HasSSE() = "SDL_HasSSE"
	Function SDL_HasSSE2() = "SDL_HasSSE2"
	Function SDL_HasAltiVec() = "SDL_HasAltiVec"

End Extern



TartanTangerine (was Indiepath)(Posted 2005) [#5]
This would be great, not sure If I have the skills to help but I'll give you 100% support.


Robert Cummings(Posted 2005) [#6]
New update from James L Boyd!
To easily call DLL's from Blitzmax under windows we can go...
' Load relevant DLLs...

 user32 = LoadLibraryA ("user32.dll")

' Check they loaded...

 If user32 = 0 Then Print "Failed to open user32.dll"; End

' Create Blitz function prototypes (to match Win32 API parameters)...

 Global Info (window, message$z, title$z, flags) "win32"

' Point Blitz functions to DLL functions...

 Info = GetProcAddress (user32, "MessageBoxA")

' Call user32's MessageBox...

 Info 0, "Hello world!", "Amazing...", 0


BIG thanks to James for pointing this out. All we need to do now is take a really close look at the SDL functions and maybe find out if any need callbacks.

For Linux and Mac, there's also precompiled files for SDL, but we don't yet know how they will talk to Blitzmax.

Things for us to find out:
* list of SDL calls and parameters for DLL calling
* how callbacks work with DLLs
* how precompiled SDL works with Mac (.pax?) and Linux (see files above)

Keep it coming, folks!


Sarge(Posted 2005) [#7]
Remember on mirc,
Global Libary=LoadLibraryA( "SDL.dll" )
Global SDL_HasMMX()"win32"=getprocaddress(Libary,"SDL_HasMMX")

Print SDL_HasMMX() 



N(Posted 2005) [#8]
Looks like my b spawn of a module is going somewhere.


Robert Cummings(Posted 2005) [#9]
Please edit for swearing. Thanks so far for everyone's contribution - keep it coming, and only post if you have something constructive to say :)


Suco-X(Posted 2005) [#10]
Hi
The code on your first post dont work, Fish. Many Duplicate Identifiers.
I think itīs better to go step by step and i have created one sample.

- You need the "Win32 Development Libraries" (SDL-devel-1.2.8-mingw32.tar.gz (Mingw32))
from http://www.libsdl.org/download-1.2.php .

-Put the "libSDL.dll.a" file in your BlitzMax Lib dir.

Now you can run my code.




Itīs a bit hard to work without CStructs.
First, small sample. Hope i can help
Mfg Suco


Robert Cummings(Posted 2005) [#11]
Many, many thanks Suco-X! this is amazingly well done! I must commend you on the excellent and thoughtful contribution, thank you :)

I will examine your code - you are actually using the .a file so this is very interesting! It looks like we can expand this example to cover the entire command set for SDL windows. Do you think this will work cross platform?

Once again, thank you for the wonderful contribution.


Suco-X(Posted 2005) [#12]
No Problem, Fish.
Ok, next Version. This sample show you how you can load Surface from Pixmaps and i have some more functions added.
The Image:
Rename to "asteroid1.png"

Sample:





This code is very alpha but it works without errors(I Hope ;) )

And yes, it works cross platform.
Mfg Suco


Suco-X(Posted 2005) [#13]
Hi
Next Update, all SDL functions and 2 helper functions.





Robert Cummings(Posted 2005) [#14]
I'm at work at the moment but when I return, I will immediately dive in and try this wonderful module out :)

Good man! I can't believe you've done this in full. You have my utmost gratitude on behalf of the entire Blitzmax community! Thank you :)

You have single-handedly solved all the SDL problems for mac, win and linux - now anyone can make blitzmax games with 100% reliability regardless of target hardware...

Thats the gift you've given us :)

Finally, I move to ask BRL if they will make SDL module an official part of the Blitzmax modules.


Stuart Morgan(Posted 2005) [#15]
Finally, I move to ask BRL if they will make SDL module an official part of the Blitzmax modules.

I second this request.

Good work to everyone who worked on this btw :)


Suco-X(Posted 2005) [#16]
Hi
I have created a small Gametest with SDL. Please test with Win/Mac/Linux.

http://www.sucox.art-fx.org/BlitzPastingv2/uploads/useruploads/rSsjR131877_7005760.zip

(code+exe)
Mfg Suco


Dreamora(Posted 2005) [#17]
Making it an official part has some probs ... for example they can not include the library itself ... and a module that does not work after downloaded until you download other things isn't that good.

Suco: works with XP SP2 no prob with any part :-)


Beaker(Posted 2005) [#18]
Suco-X - try and use <codebox> instead of <code>. I've edited your posts to use codebox instead.


Robert Cummings(Posted 2005) [#19]
Sucro-X
I downloaded the demo and it did not work at first, but I added the SDL.DLL and then it worked PERFECTLY! very smooth - great test!

I imagine that for Mac and linux we need to include the relevent runtimes for each os?


Dreamora(Posted 2005) [#20]
fish: Yepp but official modules for BM are for syncmod. But for SDL you need the sdl.dll or whatever which are
1. not plattform indipendent
2. can not be included due to their license

This makes them useless as official BM mod.

And no you don't need to include. you need to link to the sdl page as you are not allowed to include it without special permission


boomboommax(Posted 2005) [#21]
windowed mode fails to draw anything or even seem to flip


Robert Cummings(Posted 2005) [#22]
Cyanide, how do you invoke windowed mode? Can you post code?


Dreamora(Posted 2005) [#23]
Its great work so I don't want to spoil it to anyone.
I just want to prevent a "please make it official" hype which would cost many nerves at BRL just for nothing because some people don't read licenses of stuff they use.


boomboommax(Posted 2005) [#24]
TLibSDL.Graphics(800,600,32,false) (last flag, true for fullscreen)

edit: thou sdl does the same for me in c++ with windowed mode, so probally my intel pos


BlitzSupport(Posted 2005) [#25]
Barely informed rambling -- feel free to correct!

If you Google around to try and clarify the SDL/LGPL requirements, you'll find there's a lot of confusion (eg. http://www.gamedev.net/community/forums/topic.asp?topic_id=301120&whichpage=1 ), but mostly the debates seem to eventually agree that you basically have to a) distribute the unchanged .dll and LGPL licence with your game, b) make clear reference to the LGPL and c) provide a link to download the SDL source code on your own site. (DISCLAIMER: not legal advice!)

Sami Lantingen is the author of SDL, and his thoughts are here:
http://www.devolution.com/pipermail/sdl/2000-August/029476.html

Only thing is, the current conversion by Suco-X (very nice work!) seems to link statically as far as I can tell, ie. it imports sdl.a (which I think may import other .a libs in turn?), though it still requires the DLL. Maybe I don't fully understand static vs dynamic linking yet, but I'd have thought that using static .a linking wouldn't require the DLL (?).

As far as I can tell, you'd have to be linking dynamically (ie. using only the DLL) to fit these conditions. Linking statically means you have to distribute the source or object code to your own programs, as the library is effectively embedded in your program, as opposed to being a separate .dll file. Linking dynamically would mean doing similar to what Sarge suggests for each function...


Robert Cummings(Posted 2005) [#26]
I'm gonna go with what the author says - include the runtime and a nice little text doc.

The rest can get stuffed because it's not strictly statically linking as the DLL is still required. We are also making no changes to the original source. So, for me, DLL and text doc :)


DStastny(Posted 2005) [#27]
James,

When linking to DLL there are two ways to do this. Static Linking or Dynamic Linking.

Static Linking is done by creating an import lib from the DLL and linking to that. ie libXXX.a for mingw. The "XXX.dll" is still loaded at runtime but the linker resolving the references via libXXX.a

Dynamic Linking is of the form

Lib=LoadLibary("xxx.dll")
func=GetProcAddress(lib,"Foo")

Either way can be used for DLLs however personally although more work Dynamic is better since if the DLL is not on the machine you can programtically error out vs implict your program just crashes saying it cant find some dependent file. Another benfit to Dynamic Linking is if you dont have the libXXXX.a file you can still use the DLL as long as you know the name and paramters of the entry points.

Hope this helps understand DLLs and different forms of linking

Doug Stastny


BlitzSupport(Posted 2005) [#28]
Thanks Budman. I know the very basics, but the below is something I wondered about (just because I know that in some cases the .a being linked into the executable is all that's needed, and so assumed that was always the case):


Static Linking is done by creating an import lib from the DLL and linking to that. ie libXXX.a for mingw. The "XXX.dll" is still loaded at runtime but the linker resolving the references via libXXX.a



... so knowing this as well is very helpful, thanks.


Mr. Write Errors Man(Posted 2005) [#29]
This is totally awesome!


Robert Cummings(Posted 2005) [#30]
Indeed. I'm very proud of the community that helped made this happen, and continue to evolve it... it's not finished yet :)


ckob(Posted 2005) [#31]
now dont shoot me for asking but I thought SDL was slower then directx and opengl and that it was more or less just an opengl wrapper? am I wrong please explain


Robert Cummings(Posted 2005) [#32]
You are wrong. It has OGL, DX and Software rendering. Software rendering is why we like it.


ckob(Posted 2005) [#33]
so its a wrapper for DX and OGL?


taxlerendiosk(Posted 2005) [#34]
No, the whole point is it doesn't need either (although it can make use of them if available).


Robert Cummings(Posted 2005) [#35]
Stay tuned folkes, doing a nice demo for Blitzmax which falls back from hardware to software.

Got a problem trying to detect if hardware is present.

Use the troubleshoot tab on your windows display preferences -> advanced window to disable 3D to test.

The problem I'm having is: blitzmax throws an unhandled exception on both DX and OpenGL when not present --- nasty!

How do we work around this? Ideally Graphics() should return true or false if it worked or not.


taxlerendiosk(Posted 2005) [#36]
What's the situation with screen resolutions in SDL? Can I have really low ones like 320x200 that aren't supported by modern graphics cards, or will it still fail?


Robert Cummings(Posted 2005) [#37]
Update: we've fixed the problem with detecting if Graphics modes exist, see this thread.

SDL specific questions must be referred to http://www.libsdl.org/ as I can't answer that. But I will try - yeah most modern graphics cards do in actual fact, support really low resolutions like 320x200, however windows XP won't show much below 800x600. Some might not though.

You can always do it in a higher resolution like 640x480. I recommend you do... just draw half the size, then scale it up after. There's a version of SDL which does scaling, and you might be able to integrate it with the above code. Why not let us know how you get on?

Even better, just draw your sprites in 320x200, then pre-scale them up twice the size. It all depends if you want 320 for the "look" or if you're doing mental pixel stuff...

If I can find anything else to help you, I'll post it in this thread.


TartanTangerine (was Indiepath)(Posted 2005) [#38]
Is this now complete? ie. Can I use this with Blending modes and rotation/scaling of images?


Robert Cummings(Posted 2005) [#39]
The initial SDL doesn't support "rotozoom", you need to addon another SDL package for that. If you manage to do it, please contribute it here in respect for the good work done so far to set us off.

The link is: http://www.ferzkopp.net/~aschiffler/Software/SDL_gfx-2.0/

So if you manage it (Should be fairly simple based off the above code) please post how in this thread :)

tis only fair...


Mr. Write Errors Man(Posted 2005) [#40]
Has anyone made further work on this? I am slowly starting to get to the point in my project in which I'll start adding SDL fallback functionality. I'd hate to do unnecessary double work. :)

I think I need to (at least) add LoadAnimImage functionality and try to find a code based solution to making images with per-pixel alpha display OK with SDL. The first one should be no biggie and I hope the second can be solved simply by masking pixels that have "enough" alpha.

Has anyone looked yet into SDL_gfx 2.0?


Robert Cummings(Posted 2005) [#41]
LoadAnimImage functionality is in, but not the way you expect it to be. It uses some sort of rect mechanism to copy the desired frame from a larger image.

I would like to see it updated with LoadAnimImage too, but more importantly - has anyone got it working with the mac?

You're right - can we do alpha fading with an image with a normal mask?


TartanTangerine (was Indiepath)(Posted 2005) [#42]
What happened to this?


Robert Cummings(Posted 2005) [#43]
Well it all works but it got de-stickied for FMOD, which is why people miss it a lot. Not much mac support.


GazChap(Posted 2006) [#44]
Does this SDL module allow me to write games for the GP2X (http://www.gp2x.co.uk) in BlitzMax?


Robert Cummings(Posted 2006) [#45]
Only if gp2x supports pc or mac hardware.


Russell(Posted 2006) [#46]
<bump>

So is this complete?

Russell


Robert Cummings(Posted 2006) [#47]
Seems to be.


BeChris(Posted 2006) [#48]
As on http://www.blitzbasic.com/Community/posts.php?topic=57179

I'd like it to be seemlessly integrated as a Max2D module, i.e instead of using SDL dedicated functions to open a display and draw things on it,
it should be very cool to just issue a:

SetGfxDriver SDLMax2DDriver() and then use usual commands (Graphics, DrawLine, ...)

Has anyone began to work on this integration ?


Robert Cummings(Posted 2006) [#49]
Bump.


Robert Cummings(Posted 2006) [#50]
We need LoadAnimImage and RotoZoom, anyone? based off 1.2.9 SDL... this is new stuff :)

Current problems

How to draw offscreen, for example -1

How to draw from cells of images like LoadAnimImage

How to Rotate images


Chris C(Posted 2006) [#51]
Why not have a go at it yourself then?


ImaginaryHuman(Posted 2006) [#52]
On some systems that don't have hardware-accelerated support, their OpenGL driver, for example, will do everything in software, anyway.

What you're proposing isn't a replacement for the system that is already in place, you are proposing a different graphics library of deliberately software-based rendering.

On my ibook for example there is no hardware acceleration, the OpenGL driver is entirely in software. Max2D works totally fine. There is no need for software fallback routines.

I don't know if dx is the same.

Now, proposing 256-color indexed graphics support would be another matter and that would be useful perhaps, for doing software rendering in. Otherwise I don't see why you need to create your own software fallback.


Robert Cummings(Posted 2006) [#53]
On my ibook for example there is no hardware acceleration, the OpenGL driver is entirely in software. Max2D works totally fine. There is no need for software fallback routines.

The mac is vastly superior at its OpenGL software emulation. I regret to say the pc isn't even close in this regard.

I have tried this on the PC, on three different machines. OpenGL in software corrupts really badly before ultimately crashing. It is also garbage in visuals. It also runs at an appalling framerate. This is to be expected, but not this badly...

@Chris C, I am trying, I am also asking for help on this. All findings are shared in this thread.

Everyone can and will stand to benefit.


Robert Cummings(Posted 2006) [#54]
Does anyone have the source for the asteroid demo ?


www.sucox.art-fx.org/BlitzPastingv2/uploads/useruploads/rSsjR131877_7005760.zip

404... :(


ImaginaryHuman(Posted 2006) [#55]
Ahh, I see, I didn't realize it was so bad on the PC. Then it certainly looks like y'all have good reason to seek a software fallback.


Robert Cummings(Posted 2006) [#56]
Managed to get something going :) Will post what I have if its any good.


BeChris(Posted 2006) [#57]
Hi everybody, I just tried to create a SDL backend for Max2D, based on SDL 1.2.11 and SDL_gfx 3.0 (no dll for this last one, c files directly included).

I currently can display images scaled and rotated (thanks to SDL_gfx), also calling SetAlpha will have an effect on displayed image.

I still have a problem with rotation (as SDL_gfx always rotate according to the top left corner of the image, whereas Max2D can rotated according to whichever handle is set before) and alpha channel (which may produce garbage depending on images).

I also receive keyboard and window close events and forward them succesfully to blitzmax internal event handler.

If you want sources and try an example, go grab it at http://perso.wanadoo.fr/chrisgames/sdlmax.zip (windows only for the moment)

(press ESC or close window to stop example).

Is it worth creating a community project ?

Waiting for your comments ...


Nigel Brown(Posted 2011) [#58]
what has happened to this project?


ImaginaryHuman(Posted 2011) [#59]
Personally I don't see the point of trying to fall back to software rendering, you're basically going back like 10 years in hardware progress.

But I'm sure some people will disagree and so good luck with it.


slenkar(Posted 2011) [#60]
i agree, any non-ancient PC has a graphics card,