SDL

Anything and everything about programming graphics with Ultibo
Gavinmc42
Posts: 1665
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

SDL

Postby Gavinmc42 » Sat Sep 23, 2017 12:58 am

I opened my mouth and said Basic could run on Ultibo :o
https://www.raspberrypi.org/forums/view ... 8#p1214208

Well someone pointed to SpecBasic which is written in Pascal :D
But it uses OpenGL and SDL for graphics.

SDL is a library, could it be ported like the VC4 stuff?
https://www.libsdl.org/download-2.0.php

If SDL works then lots of graphics stuff could be ported to Ultibo.
Where is the source for SDL on Pi's?
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: SDL

Postby pjde » Sat Sep 23, 2017 5:01 am

SDL2 should be very possible. It can be compiled using OpenGL and does not need X11.

SDL1 is not license friendly towards static linking but SDL2 is ok. Probably the hardest part would be interfacing to the mouse and keyboard.

Regards

Paul
Gavinmc42
Posts: 1665
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: SDL

Postby Gavinmc42 » Sat Sep 23, 2017 5:55 am

There looks like there is an OpenGL ES2 version and simpler audio for Android and embedded.
Have not looked at the mouse, keyboard yet.

Wonder if Dispmanx would help?
This middle level stuff is new to me, i'm googling like mad :lol:

Getting ambitious too :lol: but thats another post :D
https://bitbucket.org/chromiumembedded/cef
http://wiki.freepascal.org/fpCEF3
pik33
Posts: 891
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: SDL

Postby pik33 » Sat Sep 23, 2017 6:12 am

The chromium embedded has to be tested here :)

About SDL: we don't have to have a full SDL to do what we want. I used SDL as a pattern when writing SimpleAudio module, but then I added some functions which are not in SDL, but they are simpler. Having SDL type audio functions allowed me to simply add module player and mp3 player basing on SDL examples.

Now having an HDMI audio example I will add HDMI audio to the unit, so I will get not only jack, but HDMI audio too.

Having VC4 libraries implemented we can also add video functions modelled after SDL.

Adding the keyboard and mouse function based on SDL is now easy as my retromachine/GUI stuff uses low level keyboard and mouse access, so I know how to do this.

One important stuff which is not implemented yet is USB joystick.

So the conclusion is: we need joystick driver. Then we can write a mini-sdl library which then will allow easy porting SDL based stuff to Ultibo.
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: SDL

Postby pjde » Sat Sep 23, 2017 7:05 am

As joysticks are essentially HID devices, the standard 2 axis style should be relatively easy to implement.

The word there of course is "should".
Gavinmc42
Posts: 1665
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: SDL

Postby Gavinmc42 » Sun Sep 24, 2017 2:47 am

pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: SDL

Postby pjde » Sun Sep 24, 2017 4:18 am

There a number of pascal units available that provide the api headers for SDL2.

The biggest challenge is to compile the SDL2 source code in a Ultibo friendly manner.

The last project I was working on using Lazarus/FPC on Rasbian was a SDL2 based kiosk. The header files I used could be easily modified for static binding.

Regards

Paul
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: SDL

Postby pjde » Sat Oct 07, 2017 12:32 am

Hi All

I have been investigating importing SDL2 into Ultibo but am getting stuck at the beginning so any help is appreciated.

I have :-
Downloaded the source for SDL2 and extracted it.
Created a batch file to initially compile just the base objects including SDL.c in the src folder and generate an archive file

Code: Select all

echo Compiling SDL
set CC=arm-none-eabi-gcc
set AR=arm-none-eabi-ar
set CFLAGS=-O2 -mabi=aapcs -marm -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard -Iinclude -fno-short-enums -D__DYNAMIC_REENT__
echo Source ...
%CC% %CFLAGS% -c src/*.c
echo Creating SDL archives
%AR% rcs ..\libsdl2.a *.o


This does not generate any errors and produces a SDL.o (and others) as well as libsdl2.a in the appropriate project folder.

In my Lazurus unit I have defined the two init functions which are defined in sdl.h in the src folder.

Code: Select all

{$linklib libSDL2}
function SDL_Init (flags: LongWord): integer; cdecl; external 'libSDL2' name 'SDL_Init';
function SDL_InitSubSystem (flags : LongWord): integer; cdecl; external 'libSDL2' name 'SDL_InitSubSystem';


and in the initialisation section call the two functions so that the FPC has to actually link to them.

Code: Select all

initialization
SDL_Init (0);
SDL_InitSubSystem (0);


but when I try to build the project (Target Processor ARMV7A Target Controller PI3B) I get :-

Compile Project, OS: ultibo, CPU: arm, Target: SDL2: Exit code 1, Errors: 1
C:\Ultibo\Projects\SDL2\lib\arm-ultibo\uSDL2.o: In function `USDL2_$$_init':
uSDL2.pas:(.text.n_usdl2_$$_init+0x8): undefined reference to `SDL_Init'
uSDL2.pas:(.text.n_usdl2_$$_init+0x10): undefined reference to `SDL_InitSubSystem'
SDL2.lpr(27,0) Error: Error while linking


Hopefully it is something simple.

Regards

Paul
User avatar
Ultibo
Site Admin
Posts: 2303
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: SDL

Postby Ultibo » Sun Oct 08, 2017 11:55 pm

pjde wrote:but when I try to build the project (Target Processor ARMV7A Target Controller PI3B) I get :-

uSDL2.pas:(.text.n_usdl2_$$_init+0x8): undefined reference to `SDL_Init'
uSDL2.pas:(.text.n_usdl2_$$_init+0x10): undefined reference to `SDL_InitSubSystem'


I copied your steps and then did the following with libsdl2.a to see what is included in it:

Code: Select all

arm-none-eabi-objdump -d libsdl2.a > libsdl2.list

This gives a text listing of the disassembled contents of libsdl2.a and from that I can see that the functions you are wanting end up as follows:

Code: Select all

00000014 <SDL_InitSubSystem_REAL>:
0000164 <SDL_Init_REAL>:

In fact all of the functions have the suffix _REAL added to them.

After a really quick look it seems that SDL.c includes SDL_internal.h which includes SDL_dynapi.h which enables SDL_DYNAMIC_API if not otherwise disabled.

The enabling of SDL_DYNAMIC_API causes SDL_internal.h to include SDL_dynapi_overrides.h which then redefines all of the function names to have _REAL on the end.

I would suggest trying to use the proper build process in order to get this working rather than going with a simple batch file, it looks like SDL can be built using CMake and that is one of the easier tools to configure for our purpose (as opposed to configure scripts which are often used).

We have produced a couple of CMake configuration files which we will do a post about sometime but they are also included in the Userland libraries port, you can find our additions under the makefiles and toolchains folders. The buildme.armv?-ultibo shell scripts pass the needed parameters to CMake to allow detecting the Ultibo target during the build.

Doing it this way takes longer to get started but pays off once you get it working because you spend far less time messing with C compiler configuration and wondering why you get weird error messages that don't happen in the official builds. Just looking at the CMakeLists.txt file there are a huge number of options and parameters that can be configured in order to customize the build process.
Ultibo.org | Make something amazing
https://ultibo.org
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: SDL

Postby pjde » Mon Oct 09, 2017 3:21 am

Thanks Garry

I was trying to avoid having to work out how cmake works but I will try it.

Regards

Paul

Return to “Graphics”

Who is online

Users browsing this forum: No registered users and 36 guests