This is related to an earlier question "eglGetDisplay() fails on RaspBerry 3". On Raspbian Stretch with the full OpenGL driver, running hello_triangle or other GLES examples under /opt/vc/src/hello_pi/ results in:

failed to add service - already in use?

Per the Stack Overflow link below, this can be worked around by commenting out dtoverlay=vc4-kms-v3d in config.txt. Unfortunately that disables OpenGL, leading to odd configuration restrictions like being unable to run both Quake 3 and full Minecraft without rebooting.

How can I fix this in the source code of GLES apps while still linking with the Broadcom VideoCore GLES/EGL libraries? Note that although such apps could be ported to avoid dispmanx and use the Mesa open-source driver instead, performance would take a hit.

minecraft-pi doesn't have this error so it should be possible, but it would take some effort to step through that closed-source application. Maybe someone knows a working example with source code?


1 Answer 1


One Minecraft Pi Edition (MCPI) user had reported this error appearing with a patched minecraft-pi but not the original. This suggested /usr/bin/minecraft-pi may be more than just a symlink, and it turns out to be a helper script. It appears the Raspbian maintainers installed a wrapper for libbcm_host using the LD_PRELOAD trick to keep MCPI running in both configurations.

The tiny helper library /opt/minecraft-pi/lib/mesa/libbcm_host.so.1.0 depends on SDL for window creation. hello_triangle can be ported to make use of it with the following minimal changes:

@@ -39,6 +39,7 @@
 #include "GLES/gl.h"
 #include "EGL/egl.h"
 #include "EGL/eglext.h"
+#include "SDL/SDL.h"

@@ -527,6 +528,8 @@

 int main ()
+   SDL_SetVideoMode(640, 480, 0, 0);

To resolve linker dependencies, run sudo apt install libsdl1.2-dev, add -lSDL to LDFLAGS while changing -lbrcmEGL -lbrcmGLESv2 to -lEGL -lGLESv2 in ../Makefile.include, and run the command-line in the same manner as the MCPI shim:

LD_PRELOAD=/opt/minecraft-pi/lib/mesa/libbcm_host.so.1.0 \
  LD_LIBRARY_PATH=/opt/minecraft-pi/lib/mesa \

It's then straightforward to make a selection script similar to /usr/bin/minecraft-pi, which works by checking /proc/device-tree/soc/v3d@7ec00000/status

Caveat: Now that it's evident this path doesn't actually run the old closed-source driver, rendering performance won't be any better than if these examples were fully ported to use standard headers. The remaining benefits are that we can build applications with runtime support for both modes (like MCPI), and Raspbian's built-in GLES examples become a little more usable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.