Search code examples
qtopenglraspbianraspberry-pi2qtopengl

Qt OpenGl context on raspberry pi


I'm writing a program that with Qt5 opengl context. It works well on my desktop (fedora 23). But i have to run it on the pi 2. So i download Qt5 every where source code and compiled it natively on the pi. When i tried to compile and run my program on the pi it throws following error:

QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled

In Qt forums i saw that in Raspberry pi XCB cant integrate with egl in anyway. Also when i was configuring Qt source codes the EGL on x option was no. But GLX was enabled. Is there anyway to set QXcbIntegration to use GLX on the pi?

I was trying to fix XCB and egl integration. So i tried to recompile egl-x11 test in config.tests/qpa directory of qtbase to see the errors. Output was:

g++ -c -pipe -O2 -Wall -W -fPIC  -I. -isystem /usr/include/libdrm -I../../../mkspecs/linux-g++ -o egl-x11.o egl-x11.cpp
egl-x11.cpp: In function ‘int main(int, char**)’:
egl-x11.cpp:47:20: error: invalid conversion from ‘EGLNativeDisplayType {aka void*}’ to ‘Display* {aka _XDisplay*}’ [-fpermissive]
egl-x11.cpp:49:11: error: invalid conversion from ‘EGLNativeDisplayType {aka void*}’ to ‘Display* {aka _XDisplay*}’ [-fpermissive]
egl-x11.cpp:50:79: error: invalid conversion from ‘Window {aka long unsigned int}’ to ‘EGLNativeWindowType {aka void*}’ [-fpermissive]
egl-x11.cpp:51:26: error: invalid conversion from ‘EGLNativeWindowType {aka void*}’ to ‘Window {aka long unsigned int}’ [-fpermissive]
/usr/include/X11/Xlib.h:2251:12: error:   initializing argument 2 of ‘int XDestroyWindow(Display*, Window)’ [-fpermissive]
Makefile:530: recipe for target 'egl-x11.o' failed
make: *** [egl-x11.o] Error 1

Is there any way to fix the XCB and EGL integration?

If neither EGL nor GLX integration is possible on raspberry pi what can i do to run my application on the pi?


Solution

  • You'll need to have a Raspberry Pi 2. And you'll have to recompile the Qt library for it.

    It'll run using Qt EGLFS platform integration that uses EGL. Which means one fullscreen Qt application, no desktop environment.

    Haven't built the library on raspberry, but I've done the cross-compile of the Qt library. It requires a raspberry sysroot to configure Qt against it:

    ./configure -opengl es2 -device linux-rasp-pi2-g++ -sysroot "$R" -opensource -confirm-license -optimized-qmake -reduce-exports -release -make libs -make tools ... <lots of other options>
    

    If the correct stuff is installed in the sysroot, it will detect and configure correctly.