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

glbinding is not compatible with gl.h #310

Closed
Ashe opened this issue Jan 27, 2020 · 2 comments
Closed

glbinding is not compatible with gl.h #310

Ashe opened this issue Jan 27, 2020 · 2 comments

Comments

@Ashe
Copy link

Ashe commented Jan 27, 2020

I'm including glbinding as a subdirectory as part of my project and I'm trying to build the imgui example code found here.

I'm getting lots of errors and I'm really not well versed with all this as I'm just trying to get the basic example compiling so I can study it. The errors can be found in output.txt with the most notable error being: glbinding is not compatible with gl.h.

Here's how I'm including dependencies for cmake - I couldn't seem to use the find_package mechanism for glbinding and I prefer using git submodules anyway:

set(OpenGL_GL_PREFERENCE "GLVND")
find_package(OpenGL REQUIRED)

# GLFW
set(GLFW_BUILD_EXAMPLES                 OFF CACHE INTERNAL "")
set(GLFW_BUILD_TESTS                    OFF CACHE INTERNAL "")
set(GLFW_BUILD_DOCS                     OFF CACHE INTERNAL "")
set(GLFW_INSTALL                        OFF CACHE INTERNAL "")
add_subdirectory(glfw/)

# CPPLocate
set(cpplocate_DIR ${CMAKE_SOURCE_DIR}/deps/cpplocate/)
include(${CMAKE_SOURCE_DIR}/deps/cpplocate/cpplocate-config.cmake)
set(cpplocate_FOUND TRUE)

# GLBinding
set(BUILD_SHARED_LIBS                   ON  CACHE INTERNAL "")
set(OPTION_SELF_CONTAINED               OFF CACHE INTERNAL "")
set(OPTION_BUILD_TESTS                  OFF CACHE INTERNAL "")
set(OPTION_BUILD_DOCS                   OFF CACHE INTERNAL "")
set(OPTION_BUILD_TOOLS                  ON  CACHE INTERNAL "")
set(OPTION_BUILD_EXAMPLES               OFF CACHE INTERNAL "") 
set(OPTION_BUILD_WITH_BOOST_THREAD      OFF CACHE INTERNAL "")
set(OPTION_BUILD_CHECK                  OFF CACHE INTERNAL "")
add_subdirectory(glbinding/)

# GLEW
find_package(GLEW REQUIRED)

# GLM
set(GLM_TEST_ENABLE                     OFF CACHE INTERNAL "")
set(BUILD_SHARED_LIBS                   OFF CACHE INTERNAL "")
set(BUILD_STATIC_LIBS                   OFF CACHE INTERNAL "")
add_subdirectory(glm/)

# Imgui
include(imgui.cmake)

Maybe this issue has a simple solution, but I'm struggling to figure this out on my own when I haven't done any real programming myself in this project and I'm just trying to get things that should compile to work together. Any help would be appreciated and maybe this issue would help other beginners in this position! :)

@Ashe Ashe changed the title Lots of error messages about gl/enum.h glbinding is not compatible with gl.h Jan 27, 2020
@Ashe
Copy link
Author

Ashe commented Jan 27, 2020

Seems like a simple fix but maybe someone wants to chime in, I included glbinding headers before everything else and this seemed to fix the issues I was having! 🎉

@Ashe Ashe closed this as completed Jan 27, 2020
@scheibel
Copy link
Member

Short comment:
As this is somewhat a workaround, and especially with the use of GLFW, we suggest to use compiler directives to instruct GLFW to not include any OpenGL symbols.
This is somewhat described in this issue: cginternals/globjects#388.
The main objective for this workaround is the silencing of warnings but not the removal of misbehavior.

Detailed description:
One example: glbinding introduces a C++ static constant (an enum) for GL_TRUE with the value of a glbinding::Boolean8 instance representing the value true, i.e., 1. If you later include any version of gl.h, e.g., either through GLFW or GLEW, they declare a compile-time definition GL_TRUE with the value of 1.
When you later use glbinding code to reference the GL_TRUE constant, e.g., glbinding32core::GL_TRUE, the precompiler may convert this code to glbinding32core::1.
This depends on the order of includes and the latter is a compiler error.
Because of this, we check when including glbinding if the gl.h header was already included and issue a warning before compiler errors may occur.
With your workaround, glbinding cannot check anymore if it is used together with other variants of OpenGL bindings.

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

No branches or pull requests

2 participants