Search code examples
craspberry-piframebufferxorg

Is there a way to config xorg to use a framebuffer device as the primary monitor?


I have a Raspberry Pi with a GPIO display. I currently have it set up as a framebuffer device at /dev/fb1. Is there a way to make it my default or primary display for X windows? I'm ultimately trying to draw graphics to it, I was originally planning on using DirectFB and SDL, but DirectFB is in alpha for the pi. I've tried using SDL1.2 as well since it has Framebuffer support, but I can't figure out how to get SDL to choose a framebuffer device to draw to without using DirectFB.

I considered using SDL to prepare each frame of my simple GUI as a raw image and use mmap to blit it to /dev/fb1 instead of using SDL's built in draw functions, but I feel like this is a poor way to achieve my goal.

I think that if I can get xorg to use my framebuffer device as the primary monitor, I wouldn't have to worry about doing anything special to have SDL draw my image files. But I'm not really sure how xorg really works and if this is possible.

Any insight or help anyone has would greatly help! I've been butting heads with this problem for a week looking at different possibilities.


Solution

  • With SDL2 on Raspbian you can draw directly on a framebuffer without using X at all. The graphical window is always full screen. You can start the code from console mode (with X stopped or from LXDE with X running, the idea is that SDL2 won't use X).

    Unfortunately, Raspbian doesn't come with SDL2 (the SDL2 from Jessie doesn't work) so you will need to build it yourself (takes about an hour). Here is a description of the process of building SDL2:

    sudo apt-get install build-essential libfreeimage-dev libopenal-dev libpango1.0-dev libsndfile-dev libudev-dev libasound2-dev
    

    Download the sources for SDL2 from https://www.libsdl.org/download-2.0.php . Assuming that your downloaded file is called SDL2*.tar.gz, you can build and install it with:

    cd ~/Downloads
    tar zxvf SDL2*.tar.gz
    cd SDL2*
    
    ./configure --disable-video-x11
    make
    sudo make install
    

    After that, you should be able to link any C++ program with SDL2, e.g:

    g++ my_program.cpp -lSDL2 -o my_program
    ./my_program