mlepage
Posts: 89
Joined: Tue Jun 12, 2012 1:58 am

SDL 2.0 on Pi?

Sat Jul 28, 2012 1:29 am

Is anyone going to be porting SDL 2.0 to Raspberry Pi?

It's near release, as the developers are basically only fixing release critical bugs now, so it would be a perfect time to get started.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: SDL 2.0 on Pi?

Sat Jul 28, 2012 1:43 am

Can you tell us what sorts of advantages it would bring?

All I know about SDL is that it is used for DosBox and for QEMU. What else does it do?
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

portets
Posts: 186
Joined: Sat Oct 29, 2011 6:24 am

Re: SDL 2.0 on Pi?

Sat Jul 28, 2012 2:45 am

It's used in almost every major open source game project to provide an easy way for programmers to display 2d and 3d video, audio, input handling, loading of images/fonts.

SDL 2.0 brings easy to use hardware accelerated rendering of 2d material, which was more complicated before. I've heard SDL 2.0 is faster in a lot of other ways too, with many, many other various improvements. It also features better input handling and a unified force-feedback API.

I'm sure I'm missing a lot of new features here. ;)

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: SDL 2.0 on Pi?

Sat Jul 28, 2012 2:49 am

Sounds good.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

JPDefault
Posts: 30
Joined: Mon Jul 30, 2012 8:12 am
Location: Wiltshire

Re: SDL 2.0 on Pi?

Sun Aug 05, 2012 10:57 pm

Hiya!
SDL 2.0 compiles on Raspbian with minimal modifications, I tried it a few days ago (took about 2-3 hours to compile).
The problem is that your SDL 1.2 applications will run slower on 2.0 unless you rewrite them using the new features (e.g. use SDL_Texture instead of SDL_Surface).

User avatar
crazysam
Posts: 2
Joined: Sun Sep 23, 2012 9:03 am
Location: Baltimore, MD
Contact: Website

Re: SDL 2.0 on Pi?

Mon Sep 24, 2012 6:44 am

Isn't pygame essentially an interface for SDL?
That means someone has some sweet binaries that they're not sharing :-P

ghans
Posts: 7388
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: SDL 2.0 on Pi?

Mon Sep 24, 2012 8:17 am

Is is SDL usable without hardware acceleration on the Pi ? This was a problem
for many people who ported apps , which itself are potable because of
SDL.


ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
gordon@drogon.net
Posts: 1970
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: SDL 2.0 on Pi?

Tue Sep 25, 2012 12:08 pm

ghans wrote:Is is SDL usable without hardware acceleration on the Pi ? This was a problem
for many people who ported apps , which itself are potable because of
SDL.


ghans
SDL is very usable on the Pi, but the standard interfaces aren't acellerated. However for my application, it ported by me simply typing 'make' and worked right away. Yes, it's a little slower than on my desktop, but tht's mostly due to the ARM processor being slower - my application is poking pixels for the most part - although the sprite handler would benefit from some sort of hardwar "blitter" type acelleration as done on some of the early 2D graphics cards...

-Gordon
--
Gordons projects: https://projects.drogon.net/

jethrogb
Posts: 7
Joined: Mon Oct 15, 2012 12:49 am

Re: SDL 2.0 on Pi?

Mon Oct 15, 2012 1:02 am

I've got SDL 2.0 working with hardware acceleration without X. "patch" at http://jbeekman.nl/pub/sdl2_video_rpi.tbz . This is mostly the pandora code with modifications to make it work on the RPi. This is a huge hack, but it works. Events don't work, I'm not sure if I will be implementing those.

Besides SDL dependencies, you might also want to apt-get install mercurial build-essential .

To download, configure, build and install SDL:

Code: Select all

hg clone http://hg.libsdl.org/SDL
cd SDL
./autogen.sh
wget http://jbeekman.nl/pub/sdl2_video_rpi.tbz
tar xvjf sdl2_video_rpi.tbz
mkdir build
cd build
export CFLAGS="-I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads"
export LDFLAGS="-L/opt/vc/lib/"
../configure --prefix=`pwd`/install --without-x --disable-video-x11 --disable-x11-shared --disable-video-x11-xcursor --disable-video-x11-xinerama --disable-video-x11-xinput --disable-video-x11-xrandr --disable-video-x11-scrnsaver --disable-video-x11-xshape --disable-video-x11-vm --disable-video-opengl --disable-video-directfb --enable-video-opengles --enable-video-dummy
make
make install
# The binaries and includes are now located in SDL/build/install
SDL_image:

Code: Select all

hg clone http://hg.libsdl.org/SDL_image
cd SDL_image
./autogen.sh
mkdir build
cd build
../configure --prefix=`pwd`/../../SDL/build/install
make
make install
# The binaries and includes are now located in SDL/build/install
SDL_ttf (does not have hardware accelerated drawing):

Code: Select all

hg clone http://hg.libsdl.org/SDL_ttf
cd SDL_ttf
./autogen.sh
mkdir build
cd build
../configure --prefix=`pwd`/../../SDL/build/install --without-x
make
make install
# The binaries and includes are now located in SDL/build/install
You can change the prefix to /usr/local if you want to pollute your system. If you don't, it's probably easier to link statically.

Vanfanel
Posts: 409
Joined: Sat Aug 18, 2012 5:58 pm

Re: SDL 2.0 on Pi?

Mon Oct 15, 2012 3:29 pm

Awesome work, jethrogb!!
Accelerated X-less SDL is probably the best thing that could happen to the Raspberry Pi.

But I have some questions:

-If events are not working, how is input supposed to work?
-What do you mean by accelerated exactly? Image scaling, blitting, both? What backend did you use in the Pi's side?

Thanks!

jethrogb
Posts: 7
Joined: Mon Oct 15, 2012 12:49 am

Re: SDL 2.0 on Pi?

Mon Oct 15, 2012 9:19 pm

Re: the events, assuming you are running this from a terminal, you can still use the terminal for input however you see fit. For example:

Code: Select all

#include <unistd.h>
#include <termios.h>
#include <fcntl.h>

int main ()
{
    struct termios old_terminal_settings, new_terminal_settings;

    //Disable line buffering, read STDIN char by char
    tcgetattr(0, &old_terminal_settings);
    memcpy(&new_terminal_settings, &old_terminal_settings, sizeof(struct termios));
    new_terminal_settings.c_lflag &= ~(ICANON|ECHO);
    new_terminal_settings.c_cc[VTIME] = 0;
    new_terminal_settings.c_cc[VMIN] = 1;
    tcsetattr(0, TCSANOW, &new_terminal_settings);
    fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK);

    //SDL init here

    while (!feof(stdin))
    {
        char ch;
        
        //SDL main loop here

        if (EOF!=(ch=getchar()))
        {
            //interpret ch here
        }
        else
        {
            //should check for errno==EAGAIN here, other errors might indicate real EOF
        }
    }

    tcsetattr(0, TCSANOW, &old_terminal_settings);

    //SDL finish here

    return 0;
}
It should also be possible to interpret mouse input from the terminal, but I'm not sure how. I think ncurses can do this (edit: yes, with gpm). Of course, this means you can't port existing software easily, but hey, it's a start.

Re: the acceleration. See http://www.raspberrypi.org/phpBB3/viewt ... 12#p148212 for SDL 2.0 HW acceleration features. SDL 2 supports OpenGL ES 2.0 for rendering out of the box. You turn surfaces into textures and render those (like blitting), see SDL 2.0 MigrationGuide and SDL_RenderCopyEx. There are other hardware accelerated functions, see SDL Wiki Category Render.

Edit: wow, links are invisible in this theme. Underlined for your convenience.

Vortex code
Posts: 4
Joined: Sun Jul 07, 2013 1:33 pm

Re: SDL 2.0 on Pi?

Thu Aug 15, 2013 4:38 pm

I have created a video and posted it on youtube showing how to download and setup SDL 2.0 for the raspberry pi on youtube.

Here is the link and please subscribe and share!

http://youtu.be/Yo7hO7GZ-ug :D :ugeek:

bloodline
Posts: 76
Joined: Sun Jun 10, 2012 8:44 pm
Location: London - England

Re: SDL 2.0 on Pi?

Tue Aug 27, 2013 5:02 pm

jethrogb wrote:I've got SDL 2.0 working with hardware acceleration without X. "patch" at http://jbeekman.nl/pub/sdl2_video_rpi.tbz . This is mostly the pandora code with modifications to make it work on the RPi. This is a huge hack, but it works. Events don't work, I'm not sure if I will be implementing those.
Thanks to your post, I can build SDL2.0 apps now, but I'm getting intriguing graphics corruption.

All SDL_RenderDraw* functions show the console framebuffer through... not sure if I'm doing something wrong here?

-Edit it seems as though there is some kind of blend mode active with the console frame buffer... I have tried to change it but to no avail.

bloodline
Posts: 76
Joined: Sun Jun 10, 2012 8:44 pm
Location: London - England

Re: SDL 2.0 on Pi?

Tue Aug 27, 2013 6:14 pm

Ok, The blending modes seem to be messed up (or I don't under stand them properly).

To stop the Console/X11 framebuffer showing through you need to set this:

Code: Select all

SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
Where renderer is the pointer to your renderer...

I'm now experimenting with the Texture blending modes to see what works correctly with these...

bloodline
Posts: 76
Joined: Sun Jun 10, 2012 8:44 pm
Location: London - England

Re: SDL 2.0 on Pi?

Thu Aug 29, 2013 8:56 am

The texture blend mode also needs to be set to blend, if you don't set the blend mode or set it to none, the console/X11 frame buffer shows through.

Also, I am only able to get 40fps (with very occasional little jumps up to my monitor's refresh rate) and this is with VSync on. Which looks jerky, not fluid at all :(

-Edit- Turning VSync off gets me 46 FPS... My monitor refresh is 60Hz so it really doesn't look nice :(

User avatar
jwzumwalt
Posts: 44
Joined: Sun Aug 04, 2013 4:00 pm

Re: SDL 2.0 on Pi?

Sat Sep 28, 2013 6:07 am

I just successfully got SDL2 up and running.
My instructions are located at http://www.raspberrypi.org/phpBB3/viewt ... 91&t=56756

Return to “Graphics programming”

Who is online

Users browsing this forum: No registered users and 2 guests