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

Manage OpenGL loader in opengl2 back-end #3736

Closed
rtoumazet opened this issue Jan 20, 2021 · 3 comments
Closed

Manage OpenGL loader in opengl2 back-end #3736

rtoumazet opened this issue Jan 20, 2021 · 3 comments

Comments

@rtoumazet
Copy link

Version/Branch of Dear ImGui:

Version: 1.79 (through vcpkg)
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl2.cpp + imgui_impl_glfw.cpp
Compiler: Visual Studio 2019
Operating System: Windows 10

My Issue/Question:

Using an OpenGL loader with this configuration (opengl2 + glfw + glbinding in my specific case) leads to multiple inclusion of OpenGL functions.
Commenting #include <GL/gl.h> in imgui_impl_opengl2.cpp was working when including the files directly in the project, but with vcpkg it's not an option anymore.

In imgui_impl_opengl3.cpp various defines (like IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) are used to automatically handle the loaders, maybe something similar yet simpler could be applied in the present case ?
I'm not sure of the right way to do this (reuse an existing define, create a new one, something else ?).

Relevant code in imgui_impl_opengl2.cpp :

// Include OpenGL header (without an OpenGL loader) requires a bit of fiddling
#if defined(_WIN32) && !defined(APIENTRY)
#define APIENTRY __stdcall                  // It is customary to use APIENTRY for OpenGL function pointer declarations on all platforms.  Additionally, the Windows OpenGL header needs APIENTRY.
#endif
#if defined(_WIN32) && !defined(WINGDIAPI)
#define WINGDIAPI __declspec(dllimport)     // Some Windows OpenGL headers need this
#endif
#if defined(__APPLE__)
#define GL_SILENCE_DEPRECATION
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

Here's my declaration :

#include <glbinding/gl21/gl.h>
#include <glbinding/gl21ext/gl.h>
#include <glbinding/glbinding.h>

#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl2.h>
#include <GLFW/glfw3.h>

using namespace gl21;
using namespace gl21ext;

And the error message :
image

Thanks for reading me :)

@ocornut
Copy link
Owner

ocornut commented Jan 20, 2021

If I have to be honest, dealing with OpenGL loaders seems like a never-ending quagmire of issues :( and at some point we should leave it to users to copy and paste those files. It's not my responsibility if vcpkg decide to package libraries that are not designed to be packaged, but I'm willing to help fix things if we can do it with reasonable effort.

HOWEVER
I must state that imgui_impl_opengl2 and imgui_impl_opengl3 are incorrectly named.
If you are using glbinding/ with a 2.1 context you may be able to use imgui_impl_opengl3. Can you investigate this path?

@rtoumazet
Copy link
Author

Wow ... you're lightning fast to answer :)

I'll investigate this path for sure .. actually I already did that a bit in the past (check issue #1513), but I'm no longer in possession of the laptop that triggered the original problem, so I guess I'll be just as good to forget opengl2 now :)

Thanks for your reply.

@rtoumazet
Copy link
Author

Changing calls to use imgui_impl_opengl3 works fine when defining #define GLFW_INCLUDE_NONE.
I guess that's it for this one :)

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

2 participants