Version/Branch of Dear ImGui:
Version: Dear ImGui 1.74 WIP (17301)
Branch: master
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_sdl.cpp imgui_impl_opengl3.cpp
Compiler: gcc 8.3.0
Operating System: Raspbian GNU/Linux 10 (buster)
My Issue/Question:
I want to run sdl + opengl example on raspberry pi zero w, more exactly, I want to use the raspberry pi vc opengles 2.0, I have made some changes to use pi's brcmGLESv2, see (https://github.com/r18nix/imgui/commit/6cb36f0c25d0c1e0e6ed5a7cc375266f411fe08b).
but when I run ./example_sdl_opengl3, it says:
ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile vertex shader!
ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile fragment shader!
ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link shader program! (with GLSL '#version 100
I have tried some other glsl version string, The result is the same.
I'm not familiar with opengl, So what is wrong ? How can I get this working?
My changes are here https://github.com/r18nix/imgui/commit/6cb36f0c25d0c1e0e6ed5a7cc375266f411fe08b
Screenshots/Video
Standalone, minimal, complete and verifiable example:
I have upload my code to the link below
https://github.com/r18nix/imgui/tree/pizero
compile on raspberry pi zero , cd examples/example_sdl_opengl3 && make
Can you check if the code in imgui_impl_opengl3.cpp is compiling for ES2 properly and not for desktop opengl3 ?
Look at this block:
#if defined(IMGUI_IMPL_OPENGL_ES2)
if (glsl_version == NULL)
glsl_version = "#version 100";
#elif defined(IMGUI_IMPL_OPENGL_ES3)
if (glsl_version == NULL)
glsl_version = "#version 300 es";
#else
if (glsl_version == NULL)
glsl_version = "#version 130";
#endif
And add an #error statement in each to tell which one is actually being compiled.
Add #define IMGUI_IMPL_OPENGL_ES2 in your project or in imconfig.h
We could perhaps extra test to automatically enabled ES2 on Raspberry?
I have checked I am compiling for ES2 , I changed CXXFLAGS to CXXFLAGS += -D_REENTRANT -DIMGUI_IMPL_OPENGL_ES2 -I/usr/include/SDL2 -I/opt/vc/include/ in examples/example_sdl_opengl3/Makefile.
changes I have made to examples/example_sdl_opengl3/Makefile
diff --git a/examples/example_sdl_opengl3/Makefile b/examples/example_sdl_opengl3/Makefile
index 9e84df92..4ef206e8 100644
--- a/examples/example_sdl_opengl3/Makefile
+++ b/examples/example_sdl_opengl3/Makefile
@@ -47,9 +47,9 @@ CXXFLAGS += -I../libs/gl3w
ifeq ($(UNAME_S), Linux) #LINUX
ECHO_MESSAGE = "Linux"
- LIBS += -lGL -ldl `sdl2-config --libs`
+ LIBS += -L/opt/vc/lib -L/usr/lib/arm-linux-gnueabihf -lSDL2 -lm -lbrcmGLESv2 -lbrcmEGL -ldl
- CXXFLAGS += `sdl2-config --cflags`
+ CXXFLAGS += -D_REENTRANT -DIMGUI_IMPL_OPENGL_ES2 -I/usr/include/SDL2 -I/opt/vc/include/
CFLAGS = $(CXXFLAGS)
endif
here is my build output;
pi@raspberrypi:~/code/imgui/examples/example_sdl_opengl3 $ make
g++ -I../ -I../../ -g -Wall -Wformat -I../libs/gl3w -D_REENTRANT -DIMGUI_IMPL_OPENGL_ES2 -I/usr/include/SDL2 -I/opt/vc/include/ -c -o main.o main.cpp
g++ -I../ -I../../ -g -Wall -Wformat -I../libs/gl3w -D_REENTRANT -DIMGUI_IMPL_OPENGL_ES2 -I/usr/include/SDL2 -I/opt/vc/include/ -c -o imgui_impl_sdl.o ../imgui_impl_sdl.cpp
g++ -I../ -I../../ -g -Wall -Wformat -I../libs/gl3w -D_REENTRANT -DIMGUI_IMPL_OPENGL_ES2 -I/usr/include/SDL2 -I/opt/vc/include/ -c -o imgui_impl_opengl3.o ../imgui_impl_opengl3.cpp
g++ -I../ -I../../ -g -Wall -Wformat -I../libs/gl3w -D_REENTRANT -DIMGUI_IMPL_OPENGL_ES2 -I/usr/include/SDL2 -I/opt/vc/include/ -c -o imgui.o ../../imgui.cpp
g++ -I../ -I../../ -g -Wall -Wformat -I../libs/gl3w -D_REENTRANT -DIMGUI_IMPL_OPENGL_ES2 -I/usr/include/SDL2 -I/opt/vc/include/ -c -o imgui_demo.o ../../imgui_demo.cpp
g++ -I../ -I../../ -g -Wall -Wformat -I../libs/gl3w -D_REENTRANT -DIMGUI_IMPL_OPENGL_ES2 -I/usr/include/SDL2 -I/opt/vc/include/ -c -o imgui_draw.o ../../imgui_draw.cpp
g++ -I../ -I../../ -g -Wall -Wformat -I../libs/gl3w -D_REENTRANT -DIMGUI_IMPL_OPENGL_ES2 -I/usr/include/SDL2 -I/opt/vc/include/ -c -o imgui_widgets.o ../../imgui_widgets.cpp
cc -I../ -I../../ -g -Wall -Wformat -I../libs/gl3w -D_REENTRANT -DIMGUI_IMPL_OPENGL_ES2 -I/usr/include/SDL2 -I/opt/vc/include/ -c -o gl3w.o ../libs/gl3w/GL/gl3w.c
g++ -o example_sdl_opengl3 main.o imgui_impl_sdl.o imgui_impl_opengl3.o imgui.o imgui_demo.o imgui_draw.o imgui_widgets.o gl3w.o -I../ -I../../ -g -Wall -Wformat -I../libs/gl3w -D_REENTRANT -DIMGUI_IMPL_OPENGL_ES2 -I/usr/include/SDL2 -I/opt/vc/include/ -L/opt/vc/lib -L/usr/lib/arm-linux-gnueabihf -lSDL2 -lm -lbrcmGLESv2 -lbrcmEGL -ldl
Build complete for Linux
pi@raspberrypi:~/code/imgui/examples/example_sdl_opengl3 $
My changes is here https://github.com/r18nix/imgui/commit/6cb36f0c25d0c1e0e6ed5a7cc375266f411fe08b, plz ignore the changes in examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj.
My guess is you'll get a better answer asking in Raspberry+OpenGL communities, as it doesn't look like a dear imgui specific problem. Maybe Raspberry's OpenGL needs some kind of initialization?
If you find the solution it would be nice to post it here.
Also once confirmed that IMGUI_IMPL_OPENGL_ES2 is the right define to use for Raspberry it may be good to make that automatic by testing for suitable defines.
thanks advice. I will look for help in Raspberry communities, try to learning and find out what specific initialization(?) is needed on raspberry pi.
On raspberry pi zero, current master branch without any changes build ok, but you only get 1- 3 fps(opengl 3 is software implementation), other application using opengles 2(brcmGLESv2 ) can get 30fps or 60fps.
I got this raspberry pi zero few months ago,I don't want to waste such a expensive device.
Here is the instructions about how to using broadcom vc Accelerated Open GL ES2 on raspberry pi(<=3). the default sdl2 library did not build with rpi video driver, so you must rebuild sdl.
change pi's gl driver to legacy. by sudo raspi-config.
Uninstall the default sdl2 dev package , download the latest sdl source package, and compile with rpi video driver. you can disable all other video driver except --enable-video-rpi, or use export SDL_VIDEODRIVER=rpi before your program running. type ./configure --help | grep video to see the details. example build configure are:
sudo apt-get remove -y libsdl2-dev
wget https://www.libsdl.org/release/SDL2-2.0.9.tar.gz
tar xzvf SDL2-2.0.9.tar.gz
cd SDL2-2.0.9.tar.gz
./autogen.sh
./configure --disable-video-mir --disable-video-vulkan --disable-video-wayland --disable-video-opengl --disable-pulseaudio --disable-esd --prefix=`pwd`/sysroot
make && make install
git clone https://github.com/atmgnd/imgui.git
git checkout origin/rpi
cd imgui/examples/example_sdl_opengl3
make SDL2_CONFIG=/home/pi/code/build/SDL2-2.0.9/sysroot/bin/sdl2-config
note, you may change SDL2_CONFIG's value
$ ldd example_sdl_opengl3 | grep -E "GL|SDL"
libSDL2-2.0.so.0 => /your_latest_sdl/sysroot/lib/libSDL2-2.0.so.0 (0xb6e51000)
libbrcmGLESv2.so => /opt/vc/lib/libbrcmGLESv2.so (0xb6e2c000)
libbrcmEGL.so => /opt/vc/lib/libbrcmEGL.so (0xb6df3000)
export SDL_VIDEODRIVER=rpi
./example_sdl_opengl3
# or just
SDL_VIDEODRIVER=rpi ./example_sdl_opengl3
plus:
reference:
nuklear's opengles2 implementation
nuklear issuse: Add Raspberry Pi accelerated Open GL output
Amazing explanation, thank you @atmgnd .
I would like to open a Wiki page to describe this setup, and maybe the same Wiki page can be devoted to running imgui on small devices, with setup suggestions (disable rounding, borders, anti-aliasing, etc.)
Hello, I am going to delete the repo metioned above(https://github.com/atmgnd/imgui/tree/rpi). For some reason(reference ...), You can get it by download official imgui https://github.com/ocornut/imgui/archive/892dfb1dea65644b1c6f9882b9c883a837b18369.zip, and apply the patch below.
0001-enable-hardware-Open-GL-ES2-on-raspberry-pi-zero.zip
Hello, I am going to delete the repo metioned above(https://github.com/atmgnd/imgui/tree/rpi). For some reason(reference ...), You can get it by download official imgui https://github.com/ocornut/imgui/archive/892dfb1dea65644b1c6f9882b9c883a837b18369.zip, and apply the patch below.
0001-enable-hardware-Open-GL-ES2-on-raspberry-pi-zero.zip
I tried to follow the instuctions you listed. I made changes as per the patch. I could get to compile. But when I run using
SDL_VIDEODRIVER=rpi ./example_sdl_opengl3
I get output on console as
Compiled
Compiled
I do not see any window or error.
If I do like
./example_sdl_opengl3
I get same error
ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to comp^CERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile vertex shader!
ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile fragment shader!
ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link shader program! (with GLSL '#version 100
I also followed the instructions on unmerged branch on imgui repo (Rpi), I get same result.
Is there an existing solution to using RPI 3b+ with imgui? since that pr is not merged, is there not solution?
@readblack1234, this link may be of help -- getting the very fine hello_imgui boilerplate running on raspberry pi 0,1,2,3 with the original broadcom drivers -- https://github.com/zertyz/hello_imgui_rpi
you may look specifically at the patch files and translate them back to the original imgui project -- the patched files are very similar between these two projects.
@readblack1234 have you tried steps in the pull request #2837?
That works for me on both, rpi3 and rpi zero.
Most helpful comment
Hello, I am going to delete the repo metioned above(https://github.com/atmgnd/imgui/tree/rpi). For some reason(reference ...), You can get it by download official imgui https://github.com/ocornut/imgui/archive/892dfb1dea65644b1c6f9882b9c883a837b18369.zip, and apply the patch below.
0001-enable-hardware-Open-GL-ES2-on-raspberry-pi-zero.zip