andreasvolz
Posts: 2
Joined: Sat Jul 10, 2021 10:30 pm

SDL2 without X11

Sat Jul 10, 2021 10:52 pm

Hi,

following setup:
- Raspberry Pi 3 Model A Plus Rev 1.0
- piCorePlayer v7.0.0 / piCore v12.0pCP

This setup supports a GUI based on SDL1.x.

I try to modify the piCorePlayer setup for an application using SDL2. For this I compiled the SDL2-2.0.14 sources

SDL2 Configure Summary:
Building Shared Libraries
Building Static Libraries
Enabled modules : atomic audio video render events joystick haptic sensor power filesystem threads timers file loadso cpuinfo assembly
Assembly Math :
Audio drivers : disk dummy oss alsa(dynamic)
Video drivers : dummy rpi x11(dynamic) opengl opengl_es1 opengl_es2 vulkan
X11 libraries : xdbe xshape xvidmode
Input drivers : linuxev linuxkd
Enable virtual joystick APIs : YES
Using libsamplerate : NO
Using libudev : YES
Using dbus : NO
Using ime : YES
Using ibus : NO
Using fcitx : NO

This works nice as long as I run it under a X11 configuration. But I like to run it direct without X11.

See here what happens if I call a driver demo
Testing video drivers...
SDL_VIDEODRIVER available: x11 RPI dummy
SDL_VIDEODRIVER usable :
SDL_Init(): The video driver did not add any displays

A similar configuration with raspbian works nice with driver "RPI". So I assume there is a problem with "RPI" in this special setup. Do you've any ideas how to trace the problem? Is there a driver example that works without SDL to ensure the driver itself is working?

andreasvolz
Posts: 2
Joined: Sat Jul 10, 2021 10:30 pm

Re: SDL2 without X11

Sun Jul 11, 2021 4:26 am

Code: Select all

#include <SDL2/SDL.h>
#include <iostream>
#include <vector>

int main( int argc, char** argv )
{
    SDL_Init( 0 );

    std::cout << "Testing video drivers..." << '\n';
    std::vector< bool > drivers( SDL_GetNumVideoDrivers() );
    for( int i = 0; i < drivers.size(); ++i )
    {
        drivers[ i ] = ( 0 == SDL_VideoInit( SDL_GetVideoDriver( i ) ) );
        SDL_VideoQuit();
    }

    std::cout << "SDL_VIDEODRIVER available:";
    for( int i = 0; i < drivers.size(); ++i )
    {
        std::cout << " " << SDL_GetVideoDriver( i );
    }
    std::cout << '\n';

    std::cout << "SDL_VIDEODRIVER usable   :";
    for( int i = 0; i < drivers.size(); ++i )
    {
        if( !drivers[ i ] ) continue;
        std::cout << " " << SDL_GetVideoDriver( i );
    }
    std::cout << '\n';

    if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
    {
        std::cerr << "SDL_Init(): " << SDL_GetError() << '\n';
        return EXIT_FAILURE;
    }
    std::cout << "SDL_VIDEODRIVER selected : " << SDL_GetCurrentVideoDriver() << '\n';

    SDL_Window* window = SDL_CreateWindow
        (
        "SDL2",
        SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
        640, 480,
        SDL_WINDOW_SHOWN
        );
    if( nullptr == window )
    {
        std::cerr << "SDL_CreateWindow(): " << SDL_GetError() << '\n';
        return EXIT_FAILURE;
    }

    std::cout << "SDL_RENDER_DRIVER available:";
    for( int i = 0; i < SDL_GetNumRenderDrivers(); ++i )
    {
        SDL_RendererInfo info;
        SDL_GetRenderDriverInfo( i, &info );
        std::cout << " " << info.name;
    }
    std::cout << '\n';

    SDL_Renderer* renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED );
    if( nullptr == renderer )
    {
        std::cerr << "SDL_CreateRenderer(): " << SDL_GetError() << '\n';
        return EXIT_FAILURE;
    }
    SDL_RendererInfo info;
    SDL_GetRendererInfo( renderer, &info );
    std::cout << "SDL_RENDER_DRIVER selected : " << info.name << '\n';

    bool running = true;
    unsigned char i = 0;
    while( running )
    {
        SDL_Event ev;
        while( SDL_PollEvent( &ev ) )
        {
            if( ( ev.type == SDL_QUIT ) ||
                ( ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_ESCAPE ) )
            {
                running = false;
            }
        }

        SDL_SetRenderDrawColor( renderer, i, i, i, SDL_ALPHA_OPAQUE );
        SDL_RenderClear( renderer );
        SDL_RenderPresent( renderer );
        i++;
    }

    SDL_DestroyRenderer( renderer );
    SDL_DestroyWindow( window );
    SDL_Quit();
    return 0;
}
Last edited by andreasvolz on Sun Jul 11, 2021 4:27 am, edited 1 time in total.

JoeStrout
Posts: 50
Joined: Sun Oct 09, 2011 12:11 pm
Contact: Website

Re: SDL2 without X11

Thu Jul 29, 2021 4:56 pm

Hi Andreas,

Does that second post mean you got it working? I'm gearing up for a SDL (without X11) project myself, and I'm a little intimidated by the difficulties I see people having...

Thanks,
- Joe
Last edited by JoeStrout on Thu Jul 29, 2021 5:18 pm, edited 1 time in total.
Creator of MiniScript, a new language for learning, teaching, and embedding in other C/C++ or C# applications.
For more info, visit https://miniscript.org

cdsteinkuehler
Posts: 11
Joined: Thu Feb 11, 2021 2:24 am
Contact: Website

Re: SDL2 without X11

Tue Aug 03, 2021 3:17 pm

I don't know if it will help, but I was experimenting with SDL2 on top of Ubuntu (64-bit 20.04.2) and for me the following results in a working SDL2 library that runs without X11. I haven't done a lot of testing but I got a few available simple SDL test programs working. The important part is obviously the configure options.

Code: Select all

# Grab SDL2 library:
https://libsdl.org/download-2.0.php

# Extract & build
tar -xzvf SDL2-2.0.14.tar.gz
cd SDL2-2.0.14
sudo mk-build-deps --install debian/control
sudo apt-get install libdirectfb-dev libgbm-dev
mkdir build
cd build
../configure --disable-pulseaudio --disable-esd --disable-video-opengl --disable-video-wayland --disable-video-directfb --enable-video-kmsdrm --enable-video-opengles
make -j3
sudo make install

User avatar
Gavinmc42
Posts: 6075
Joined: Wed Aug 28, 2013 3:31 am

Re: SDL2 without X11

Tue Aug 03, 2021 11:43 pm

You want framebuffer not x11.

I wonder if SDL will run on QEMU?
I have been trying to do graphics in QEMU framebuffer, had not thought about SDL
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

JoeStrout
Posts: 50
Joined: Sun Oct 09, 2011 12:11 pm
Contact: Website

Re: SDL2 without X11

Wed Aug 04, 2021 9:14 pm

Sorry, I'm super new at Pi and Linux in general. When you say
You want framebuffer not x11.
...is that implying some correction to what was posted above, or just giving proper terms to what we're trying to do in this thread?

Is maybe `--disable-video-directfb` not the right option to use (assuming that stands for "direct framebuffer") if I'm not planning to use OpenGLES?

(Waiting for my HDMI adapter to arrive so I can start playing around with me Seeed Studio Pi4 keyboard-computer and try this stuff out!)
Creator of MiniScript, a new language for learning, teaching, and embedding in other C/C++ or C# applications.
For more info, visit https://miniscript.org

Jarrod
Posts: 28
Joined: Sat Sep 02, 2017 5:57 am

Re: SDL2 without X11

Sun Aug 08, 2021 4:42 am

I have been trying to get this to work as well. My ultimate goal is to build pygame against SDL2 and have it render to the framebuffer, with acceleration. The dpkg libs accessible from apt do not appear to support this. I have built SDL2 from source but was still not able to make it work.

Do I need to fkms or the kms drivers for this? It seems like I should but on my 3B+, when the real GL driver loads, my console screen goes blank. Is that expected behavior on that hardware? With the fkms driver the console/fb display behaves OK. However, I cannot get any of the /opt/vc/src/hello_* examples that use GL to work. It seems they all are unable to establish a GL surface.

Overall this has been quite frustrating. All I really require is hardware blitting. I don't actually care about the 3D stuff.

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

Re: SDL2 without X11

Mon Aug 30, 2021 4:22 pm

All you guys need for this is building SDL2 with the KMSDRM video backend.
It has been working for years.
Don't use FKMS, just full KMS. Nothing related to the old dispmanx is involved on this.

Jarrod
Posts: 28
Joined: Sat Sep 02, 2017 5:57 am

Re: SDL2 without X11

Mon Aug 30, 2021 5:35 pm

Thanks and yes I've since seen your comments in the kernel github issues. Would be amazing if the raspbian packages worked out of the box, but I will compile these when I find time.

My blank screen when the KMS driver loads turns out to be that the EDID on my display has some odd (as opposed to even) pixel clock values and this is not compatible with the KMS driver, even on Pi3, since the Pi4 requires 2 pixels per clock.


Return to “Graphics programming”