[SOLVED]Building/Installing SDL2 on RaspBerryPi

Hello,

I have to develop a SDL2 application on RaspberryPi.

So, I first tried to install everything based on this tuto.

But building SDL2 library cause some problems.

First, the build is normally based on SDL2-2.0.5.tar.gz (wget http://www.libsdl.org/release/SDL2-2.0.5.tar.gz).

But make install create a /usr/local/lib/libSDL2-2.0.so.0.4.1 library. Seems not normal, right?

In this tuto, SDL2 is configured to not use libPulseAudio:

./configure --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-opengl --host=arm-raspberry-linux-gnueabihf

But when I launch my app, I see a window flickering, then it complains for a missing libPulse configuration file:

W: [pulseAudio] core-util.c Failed to open configuration file "/home/pi/......." 

Then, I get a renderer creation problem.

Falied to create renderer : couldn’t matching render driver

Finally, I tried to download RaspberryPi prebuilt lib from buildbot libsd .org … sdl-raspberrypi-2166.tar.xz (2017-08-25)

And I still get the same errors about libPulse and renderer creation fail.

Info: I try to launch my app from a bash in X11 Raspbian desktop. (Linux 4.4.34-v7+ #930 armv71)
Hardware: BCM2709
Revision : a01041

How can I get SDL2 working please?

My code is:

int main(int argc, char** argv)
{
	if (SDL_Init(SDL_INIT_VIDEO) != 0 )
	{
		fprintf(stdout,"Fail to initalize SDL (%s)\n",SDL_GetError());
		return -1;
	}

	if(TTF_Init()==-1)
	{
		printf("TTF_Init: %s\n", TTF_GetError());
		exit(2);
	}

	SDL_Window* pWindow = NULL;
	pWindow = SDL_CreateWindow("Test SDL2",100,
									100,
									800,
									600,
									SDL_WINDOW_SHOWN);

	if( pWindow )
	{
		SDL_Renderer *pRenderer = SDL_CreateRenderer(pWindow,-1,SDL_RENDERER_ACCELERATED);

		if ( pRenderer )
		{
			SDL_RendererInfo info;
			SDL_GetRendererInfo(pRenderer, &info);

			fprintf(stderr, "name : %s\n", info.name);

			fprintf(stderr, "flags : ");

			        if (info.flags & SDL_RENDERER_SOFTWARE) fprintf(stderr, "SDL_RENDERER_SOFTWARE");
			if (info.flags & SDL_RENDERER_ACCELERATED) fprintf(stderr, "SDL_RENDERER_ACCELERATED ");
			if (info.flags & SDL_RENDERER_PRESENTVSYNC) fprintf(stderr, "SDL_RENDERER_PRESENTVSYNC ");
			if (info.flags & SDL_RENDERER_TARGETTEXTURE) fprintf(stderr, "SDL_RENDERER_TARGETTEXTURE ");

			fprintf(stderr, "\nnb textures max : %d\n", info.num_texture_formats);

			fprintf(stderr, "texture size max : %d x %d \n", info.max_texture_width, info.max_texture_height);

			int numDrivers = SDL_GetNumVideoDrivers();
			fprintf(stderr, "num Drivers %d\n", numDrivers);

			for (int i = 0; i < numDrivers; i++)
			{
				fprintf(stderr, "possible driver : %s\n", SDL_GetVideoDriver(i));
			}

			fprintf(stderr, "current driver : %s\n", SDL_GetCurrentVideoDriver());

			SDL_SetRenderDrawBlendMode(pRenderer, SDL_BLENDMODE_BLEND);
			SDL_SetRenderDrawColor(pRenderer,0,0,0,255);
			SDL_RenderClear(pRenderer);

			SDL_RenderPresent(pRenderer); // Affichage

			while (1) sleep(1);
			SDL_DestroyRenderer(pRenderer); 
		}
		else
		{
			fprintf(stdout,"fail to createrenderer (%s)\n",SDL_GetError());
		}
		SDL_DestroyWindow(pWindow);
	}
	else
	{
		fprintf(stderr,"Fail to create window: %s\n",SDL_GetError());
	}

	SDL_Quit();

	return 0;
}

If you’re happy to use the X11 driver you don’t need to build SDL2 at all, you can simply use the version available from the Raspbian repository (on Raspbian Jessie it’s 2.0.2 but on the latest Raspbian Stretch it’s 2.0.5). It’s what I do and I’m very happy with that approach.

sudo apt-get install libsdl2-2.0-0

Richard.

@rtrussell
Wow!!! You are right, it works.

Is there a development package?
How do you make your devs? cross-compil?

Al

This is the default path. Projects usually choose to install there to avoid conflicting with the packages from the distribution. If you’ve removed the SDL2 packages you can install it in their place by adding --prefix=/usr to the configure line. It’s no the recommended way because the package manager will start screaming if he finds files where they don’t belong. Better keep it in /usr/local.

SDL probably loads the x11 driver first. Since it can’t give you something accelerated, renderer creation fails with an error. You can make it select the rpi video driver with the SDL_VIDEODRIVER environment variable. Start your program with SDL_VIDEODRIVER=rpi ./mysdl2program. If you want to make the variable stay around use export SDL_VIDEODRIVER=rpi.

Edit: Note that the package from the repository doesn’t have the rpi driver. I thought you were building SDL2 yourself to get this driver.

Yes. It’s called libsdl2-dev.

Yes. On Raspbian Stretch it’s:

sudo apt-get install libsdl2-stretch-dev

On the older Jessie it’s:

sudo apt-get install libsdl2-dev

Richard.

@rtrussell

Ok, thanks, I found everything

Al

@ChliHug

In fact I was surprised by the version number (so.0.4.1), not bay the path.

And I got SDL2 working properly. I didn’t try it without X11 yet. It’s supposed to work.

Al.

Ooh, they moved to stretch. That was faster than I expected.

That’s the libtool versioning. It tries to reflect the API compatibility of the library.

I just noticed that the renderers don’t pass the SDL_RENDER_ACCELERATED request to the backend, so you can get the Mesa software renderer, too. The “no matching render driver” is because of the GL library path issues in SDL. If you want to test your self-compiled SDL2, set the SDL_VIDEO_GL_DRIVER environment variable to the name of the EGL library X11 is using. That’s probably libEGL.so.1 on your system.