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

Automatically include the available gl loader header #2798

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/imgui_impl_opengl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
strcpy(g_GlslVersionString, glsl_version);
strcat(g_GlslVersionString, "\n");

// Dummy constructs to make it easily visible in the IDE and debugger which GL loader has been selected.
// if you have multiple GL loaders header files accessible to the compiler, the auto detection block in
// imgui_impl_opengl3.h may have chosen the wrong one !!
// Use an explicit '#define IMGUI_IMPL_OPENGL_LOADER_XXX' line in imconfig.h or compiler command-line to enforce a certain GL loader.
const char* gl_loader = "Unknown";
IM_UNUSED(gl_loader);
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
gl_loader = "GL3W";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
gl_loader = "GLEW";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
gl_loader = "GLAD";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
gl_loader = "Custom";
#endif
// Make a dummy GL call (we don't actually need the result)
// IF YOU GET A CRASH HERE: it probably means that you haven't initialized the OpenGL function loader used by this code.
// Desktop OpenGL 3/4 need a function loader. See the IMGUI_IMPL_OPENGL_LOADER_xxx explanation above.
Expand Down
33 changes: 32 additions & 1 deletion examples/imgui_impl_opengl3.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,38 @@
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \
&& !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
#define IMGUI_IMPL_OPENGL_LOADER_GL3W
// to avoid problem with non-clang compilers not having this macro.
#if defined(__has_include)
// check if the header exists, then automatically define the macros ..
// check if glew gl loader exists, use it
#if __has_include(<GL/glew.h>)
// make sure we don't have another gl loader headers ....
// that means that the user might have used one and initialized it
// while we use the other ....
// so we make sure there is only one gl loader header
// in this case, we need to only have glew headers and not glad !
#if __has_include(<glad/glad.h>)
#error you have multiple headers in your system (GLEW + GLAD), remove one of them or use '#define IMGUI_IMPL_OPENGL_LOADER_GLEW'
#else
#define IMGUI_IMPL_OPENGL_LOADER_GLEW
#endif
#elif __has_include(<glad/glad.h>)
// make sure we don't have another gl loader headers ....
// that means that the user might have used one and initialized it
// while we use the other ....
// so we make sure there is only one gl loader header
// in this case, we need to only have glad headers and not glew !
#if __has_include(<GL/glew.h>)
#error you have multiple headers in your system (GLEW + GLAD), remove one of them or use '#define IMGUI_IMPL_OPENGL_LOADER_GLAD'
#else
#define IMGUI_IMPL_OPENGL_LOADER_GLAD
#endif
#else
#define IMGUI_IMPL_OPENGL_LOADER_GL3W
#endif
#else
#define IMGUI_IMPL_OPENGL_LOADER_GL3W
#endif
#endif

IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL);
Expand Down