1

I am working on an embedded Linux system (5.10.24), and there is a LCD display in it. Now I am trying to run a SDL2 example in it (from serial console), but I failed to do that. The example codes are as follows,

#include "SDL2/SDL.h"

int main(int argc, char* argv[])
{
        SDL_Window* window;
        SDL_Renderer* renderer;

        if (SDL_Init(SDL_INIT_VIDEO) < 0) {
                printf("error initializing SDL: %s\n", SDL_GetError());
                return 1;
        }

        window = SDL_CreateWindow("SDL_RenderClear",
                        SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                    512, 512, 0);

        renderer = SDL_CreateRenderer(window, -1, 0);
        SDL_SetRenderDrawColor(renderer, 64, 255, 128, 255);

        SDL_RenderClear(renderer);
        SDL_RenderPresent(renderer);

        SDL_Delay(5000);
        SDL_Quit();
        return 0;
}

It is compiled as mips-linux-gnu-gcc -g2 sdl_ex1.c -I/sysroot/usr/include/ -Lsysroot/usr/lib/ -lSDL2 -lts -o sdl_ex1 When I ran it from serial console, it failed with following error.

~ # ./sdl_ex1
error initializing SDL: No available video device
~ # echo $DISPLAY

~ #

The system is running in ARMv7 (quad core) and the GUI is a QT UI, Linux kernel is 5.10.24. There are 64MB RAM, 256MB FLASH, no X.

But I can run it correctly in Xterm in Ubuntu-20.04 VM. There are 2 framebuffer devices, /dev/fb0 and /dev/fb1. A GUI is running in the LCD display, so in this system, how can I run SDL application ?

wangt13
  • 959
  • 7
  • 17
  • Add the additional details of What embedded device?, What version of X?, What GUI is running in the LCD display? – David C. Rankin Apr 15 '23 at 01:33
  • You are linking with `libX11` as part of your compile string on the embedded device, right? E.g. `-lX11`. Add your exact compile string (or makefile). If you get an answer on the Unix & Linux question, make sure you close this one (or vice versa). The question belongs on this site as it is "Programming Related". I doubt you will get an answer on the other site. – David C. Rankin Apr 15 '23 at 16:34
  • I updated the question with compiling command per your comments. I am NOT sure how to define `programming related`, and I have been using SO for many years on lots of questions. I think it was much better when it can tolerate software related questions, and SO is the TOP 1 technical website for lots of software engineers. But recently, I found things are changed, I don't know if the official roadmap of SO is changed to NOT tolerate more question and only focusing on so-called `programming related`. IMHO, I don't think this is a right change. Be open, be tolerant, is my expectation. – wangt13 Apr 16 '23 at 02:05
  • Between StackOverflow and Unix&Linux, generally Programming questions belong here, and "How do I use ... on Linux" questions go to Unix&Linux. You are good with your question here. The problem you are having getting answers is that unless somebody has your setup (or reasonably close to it), there really is no way to know what X packages and libraries are available to you and how you system is setup. I get the error and I get you have /dev/fb0 and /dev/fb1 devices available, but based on that I don't have an answer why SDL2 can't find a video device. Sounds path related. – David C. Rankin Apr 16 '23 at 02:38
  • The SDL2 problem I have is on an embedded system, where serial console is normally used, NO X stuffs, only a LCD display using MIPI DSI shows a QT based GUI. I succeeded in running the same code in Ubuntu-20.04-desktop, where the $DISPLAY is ':1', a window showing something in Ubuntu. But error reported in the embedded system. I am not familar with SDL2, not know its system dependencies and its environment, my assumption is it might use framebuffer in Linux, but it seemed I am wrong. So I am wonder if it is practical to run SDL2 in this embedded system. – wangt13 Apr 16 '23 at 04:56
  • @wangt13 where did you get SDL2? Did you build it yourself? Does it have directfb support enabled? Are you sure your qt application haven't grabbed both fb devices? If you only run your SDL application, could it display on first fb? (i guess not, so multi-display is irrelevant until this is resolved) – keltar Apr 16 '23 at 05:30
  • The SDL2 is packed in a buildroot environment provided by the vendor, so it is built during the software build process (downloading, compiling and installation in buildroot). From the lsof QT application, I can see /dev/fb0, no /dev/fb1. directfb and SDL2 directfb are NOT enabled, I will enable them and try. And I have NOT tried running SDL2 code without running QT, my assumption is the display might be messy when two applications are writing data to Framebuffer. I will also try it without running QT application – wangt13 Apr 16 '23 at 23:36

1 Answers1

1

With Keltar and David's comments, I finally worked it out.
I rebuilt target root filesystem with directfb and SDL2 with directfb.
After that, I set export SDL_VIDEODRIVER=directfb in the shell in the target.

Then I can start SDL2 example, which can draw window and do redendering in the window.

This is what I expected.

wangt13
  • 959
  • 7
  • 17