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

Examples: Add OpenGL ES 2.0 support to SDL2 and GLFW examples #3951

Conversation

lethal-guitar
Copy link
Contributor

@lethal-guitar lethal-guitar commented Mar 20, 2021

The modern OpenGL backend (imgui_impl_opengl3) already supports OpenGL ES via the IMGUI_IMPL_OPENGL_ES2 define. But the SDL + OpenGL example (example_sdl_opengl3) only supports Desktop GL so far.

This PR adds support for OpenGL ES 2.0 to the SDL + OpenGL example on Linux. To keep things simple in the Makefile, I followed how the different GL loaders are configured, by adding commented out lines that can be enabled (instead of the default gl3w loader config) to build for GL ES.

The motivation for this PR is supporting the Raspberry Pi and other Linux-based SBC devices, therefore I limited the changes to Linux and OpenGL ES 2.0 as that seems like a good start.

See #2837 for more background and discussion.

@ocornut
Copy link
Owner

ocornut commented Mar 20, 2021

Thank for the PR and explanation!
Do you think the matching GLFW example should be updated as well? Regardless of whether GLFW works on RPI (i don’t know) it would seem sane to have those same modifications done so the examples stay in sync?

@lethal-guitar
Copy link
Contributor Author

lethal-guitar commented Mar 20, 2021

Ah yeah good point, that example is very similar. So keeping it in sync sounds reasonable. I don't have much experience with glfw and don't know if it supports the Raspberry Pi either, but it seems to support GL ES from a quick glance at the documentation so that makes sense to do the same modifications there.

@ocornut
Copy link
Owner

ocornut commented Mar 22, 2021

Thank you.
Could you rework the PR to include GLFW?
I don't have a GL ES setup here so if I did it I wouldn't be able to test the changes.

I also suggest using

#if defined() 
...
#elif defined()
...
#endif

Preprocessor block to avoid adding an extra level of #endif

Thank you!

@lethal-guitar
Copy link
Contributor Author

Could you rework the PR to include GLFW?

Will do! 👍🏻

@lethal-guitar lethal-guitar changed the title Examples: Add OpenGL ES 2.0 support to SDL2 example Examples: Add OpenGL ES 2.0 support to SDL2 and GLFW examples Mar 25, 2021
@lethal-guitar
Copy link
Contributor Author

@ocornut I adapted the GLFW example, and also changed the preprocessor bits as you suggested.

I successfully ran the GLFW example in GL ES mode on my Raspberry Pi 3 using the KMS driver, and on my Linux Desktop using the MESA OpenGL ES library (by installing libgles2-mesa-dev).

However, it doesn't seem possible to use GLFW without an X server. That means it's not possible to run with the Raspberry Pi legacy driver, unlike SDL. Therefore, I didn't include the corresponding build flags in the GLFW Makefile, only in the SDL Makefile. I also wasn't able to test on my other GL ES based devices (Odroid Go Advance/Super) since these don't have X installed at all.

@ocornut
Copy link
Owner

ocornut commented Mar 26, 2021

Merged, thank you!

@ocornut ocornut closed this Mar 26, 2021
@lethal-guitar lethal-guitar deleted the opengl-example-gles-support branch March 26, 2021 13:04
@hinxx
Copy link

hinxx commented Mar 26, 2021

Looks like I missed the train for a little amendment to the PR. For the record.

I was testing the cross compilation of the ImGui and managed to get is done using this little patch:

--- a/examples/example_sdl_opengl3/Makefile
+++ b/examples/example_sdl_opengl3/Makefile
@@ -63,6 +63,8 @@ CXXFLAGS += -I../libs/gl3w -DIMGUI_IMPL_OPENGL_LOADER_GL3W
 # LINUX_GL_LIBS = -lGLESv2
 ## If you're on a Raspberry Pi, use the following instead:
 # LINUX_GL_LIBS = -L/opt/vc/lib -lbrcmGLESv2
+## If you're cross-compiling for Raspberry Pi, use the following instead:
+# LINUX_GL_LIBS = -L$(RPIROOT)/opt/vc/lib -lbrcmGLESv2 `sdl2-config --static-libs`

So, a user cross compiling would uncomment the last LINUX_GL_LIBS. RPIROOT is the Pi image mount point. The rest (CC, CXX) would be defined outside of the Makefile (on the command line or script).

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

Successfully merging this pull request may close these issues.

3 participants