Manage OpenGL loader in opengl2 back-end #3736

Closed
opened 2021-01-20 15:31:36 +00:00 by rtoumazet · 3 comments
rtoumazet commented 2021-01-20 15:31:36 +00:00 (Migrated from github.com)

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

**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](https://user-images.githubusercontent.com/34705093/105192616-96b9fe80-5b38-11eb-94dd-b655339ae1ef.png) Thanks for reading me :)
ocornut commented 2021-01-20 15:35:46 +00:00 (Migrated from github.com)

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?

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 commented 2021-01-20 15:50:16 +00:00 (Migrated from github.com)

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.

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 commented 2021-01-20 15:58:29 +00:00 (Migrated from github.com)

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

Changing calls to use imgui_impl_opengl3 works fine when defining `#define GLFW_INCLUDE_NONE`. I guess that's it for this one :)
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#3736
No description provided.