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

Questions about Desktop OpenGL loaders #4390

Closed
NancyLi1013 opened this issue Aug 3, 2021 · 7 comments
Closed

Questions about Desktop OpenGL loaders #4390

NancyLi1013 opened this issue Aug 3, 2021 · 7 comments

Comments

@NancyLi1013
Copy link

Version/Branch of Dear ImGui:

Version: 1.83
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl3.cpp
Compiler: GCC 11.1.0
Operating System: Ubuntu 18.04

My Issue/Question:

When using imgui in vcpkg, we found that imgui failed to compile with the following errors(Please see the details in Screenshots/Video part). Through investigation, we noticed that it seems like there is only one OpenGL loader supported for once in imgui_impl_opengl3.h.
https://github.com/ocornut/imgui/blob/f99fe72c42bd5d578c2443409192b139b1c6623d/backends/imgui_impl_opengl3.h#L48-#L83

Could you please help confirm if these OpenGL loaders are mutually exclusive each other?

Thanks in advance.

Screenshots/Video

[build] : && /bin/x86_64-linux-gnu-g++-11 -g  CMakeFiles/hello.dir/main.cpp.o -o hello  /home/dylan/repositories/github/Microsoft/vcpkg/installed/x64-linux/debug/lib/libimguid.a  /home/dylan/repositories/github/Microsoft/vcpkg/installed/x64-linux/debug/lib/libglad.a  /home/dylan/repositories/github/Microsoft/vcpkg/installed/x64-linux/debug/lib/libglfw3.a  /usr/lib/x86_64-linux-gnu/librt.so  -lm  -ldl  /usr/lib/x86_64-linux-gnu/libX11.so  -lpthread && :
[build] /usr/bin/ld: /home/dylan/repositories/github/Microsoft/vcpkg/installed/x64-linux/debug/lib/libimguid.a(imgui_impl_opengl3.cpp.o): in function `ImGui_ImplOpenGL3_Init(char const*)':
[build] /home/dylan/repositories/github/Microsoft/vcpkg/buildtrees/imgui/src/v1.83-af20d68e6e.clean/backends/imgui_impl_opengl3.cpp:163: undefined reference to `glGetIntegerv'
[build] /usr/bin/ld: /home/dylan/repositories/github/Microsoft/vcpkg/buildtrees/imgui/src/v1.83-af20d68e6e.clean/backends/imgui_impl_opengl3.cpp:164: undefined reference to `glGetIntegerv'
[build] /usr/bin/ld: /home/dylan/repositories/github/Microsoft/vcpkg/buildtrees/imgui/src/v1.83-af20d68e6e.clean/backends/imgui_impl_opengl3.cpp:168: undefined reference to `glGetString'
[build] /usr/bin/ld: /home/dylan/repositories/github/Microsoft/vcpkg/buildtrees/imgui/src/v1.83-af20d68e6e.clean/backends/imgui_impl_opengl3.cpp:232: undefined reference to `glGetIntegerv'
[build] /usr/bin/ld: /home/dylan/repositories/github/Microsoft/vcpkg/installed/x64-linux/debug/lib/libimguid.a(imgui_impl_opengl3.cpp.o): in function `ImGui_ImplOpenGL3_SetupRenderState(ImDrawData*, int, int, unsigned int)':
[build] /home/dylan/repositories/github/Microsoft/vcpkg/buildtrees/imgui/src/v1.83-af20d68e6e.clean/backends/imgui_impl_opengl3.cpp:251: undefined reference to `glEnable'
[build] /usr/bin/ld: /home/dylan/repositories/github/Microsoft/vcpkg/buildtrees/imgui/src/v1.83-af20d68e6e.clean/backends/imgui_impl_opengl3.cpp:252: undefined reference to `__glewBlendEquation'
[build] /usr/bin/ld: /home/dylan/repositories/github/Microsoft/vcpkg/buildtrees/imgui/src/v1.83-af20d68e6e.clean/backends/imgui_impl_opengl3.cpp:253: undefined reference to `__glewBlendFuncSeparate'

Standalone, minimal, complete and verifiable example: (see #2261)

// Here's some code anyone can copy and paste to reproduce your issue
main.cpp:

#include <glad/glad.h>
#include <imgui_impl_opengl3.h>

int main()
{
  ImGui_ImplOpenGL3_Init();
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.18)
project(hello)

find_package(glad CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)

add_executable(hello main.cpp)
target_link_libraries(hello PRIVATE glad::glad imgui::imgui)
@NancyLi1013
Copy link
Author

Related issue in vcpkg:
microsoft/vcpkg#19231
microsoft/vcpkg#14753

@ocornut
Copy link
Owner

ocornut commented Aug 3, 2021 via email

@ocornut
Copy link
Owner

ocornut commented Aug 3, 2021

From vcpkg point of view, each loader should be its own library and the user should still be responsible for initializing it.

There are two ways you could go about this. If you can somehow detect that GLAD is being used then vcpkg could define
IMGUI_IMPL_OPENGL_LOADER_GLAD.
Otherwise it would need a dummy library eg “-loader-glad” that would both set this define and drag the actual GLAD library.

I’m tempted to recommend we could investigate the solution of embedding our own loader and not supporting/requiring a user loader…. Would simplify many things for users (with and without vcpkg).

@ocornut
Copy link
Owner

ocornut commented Aug 3, 2021

If we decided that imgui_impl_opengl3 always initialized the loader it knows about, it would mean that a system like vcpkg could also decide that adding imgui_impl_opengl3 would automatically drag and enforce a certain loader (whichever you choose) and set the define for it, user won’t have an extra init call to do.

Even if user app used another loader it would work then.

@NancyLi1013
Copy link
Author

@ocornut

Thanks for your so detailed information and suggestion to solve the problem. I think we should set the define for it according to a certain loader.

@ocornut
Copy link
Owner

ocornut commented Aug 18, 2021

Update: we decided to bite the bullet and we (and by we I mean @rokups) are working toward embedding our own minimalist OpenGL loader into the backend, in order to put in end to that endless amount of confusion/misery caused by the OpenGL loaders.

We already have a version working and we'll either aim to use it in 1.84 or right after 1.84 is released.

TL;DR; ihmo don't put effort into solving this on your end now.

@ocornut
Copy link
Owner

ocornut commented Aug 19, 2021

Should now be solved and made much simpler by #4445

@ocornut ocornut closed this as completed Aug 19, 2021
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