How To Install & Use SDL2 on Raspbian PI


22 posts
by jwzumwalt » Mon Oct 14, 2013 1:52 am
How To Install & Use SDL2 on Raspbian PI
By: Jan Zumwalt - October 15, 2013

Introduction
I have a new project that needed good 2D graphics. Even though SDL1, EGL, GLES, GLES2, VG are preloaded with the "Raspian" version of RPI that I am using, I was interested in scaling and rotation and wanted to checkout SDL2.

A google search turns up almost nothing so I found myself blazing a trail. Neither the "synaptic" or "apt-get" repositories have the SDL2 library at the time of this writing. Oddly (at least for Raspbian) there does not seem to be any issue with the installation.

The only comprehnesive example I found was this utube http://www.youtube.com/watch?v=Yo7hO7GZ-ug video that includes links to a custom version that uses "CodeBlocks". I could not get it working on my Raspbian (Weezy Debian) version.

I was desperate and was not optimistic - but once you know one trick, it is REALLY EASY to get SDL2 running!

Get Loaded
1) Download - Get the linux generic release http://www.libsdl.org/download-2.0.php and unzip it in any directory. The really neat thing is the necessary Debian install files are provided and will setup automatically.

2) Install - Navigate to the Debian subdirectory. The instructions are in the text file "install.txt". All that is needed is to go to the unzip directory as root and run the following command './configure; make; make install'. It took about 50min to 1hr to do it's thing.

3) Done - It's ready... except ... :(

I spent the next two days not getting anything to compile. I eventually found out that SDL1 and SDL2 expect a custom made config program to pass the compiler library and include file information. This program is set up during the install process.

4) - Compile - Use these commands for SDL1 or SDL2 compiles
For sdl1 progs use...
Code: Select all
gcc `sdl-config --cflags --libs` -v -o myprog main.c > compile.log 2>&1

For sdl2 programs use...
Code: Select all
gcc `sdl2-config --cflags --libs` -v -o myprog main.c > compile.log 2>&1

NOW... you are up and running.

(Note: I tried for several days to manually provide the LIB and INC settings but I was unable to get anything to compile. You can run the "sdl2-config --cflags --libs" from a terminal and see what is being sent to the gcc compiler but when I tried to cut and past the same thing in a manual compile, it just would not work for me.)

Goodies!
I quickly found that SDL needs several support libraries to be able to use images and fonts.
The packages are located at http://www.libsdl.org/projects/
SDL2_image-2.0.0 - bmp is built in but you need this for jpg, png etc.
SDL2_mixer-2.0.0 - audio support
SDL2_net-2.0.0 - network support
SDL2_ttf-2.0.12 - trutype font support
SDL_rtf-0.1.0 - rich text format support

The install instructions for each package are the same so I have provided just one example.

Image Support, SDL2_image-2.0.0 - instructions are for 'root' user (you can also use sudo)
1) Download the package from http://www.libsdl.org/projects/
2) unzip
3) cd to the working directory
4) autogen.sh
5) ./configure && make && make install

When you are done, you will receive this message
Libraries have been installed in: /usr/local/lib

If you ever happen to want to link against installed libraries in a given directory,
LIBDIR, you must either use libtool, and specify the full pathname of the library,
or use the `-LLIBDIR' flag during linking and do at least one of the following:

- add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.



I just include the directories with the -L and -I compiler commands

# file locations
LIB="-L./ -L./lib -L~/lib -L/lib -L/usr/lib -L/usr/local/lib -L/usr/lib/arm-linux-gnueabihf"
INC="-I./ -I./lib -I~/include -I/usr/include"

# graphic file locations
GLIB="-L/opt/vc/lib"
GINC="-I/opt/vc/include -Iopt/vc/src/hello_pi/libs"

# compile program
gcc `sdl2-config --cflags --libs` $LIB $GLIB $INC $GINC -v -o <program> <source> >> compile.log 2>&1

That's it, your done!

A discussion of various options in using these packages can be found at http://www.raspberrypi.org/phpBB3/viewtopic.php?f=67&t=12693&p=428692#p428692

Development Environment
For completeness I am providing my actual compiler script "compile.sh" and ".desktop" link so it can all be compiled from a text or xterm terminal.

This file is called "compile.sh" and can be run from a terminal or "desktop" link.
Code: Select all
#!/bin/bash

  printf "\n"
  printf "\t+----------------------------+\n"
  printf "\t|       Compile main.c       |\n"
  printf "\t|          SDL2 test         |\n"
  printf "\t+----------------------------+\n\t"
  printf "\n\t Start Compile: "; date

  date > compile.log; printf "\n" >> compile.log

  # file locations
  LIB="-L./ -L./lib -L~/lib -L/lib -L/usr/lib -L/usr/local/lib -L/usr/lib/arm-linux-gnueabihf"
  INC="-I./ -I./lib -I~/include -I/usr/include"

  # graphic file locations
  GLIB="-L/opt/vc/lib"
  GINC="-I/opt/vc/include -Iopt/vc/src/hello_pi/libs"

  # compile program
  gcc `sdl2-config --cflags --libs` $LIB $GLIB $INC $GINC -v -o sdl2_test main.c  >> compile.log 2>&1

  # run program
  if [ -f sdl2_test ]; then
    ./sdl2_test
    printf "\tEnd of program... \n"   
  else 
    cat ./compile.log
    printf "\t *** There where errors, compile aborted. ***\n"
  fi

  # required so xterm will not close
  printf "\n\t%s" "press any key to exit: "
  read -n 1


---------

This is the "compile.desktop" GUI link file to be able to click on and compile from a xterm.
Code: Select all
[Desktop Entry]
Name=Compile
Comment=Compiles C program
Type=Application
Encoding=UTF-8
Terminal=false
StartupNotify=true
Icon=/usr/share/icons/gear_lnk.png
Exec=xterm  -sb -rightbar -fg Beige -bg "rgb:00/10/20" -e "cd /root/<path to program>  && ./compile.sh"


Try It!
Here is the "main.c" SDL2 test program...
Code: Select all
#include <SDL2/SDL.h>

// +--------------------------------------------------+
// |            Minimal SDL2 Test Program            |
// |  Creates a graphics window then shuts it down    |
// |  after 10 seconds.                               |
// +--------------------------------------------------+


int main ( int argc, char** argv )
{
    SDL_Window *window;

    SDL_Init(SDL_INIT_VIDEO);

    window = SDL_CreateWindow(
                              "SDL2 TEST PROGRAM",    // window title
                              SDL_WINDOWPOS_CENTERED, // the x position of the window
                              SDL_WINDOWPOS_CENTERED, // the y position of the window
                              400,400,                // window width and height
                              SDL_WINDOW_RESIZABLE    // create resizeable window
                              );
    if(window == NULL)                                // if no win, show error
    {
        printf("Could not create SDL2 test window: %s\n", SDL_GetError());
        return 1;
    }

    SDL_Delay(10000);                                 // 10sec delay
    SDL_DestroyWindow(window);                        // kill window
    SDL_Quit();                                       // clean up
    return 0;                                         // return success
}


So there you have it!
Lets all get together and start sharing our SDL2 programs!!!

Test Programs
Once you install SDL2 a comprehensive set of test routines are provided with the core package - but no compile info is provided. It was at this point that I ran into my problems until I ran across the need to pass LIB & INC info using the "sdl-config" program.

I created a script that tries to compile all of them. Some will compile while others don't.
I have not looked at the problems but I expect to find they need the "image" and "font" packages.
compile_all.sh
Code: Select all
#!/bin/bash

#  +--------------------------------------+
#  |    Compile all SDL2 Test Programs    |
#  +--------------------------------------+

while read F  ; do
  printf "\n"
  printf "\t+-----   Compileing $F.c  -----+\n"
  printf "\n\t Start time: "
  date
  printf "\n"
  gcc `sdl2-config --cflags --libs` -o $F $F.c
  printf "\n\t End time: "
  date
  printf "\n"
done <./filelist.txt


filelist.txt - These test programs compile OK
Code: Select all
checkkeys
loopwave
testatomic
testaudioinfo
testdrawchessboard
testerror
testfile
testgamecontroller
testgesture
testgl2
testgles
testhaptic
testiconv
testjoystick
testkeys
testloadso
testlock
testmessage
testmultiaudio
testoverlay2
testplatform
testpower
testresample
testrumble
testsem
testshader
testshape
testspriteminimal
teststreaming
testthread
testtimer
testver
torturethread



These programs don't compile.
They also did not compile after loading Image and Font support.

testautomation_audio
testautomation
testautomation_clipboard
testautomation_events
testautomation_keyboard
testautomation_main
testautomation_mouse
testautomation_pixels
testautomation_platform
testautomation_rect
testautomation_render
testautomation_rwops
testautomation_sdltest
testautomation_stdlib
testautomation_surface
testautomation_syswm
testautomation_timer
testautomation_video
testdraw2
testime
testintersections
testnative
testnativew32
testnativex11
testrelative
testrendercopyex
testrendertarget
testscale
testsprite2
testwm2





To compile a single program use this script
compile1.sh
Code: Select all
#!/bin/bash

# check for 2 arguments
ARGS=2    # number of arguments

if [ $# -ne $ARGS ]; then
  printf "\t  +---------------------------------------+\n"
  printf "\t  |          Compile SDL2 Program         |\n"
  printf "\t  |                                       |\n"
  printf "\t  |  compile1.sh     ver Oct 1, 2013       |\n"
  printf "\t  |                                       |\n"
  printf "\t  |  Usage:                               |\n"
  printf "\t  |    compile1.sh <program> <source>      |\n"
  printf "\t  |                                       |\n"
  printf "\t  |  Example:                             |\n"
  printf "\t  |    compile1.sh  myprog  main.c        |\n"
  printf "\t  +---------------------------------------+\n"

  exit 1  # general error
fi

  printf "\n"
  printf "\t+-----   Compileing $2  -----+\n"
  printf "\n\t Start time: "; date

  # file locations
  LIB="-L./ -L./lib -L~/lib -L/lib -L/usr/lib -L/usr/local/lib -L/usr/lib/arm-linux-gnueabihf"
  INC="-I./ -I./lib -I~/include -I/usr/include"

  # graphic file locations
  GLIB="-L/opt/vc/lib"
  GINC="-I/opt/vc/include -Iopt/vc/src/hello_pi/libs"

  # compile program
  gcc `sdl2-config --cflags --libs` $LIB $GLIB $INC $GINC -v -o $1 $2 >> compile.log 2>&1

  printf "\n\t End time: ";  date
  printf "\n"

exit 0


Going Further
According to the test programs there are some problems with programs trying to use OpenGL, OpenGles, and Heptic that is pre-loaded on the Raspbian.
So, it would be nice to integrate these other common graphics packages along with the other major SDL2 packages - fonts, images, rich text, mixer, etc at http://www.libsdl.org/projects/
User avatar
Posts: 44
Joined: Sun Aug 04, 2013 4:00 pm
by Redrobes » Mon Oct 14, 2013 11:48 pm
Bravo ! Nice long and verbose bit of information to get it going.

I think there was another post about how to get SDL2 going with some more good advice on the boards somewhere - C++ forum topic I think. Anyway, this is something I would like to have a play with when I get some time. I'm sure its possible but its nice to have someone path beat it before hand.

All this info is very much appreciated.
User avatar
Posts: 80
Joined: Mon Dec 26, 2011 9:19 pm
Location: S.W. UK
by tednilsen » Fri Dec 06, 2013 10:57 am
Hi.

I have sucessfully(?) compiled the SDL2 as shown here, but I get these errors when trying to compile a simple test (Free Pascal).
After searching the web, I've learnt that "vc_dispmanx_element_add" has to do with OpenGLES somehow, and it seem to be some linking issues...

...any idea? I would love to be able to use SDL2 in FPC, so I can move my code from Windows to RPi..

First line is ok... second line triggers the error:
Code: Select all
if SDL_Init(SDL_INIT_VIDEO) <> 0 then exit;
win := SDL_CreateWindow('SDL', 0, 0, 640, 480, SDL_WINDOW_SHOWN);

Message output:
Code: Select all
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
/usr/local/lib/libSDL2.so: undefined reference to `vc_dispmanx_element_add'
/usr/local/lib/libSDL2.so: undefined reference to `vc_dispmanx_update_start'
/usr/local/lib/libSDL2.so: undefined reference to `vc_dispmanx_resource_delete'
/usr/local/lib/libSDL2.so: undefined reference to `graphics_get_display_size'
/usr/local/lib/libSDL2.so: undefined reference to `vc_dispmanx_update_submit_sync'
/usr/local/lib/libSDL2.so: undefined reference to `bcm_host_init'
/usr/local/lib/libSDL2.so: undefined reference to `vc_dispmanx_update_submit'
/usr/local/lib/libSDL2.so: undefined reference to `vc_dispmanx_element_remove'
/usr/local/lib/libSDL2.so: undefined reference to `vc_dispmanx_rect_set'
/usr/local/lib/libSDL2.so: undefined reference to `vc_dispmanx_display_open'
/usr/local/lib/libSDL2.so: undefined reference to `vc_dispmanx_resource_write_data'
/usr/local/lib/libSDL2.so: undefined reference to `vc_dispmanx_element_change_attributes'
/usr/local/lib/libSDL2.so: undefined reference to `vc_dispmanx_resource_create'
gfLib.lpr(37,32) Error: Error while linking
gfLib.lpr(37,32) Fatal: There were 1 errors compiling module, stopping
Posts: 10
Joined: Fri Dec 06, 2013 10:37 am
by kouky » Wed Dec 11, 2013 7:57 pm
Hello,

I followed the instructions but ended-up with that error message:
/usr/bin/install: cannot create regular file '/usr/local/bin/sdl2-config' : permission denied

Any hints?

edit:
the solution was to do
sudo -s
first
Posts: 6
Joined: Sat Jun 09, 2012 10:48 am
by kouky » Thu Dec 12, 2013 12:11 pm
When using the 'SDL_RENDERER_ACCELERATED' flag on the SDL_CreateRenderer function, the window content is not drawn aymore, just seeing the pi desktop.

Is that mode not compatible with Raspbian?
Posts: 6
Joined: Sat Jun 09, 2012 10:48 am
by tibi38 » Sun Dec 15, 2013 11:04 am
Dear all a nice christmas time,
I tried to get it run on my pi, but every time I start in SDL2-image the showimage programm I run in the error-message:
SDL_CreateWindowAndRenderer() failed: No available video device

what is wrong in my environment?

br
TB
Admin of http://bed-and-breakfast-ungarn.de
Posts: 42
Joined: Sat Nov 10, 2012 8:46 am
Location: Europe
by ulysess » Sat Jan 18, 2014 12:36 pm
Does anyone having problem with input devices? I'm trying to port some games and keyboard doesn't work.
Mis apuntes de...Raspberry Pi: http://misapuntesde.com
Google Docs RPi: http://goo.gl/Iwhbq
User avatar
Posts: 302
Joined: Thu Aug 02, 2012 6:35 am
Location: Spain
by Orange » Fri Mar 28, 2014 3:00 pm
Extremely useful post. Saved me a lot of time.

Thanks
Posts: 36
Joined: Tue Jan 24, 2012 6:41 am
by PiGraham » Fri May 02, 2014 8:03 pm
This was a useful thread. I have SDL2 working without X11 on Raspbian.

Unfortunately I can't run my code from GDB, or remotely with gdbserver because it hangs on SDL_init(SDL_INIT_VIDEO)
Code: Select all
126         if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0) {
(gdb)
[New Thread 0xb6bfc470 (LWP 2714)]


I have to kill gdb to recover.
NB SDL_INIT_NOPARACHUTE is included because I found a suggestion that it might help to disable the signal traps that SDL sets up by default. It made no difference.

The apps run fine without gdb, both from the local session and via SSH.

One oddity is that testopengles and testopengles2 report no support, but SDL_RendererInfo reports the renderer name is opengles2 and flag
SDL_RENDERER_ACCELERATED is set as expected.

Any ideas? Can you run SDL2 apps in GDB on Raspbian?

testver reports:
Code: Select all
INFO: Compiled with SDL 2.0 or newer
INFO: Compiled version: 2.0.0.7760 (hg-7760:323c4532e447)
INFO: Linked version: 2.0.0.7760 (hg-7760:323c4532e447)

Compiled with:
Code: Select all
    #!/bin/bash

    # check for 2 arguments
    ARGS=1    # number of arguments

    if [ $# -ne $ARGS ]; then
      printf "\t  +---------------------------------------+\n"
      printf "\t  |          Compile SDL2 Program         |\n"
      printf "\t  |                                       |\n"
      printf "\t  |  compile1.sh     ver Oct 1, 2013       |\n"
      printf "\t  |                                       |\n"
      printf "\t  |  Usage:                               |\n"
      printf "\t  |    compile1.sh <program> <source>      |\n"
      printf "\t  |                                       |\n"
      printf "\t  |  Example:                             |\n"
      printf "\t  |    compile1.sh  myprog                |\n"
      printf "\t  | compile myprog.c to binary myprog     |\n"
      printf "\t  +---------------------------------------+\n"

      exit 1  # general error
    fi

      printf "\n"
      printf "\t+-----   Compileing $2  -----+\n"
      printf "\n\t Start time: "; date

      # file locations
      LIB="-L./ -L./lib -L~/lib -L/lib -L/usr/lib -L/usr/local/lib -L/usr/lib/arm-linux-gnueabihf"
      INC="-I./ -I./lib -I~/include -I/usr/include"

      # graphic file locations
      GLIB="-L/opt/vc/lib"
      GINC="-I/opt/vc/include -Iopt/vc/src/hello_pi/libs"

      # compile program
      gcc `sdl2-config --cflags --libs` $LIB $GLIB $INC $GINC -v -ggdb -o $1 $1.c

      printf "\n\t End time: ";  date
      printf "\n"

    exit 0


teststreaming.c
Code: Select all
/*
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely.
*/
/********************************************************************************
 *                                                                              *
 * Running moose :) Coded by Mike Gorchak.                                      *
 *                                                                              *
 ********************************************************************************/

#include <stdlib.h>
#include <stdio.h>

#include "SDL.h"

#define MOOSEPIC_W 64
#define MOOSEPIC_H 88

#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
#define MOOSEFRAMES_COUNT 10

SDL_Color MooseColors[84] = {
    {49, 49, 49}, {66, 24, 0}, {66, 33, 0}, {66, 66, 66},
    {66, 115, 49}, {74, 33, 0}, {74, 41, 16}, {82, 33, 8},
    {82, 41, 8}, {82, 49, 16}, {82, 82, 82}, {90, 41, 8},
    {90, 41, 16}, {90, 57, 24}, {99, 49, 16}, {99, 66, 24},
    {99, 66, 33}, {99, 74, 33}, {107, 57, 24}, {107, 82, 41},
    {115, 57, 33}, {115, 66, 33}, {115, 66, 41}, {115, 74, 0},
    {115, 90, 49}, {115, 115, 115}, {123, 82, 0}, {123, 99, 57},
    {132, 66, 41}, {132, 74, 41}, {132, 90, 8}, {132, 99, 33},
    {132, 99, 66}, {132, 107, 66}, {140, 74, 49}, {140, 99, 16},
    {140, 107, 74}, {140, 115, 74}, {148, 107, 24}, {148, 115, 82},
    {148, 123, 74}, {148, 123, 90}, {156, 115, 33}, {156, 115, 90},
    {156, 123, 82}, {156, 132, 82}, {156, 132, 99}, {156, 156, 156},
    {165, 123, 49}, {165, 123, 90}, {165, 132, 82}, {165, 132, 90},
    {165, 132, 99}, {165, 140, 90}, {173, 132, 57}, {173, 132, 99},
    {173, 140, 107}, {173, 140, 115}, {173, 148, 99}, {173, 173, 173},
    {181, 140, 74}, {181, 148, 115}, {181, 148, 123}, {181, 156, 107},
    {189, 148, 123}, {189, 156, 82}, {189, 156, 123}, {189, 156, 132},
    {189, 189, 189}, {198, 156, 123}, {198, 165, 132}, {206, 165, 99},
    {206, 165, 132}, {206, 173, 140}, {206, 206, 206}, {214, 173, 115},
    {214, 173, 140}, {222, 181, 148}, {222, 189, 132}, {222, 189, 156},
    {222, 222, 222}, {231, 198, 165}, {231, 231, 231}, {239, 206, 173}
};

Uint8 MooseFrames[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE];

void quit(int rc)
{
    SDL_Quit();
    exit(rc);
}

void UpdateTexture(SDL_Texture *texture, int frame)
{
    SDL_Color *color;
    Uint8 *src;
    Uint32 *dst;
    int row, col;
    void *pixels;
    int pitch;

    if (SDL_LockTexture(texture, NULL, &pixels, &pitch) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock texture: %s\n", SDL_GetError());
        quit(5);
    }
    src = MooseFrames[frame];
    for (row = 0; row < MOOSEPIC_H; ++row) {
        dst = (Uint32*)((Uint8*)pixels + row * pitch);
        for (col = 0; col < MOOSEPIC_W; ++col) {
            color = &MooseColors[*src++];
            *dst++ = (0xFF000000|(color->r<<16)|(color->g<<8)|color->b);
        }
    }
    SDL_UnlockTexture(texture);
}

int
main(int argc, char **argv)
{
    SDL_Window *window;
    SDL_Renderer *renderer;
    SDL_RWops *handle;
    SDL_Texture *MooseTexture;
    SDL_Event event;
    SDL_bool done = SDL_FALSE;
    int frame;

   /* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
        return 1;
    }

    /* load the moose images */
    handle = SDL_RWFromFile("moose.dat", "rb");
    if (handle == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
        quit(2);
    }
    SDL_RWread(handle, MooseFrames, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
    SDL_RWclose(handle);


    /* Create the window and renderer */
    window = SDL_CreateWindow("Happy Moose",
                              SDL_WINDOWPOS_UNDEFINED,
                              SDL_WINDOWPOS_UNDEFINED,
                              MOOSEPIC_W*4, MOOSEPIC_H*4,
                              SDL_WINDOW_RESIZABLE);
    if (!window) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
        quit(3);
    }

    renderer = SDL_CreateRenderer(window, -1,SDL_RENDERER_PRESENTVSYNC );
    if (!renderer) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
        quit(4);
    }

    MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
    if (!MooseTexture) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
        quit(5);
    }

    /* Loop, waiting for QUIT or the escape key */
    frame = 0;
    while (!done) {
        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_KEYDOWN:
                if (event.key.keysym.sym == SDLK_ESCAPE) {
                    done = SDL_TRUE;
                }
                break;
            case SDL_QUIT:
                done = SDL_TRUE;
                break;
            }
        }

        frame = (frame + 1) % MOOSEFRAMES_COUNT;
        UpdateTexture(MooseTexture, frame);

        SDL_RenderClear(renderer);
        SDL_RenderCopy(renderer, MooseTexture, NULL, NULL);
        SDL_RenderPresent(renderer);
    }
    SDL_DestroyRenderer(renderer);

    quit(0);
    return 0;
}

/* vi: set ts=4 sw=4 expandtab: */


This is a debug session:
Code: Select all
 sudo gdb teststreaming
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/pi/SDL2/SDL/test/teststreaming...done.
(gdb) break main
Breakpoint 1 at 0x8b5c: file teststreaming.c, line 93.
(gdb) run
Starting program: /home/pi/SDL2/SDL/test/teststreaming
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".

Breakpoint 1, main (argc=1, argv=0xbefff854) at teststreaming.c:93
93          SDL_bool done = SDL_FALSE;
(gdb) next
97          SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
(gdb)
99          if (SDL_Init(SDL_INIT_VIDEO) < 0) {
(gdb)
[New Thread 0xb6bfc470 (LWP 2904)]

************ HANGS HERE until teststreaming process is killed from another tty with
sudo kill -s9 pid ***********

[Thread 0xb6bfc470 (LWP 2904) exited]
warning: Unable to fetch general register.
warning: Error removing breakpoint 0
PC register is not available
(gdb)
Posts: 2488
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville
by Keyaku » Thu Jun 05, 2014 12:09 am
Hello, everyone!

I hope I'm not complicating anything as I post this. My intention is exactly the opposite:
I created a script that, running the script as it is, will automatically download and install the latest SDL2 version (SDL2-2.0.3 as of this day).
Instructions are there, but, basically, you don't need to do a thing other than letting it run. Only when reinstalling or downgrading an SDL build will the script prompt you for a confirmation.
When the script ends, it creates jwzumwalt's compile.sh (slightly modified to show up the selected SDL version).

Here's the link for the Github page.

Hope this saves time for a lot of people!
Posts: 8
Joined: Wed Jun 04, 2014 11:11 pm
by dholth » Fri Jun 06, 2014 3:33 am
I have the same keyboard problem, I'm running SDL2 2.0.3 but my app does not receive any keyboard events even though I'm in the input group. Joystick events seem to work however. Instead, I would like to be able to receive both joystick and keyboard events as input. Any hints?

I'm using my own pysdl2-cffi SDL2 wrapper to program SDL2 in Python. It takes about a minute to load the first time, but by patching cffi to cache pickled versions of the parsed C headers it starts up in 10-20 seconds on pypy 2.3. The particular demo I'm running goes about 23 frames per second running in 1080p fullscreen compared to 500 fps on my main computer.
Posts: 2
Joined: Fri Jun 06, 2014 3:29 am
by dholth » Fri Jun 06, 2014 10:57 am
By the way according to the migration guide https://wiki.libsdl.org/MigrationGuide, SDL_INIT_NOPARACHUTE does nothing in SDL2.
Posts: 2
Joined: Fri Jun 06, 2014 3:29 am
by chungkun » Sat Aug 23, 2014 4:06 pm
For sdl2 test, please cd to test directory and do
./configure
make
Posts: 1
Joined: Sat Aug 23, 2014 4:01 pm
by ZARk » Mon Oct 13, 2014 1:01 pm
Hello

Could someone post a simple "hello world" app built in SDL2 that uses HW Acceleration (with or without X11) ?


I can't get SDL2 to create a window without X11
and with X11 it's dead slow, so most probably isn't hw accelerated ...
Posts: 3
Joined: Mon Oct 13, 2014 10:39 am
by Sonny_Jim » Mon Oct 20, 2014 8:28 pm
I had problems getting SDL2 to let me do hardware acceleration with OpenGL ES, even though I was sure that I had everything right. I was getting errors like this:
Code: Select all
Couldn't create renderer: Unknown OpenGL context profile -1092887348


The solution was to build SDL2.0.3 with the following configure options:
Code: Select all
./configure --disable-video-opengl --disable-video-x11


You'll still be able to run SDL2 apps under X11, just this time using the OpenGL ES renderer. Hope this helps.
Posts: 45
Joined: Tue Oct 23, 2012 4:15 pm
by trabitboy » Tue Nov 25, 2014 9:48 pm
Hello,
using the initial script I could compile SDL2 on raspbian,
and port a 2D project over the course of the last months.

So video works fine ( and is fast ) in console mode,
sound untested.

interestingly, gdb worked out of the box through ssh ( like running locally on the pi ), I had no hang as mentionned earlier in the thread.

This thread is a must :)
Posts: 2
Joined: Tue Nov 25, 2014 9:42 pm
by trabitboy » Mon Dec 01, 2014 9:31 am
Hi,
I got accelerated video, gamepad working on a fairly large 2d project : I must say I am super pleased by how well it feels to play on the raspi !

Now, the audio is an mp3 playing in the background with several wav samples played as fx.

The software starts fine with audio, then starts to lag , audio is interrupted,
and I can see a couple buffer underruns in the console before audio stops completely ( software keeps on running ).

I was wondering if someone has used SDL mixer for a game on the pi with similar constraints?
( one audio track + certain number of small fxs ) .

My search tracks so far:
- will check cpu use with top
- will try to run only with music / only with fxs
- will try to downsample the mp3 > find a format that is lighter

If you have any more ideas of things to try, let me know ;o)
Regards!
Posts: 2
Joined: Tue Nov 25, 2014 9:42 pm
by toxibunny » Mon Dec 01, 2014 10:18 am
very interesting thread. Is there any chance someone could make a youtube video, to show what the performance is like using hardware acceleration, please?
note: I may or may not know what I'm talking about...
Posts: 1383
Joined: Thu Aug 18, 2011 9:21 pm
by nigelbest » Mon Dec 01, 2014 3:39 pm
Been looking everywhere for this - thank you
Posts: 1
Joined: Mon Dec 01, 2014 3:32 pm
Location: Ditchling
by blacktm » Tue Dec 02, 2014 7:55 am
For yet another option to install SDL2, I have a command-line utility as part of a project I'm working on called Simple 2D (https://github.com/simple2d/simple2d). Running the `simple2d.sh` script with...
Code: Select all
bash simple2d.sh install --sdl
...will compile and install SDL2 from source. You can also run the script from the web using...
Code: Select all
url='https://raw.githubusercontent.com/simple2d/simple2d/master/simple2d.sh'; which curl > /dev/null && cmd='curl -fsSL' || cmd='wget -qO -'; bash <($cmd $url) install --sdl
Hope that helps. Enjoy!
Posts: 3
Joined: Wed Oct 22, 2014 7:17 pm
Location: Washington, DC
by watz » Wed Dec 03, 2014 10:14 am
Perfect! That script worked like a charm out of the box. Thanks :-)
Posts: 2
Joined: Wed Dec 03, 2014 7:40 am
by ThomasBR » Mon Jan 12, 2015 5:31 am
Hello altogether,
I worked since about 2 month at a special program enviroment with SDL2 and Raspbian, Version
of 09-09-2014. Now I came to the point, where I wanted to extend the window handling and
thats where the trouble started.
The first I tried out was to use rendering. I updated raspberry properly but I didn't
suceed to become a hardware rendering. The only thing I got was a very, very slow software
rendering and I'm shure that if I would write that in software from my own, it would
be about 20-50 times faster (that's no joke and although would be no special art, about
three seconds are a very long time to render a picture!).
Any other ideas for Version 09-09-2014 ?

The next thing I tried out was version 24-12-2014. With a lucky punch I found out how to
get keyboard and mouse io running. Unfortunately I didn't write it down what I made and
so until this time, I didn't suceed a second time. Only giving 'input' to user 'pi' is
not enough, at minimum 'pi' should get 'tty' and libudev-dev had to be loaded. But
there was a third thing and I have forgotten that. If someone knows the exact howto and
write it down, then I think he could not only make me but a lot of people very happy.

But now the next thing. With version 24-12-2014 rendering works very fast, but
now you can only open a fullscreen desktop window, better to say SDL2 always does so,
regardless which parameter you give to it. Also resizing the window an giving this
window to the renderer result in a small picture in a full screen window. But it's
very fast, my respect! Although if you don't use rendering. You alway get a full screen
desktop window.
Any ideas ?
(Sorry for my "half-baked" english ....)
Posts: 1
Joined: Sun Jan 11, 2015 1:47 pm