Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imgui on Raspberry pi, brcmGLESv2 error, blank #2822

Closed
r18nix opened this issue Oct 2, 2019 · 11 comments
Closed

imgui on Raspberry pi, brcmGLESv2 error, blank #2822

r18nix opened this issue Oct 2, 2019 · 11 comments

Comments

@r18nix
Copy link

r18nix commented Oct 2, 2019

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
IMG_0549

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

@ocornut
Copy link
Owner

ocornut commented Oct 2, 2019

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?

@ocornut ocornut added the opengl label Oct 2, 2019
@r18nix
Copy link
Author

r18nix commented Oct 2, 2019

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 $ 

@r18nix
Copy link
Author

r18nix commented Oct 2, 2019

My changes is here https://github.com/r18nix/imgui/commit/6cb36f0c25d0c1e0e6ed5a7cc375266f411fe08b, plz ignore the changes in examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj.

@ocornut
Copy link
Owner

ocornut commented Oct 2, 2019

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.

@r18nix
Copy link
Author

r18nix commented Oct 2, 2019

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.

@atmgnd
Copy link

atmgnd commented Oct 3, 2019

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.

  1. change pi's gl driver to legacy. by sudo raspi-config.

  2. 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
  1. check out my branch(https://github.com/atmgnd/imgui/tree/rpi), I made some changes to imgui (today master branch).
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

  1. check the output binary linked to the right libraries.
$ 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)
  1. running.
export SDL_VIDEODRIVER=rpi
./example_sdl_opengl3
# or just
SDL_VIDEODRIVER=rpi ./example_sdl_opengl3

plus:

  1. ther is a new experimental opensource gl driver (fkms) have been released for raspberry pi. but I see it's is still experimental, and on some pi, you get worse experience if you are using the new fkms driver, like pi zero.
  2. You may enable imgui to draw the mouse shape. by using rpi video driver, there is only one arrow cursor in sdl(I am not sure!!).

reference:
nuklear's opengles2 implementation
nuklear issuse: Add Raspberry Pi accelerated Open GL output

@r18nix r18nix closed this as completed Oct 3, 2019
@ocornut
Copy link
Owner

ocornut commented Oct 3, 2019

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.)

@atmgnd
Copy link

atmgnd commented Jan 11, 2020

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

@readblack1234
Copy link

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?

@zertyz
Copy link

zertyz commented Aug 8, 2020

@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.

@hinxx
Copy link

hinxx commented Aug 8, 2020

@readblack1234 have you tried steps in the pull request #2837?
That works for me on both, rpi3 and rpi zero.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants