Dav1dde / glad

Multi-Language Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specs.
https://glad.dav1d.de/
Other
3.79k stars 448 forks source link

Building using CMake's FetchContent #397

Closed drsnuggles8 closed 1 year ago

drsnuggles8 commented 1 year ago

Hello, I'm trying to update from v0.1.36 to v2.0.2. Previously, I was adding glad to my project using FetchContent:

FetchContent_Declare(glad
    GIT_REPOSITORY https://github.com/Dav1dde/glad.git
    GIT_TAG v0.1.36)
set(GLAD_PROFILE "core" CACHE STRING "OpenGL profile")
set(GLAD_GENERATOR "c"  CACHE STRING "Language to generate the binding for")
FetchContent_MakeAvailable(glad)
target_include_directories(OloEngine PRIVATE ${GLAD_OUT_DIR}/include)
target_link_libraries(OloEngine glad)

However, this does not seem to work for the new version v2.0.2. How would this be doable?

Dav1dde commented 1 year ago

Unfortunately I am not very familar with CMake, there are some examples here and here, I hope this gives you what you need.

Other than that, if glad1 works for you and there isn't a new feature you want to use, there is no need to upgrade. glad 1 will still be updated if necessary.

drsnuggles8 commented 1 year ago

Ah yeah I had a look at those, it did not really help me. [#319] had some possible solution that I'll try. Is there a changelog showing which features got added in glad2? I might just stay with glad1, was just going through all my dependencies and checked if there are any new versions out.

Dav1dde commented 1 year ago

Is there a changelog showing which features got added in glad2?

Ah this should be in the README!

Quick Summary:

drsnuggles8 commented 1 year ago

Managed to get it working, I'll post my solution here just in case anyone else will look for it here.

FetchContent_Declare(glad
    GIT_REPOSITORY https://github.com/Dav1dde/glad.git
    GIT_TAG v2.0.2
    SOURCE_SUBDIR cmake)
FetchContent_MakeAvailable(glad)
glad_add_library(glad STATIC API gl:core=4.6 LOCATION ${PROJECT_SOURCE_DIR}/vendor/glad-build/${TARGET})
target_include_directories(OloEngine PRIVATE vendor/glad-build/include)
target_link_libraries(OloEngine glad)

Had to change some other code from #include <glad/glad.h> to #include <glad/gl.h> and change my old OpenGL initialization

const int status = ::gladLoadGLLoader(reinterpret_cast<GLADloadproc>(GLFWAPI::glfwGetProcAddress));
OLO_CORE_ASSERT(status, "Failed to initialize Glad!");

OLO_CORE_INFO("OpenGL Info:");
OLO_CORE_INFO("  Vendor: {0}", glGetString(GL_VENDOR));
OLO_CORE_INFO("  Renderer: {0}", glGetString(GL_RENDERER));
OLO_CORE_INFO("  Version: {0}", glGetString(GL_VERSION));

OLO_CORE_ASSERT(GLVersion.major > 4 || (GLVersion.major == 4 && GLVersion.minor >= 5), "OloEngine requires at least OpenGL version 4.5!");

to

const int version = ::gladLoadGL(reinterpret_cast<GLADloadfunc>(GLFWAPI::glfwGetProcAddress));
OLO_CORE_ASSERT(version, "Failed to initialize Glad!");

OLO_CORE_INFO("OpenGL Info:");
OLO_CORE_INFO("  Vendor: {0}", glGetString(GL_VENDOR));
OLO_CORE_INFO("  Renderer: {0}", glGetString(GL_RENDERER));
OLO_CORE_INFO("  Version: {0}", glGetString(GL_VERSION));

OLO_CORE_ASSERT(GLAD_VERSION_MAJOR(version) == 4 && GLAD_VERSION_MINOR(version) >= 5, "OloEngine requires at least OpenGL version 4.5!");