diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 2137ae62..1039e96e 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -6,6 +6,7 @@ set_property(DIRECTORY PROPERTY CMAKE_CONFIGURE_DEPENDS aws-sdk-cpp.cmake date.cmake + glad.cmake hsluv-c.cmake imgui.cmake maplibre-native-qt.cmake @@ -16,6 +17,7 @@ set_property(DIRECTORY include(aws-sdk-cpp.cmake) include(date.cmake) +include(glad.cmake) include(hsluv-c.cmake) include(imgui.cmake) include(maplibre-native-qt.cmake) diff --git a/external/glad.cmake b/external/glad.cmake new file mode 100644 index 00000000..59ceb179 --- /dev/null +++ b/external/glad.cmake @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.24) +set(PROJECT_NAME scwx-glad) + +# Path to glad directory +set(GLAD_SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/glad/") + +# Path to glad CMake files +add_subdirectory("${GLAD_SOURCES_DIR}/cmake" glad_cmake) + +# Specify glad settings +glad_add_library(glad_gl_core_33 LOADER REPRODUCIBLE API gl:core=3.3) diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index c1dba7f2..7bd2d089 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -745,7 +745,7 @@ target_link_libraries(scwx-qt PUBLIC Qt${QT_VERSION_MAJOR}::Widgets GeographicLib::GeographicLib GEOS::geos GEOS::geos_cxx_flags - GLEW::GLEW + glad_gl_core_33 glm::glm imgui qt6ct-common @@ -753,7 +753,8 @@ target_link_libraries(scwx-qt PUBLIC Qt${QT_VERSION_MAJOR}::Widgets SQLite::SQLite3 wxdata) -target_link_libraries(supercell-wx PRIVATE scwx-qt +target_link_libraries(supercell-wx PRIVATE GLEW::GLEW + scwx-qt wxdata) if (LINUX) diff --git a/scwx-qt/source/scwx/qt/gl/gl.hpp b/scwx-qt/source/scwx/qt/gl/gl.hpp index 3361094b..ef5d0053 100644 --- a/scwx-qt/source/scwx/qt/gl/gl.hpp +++ b/scwx-qt/source/scwx/qt/gl/gl.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #define SCWX_GL_CHECK_ERROR() \ { \ diff --git a/scwx-qt/source/scwx/qt/gl/gl_context.cpp b/scwx-qt/source/scwx/qt/gl/gl_context.cpp index 4729eab5..8cdd08b4 100644 --- a/scwx-qt/source/scwx/qt/gl/gl_context.cpp +++ b/scwx-qt/source/scwx/qt/gl/gl_context.cpp @@ -57,21 +57,21 @@ void GlContext::Impl::InitializeGL() return; } - const GLenum error = glewInit(); - if (error != GLEW_OK) + const int gladVersion = gladLoaderLoadGL(); + if (!gladVersion) { - auto glewErrorString = - reinterpret_cast(glewGetErrorString(error)); - logger_->error("glewInit failed: {}", glewErrorString); + logger_->error("gladLoaderLoadGL failed"); QMessageBox::critical( - nullptr, - "Supercell Wx", - QString("Unable to initialize OpenGL: %1").arg(glewErrorString)); + nullptr, "Supercell Wx", "Unable to initialize OpenGL"); throw std::runtime_error("Unable to initialize OpenGL"); } + logger_->info("GLAD initialization complete: OpenGL {}.{}", + GLAD_VERSION_MAJOR(gladVersion), + GLAD_VERSION_MINOR(gladVersion)); + auto glVersion = reinterpret_cast(glGetString(GL_VERSION)); auto glVendor = reinterpret_cast(glGetString(GL_VENDOR)); auto glRenderer = reinterpret_cast(glGetString(GL_RENDERER)); @@ -86,7 +86,7 @@ void GlContext::Impl::InitializeGL() glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor); - if (major < 3 || (major == 3 && minor < 3)) + if (major < 3 || (major == 3 && minor < 3) || !GLAD_GL_VERSION_3_3) { logger_->error( "OpenGL 3.3 or greater is required, found {}.{}", major, minor);