From ae51d113595336c1956199459603ca1ec5ff7dc2 Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 25 Nov 2024 15:37:40 +0100 Subject: [PATCH] Add macOS support Fixed OpenGL incompatibility, fixed setting window icon on macOS (results in exception), fixed INSTALL_RPATH in CMakeList --- src/CMakeLists.txt | 2 +- src/gui/gui.cpp | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1d0844c6..6f9b0696 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,7 +64,7 @@ target_link_libraries(zero_mate if(NOT WIN32) set_target_properties(zero_mate PROPERTIES - INSTALL_RPATH "$ORIGIN" + INSTALL_RPATH "." BUILD_WITH_INSTALL_RPATH TRUE ) endif() diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index eda5a06b..f848c8c3 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -219,9 +219,17 @@ namespace zero_mate::gui return 1; } - // Set up GLFW window hints. - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + #if defined(__APPLE__) + // GL 3.2 + GLSL 150 + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac + #else + // Set up GLFW window hints. + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + #endif // Create a GLFW window. GLFWwindow* window = glfwCreateWindow(Window_Width, Window_Height, Window_Title, nullptr, nullptr); @@ -270,7 +278,11 @@ namespace zero_mate::gui // Init ImGUI GLFW with OpenGL implementation. ImGui_ImplGlfw_InitForOpenGL(window, true); - ImGui_ImplOpenGL3_Init("#version 130"); + #if defined(__APPLE__) + ImGui_ImplOpenGL3_Init("#version 150"); + #else + ImGui_ImplOpenGL3_Init("#version 130"); + #endif // Attempt to load a custom font and icons. if (std::filesystem::exists(config::Font_Path) && std::filesystem::exists(config::Icons_Path)) @@ -311,7 +323,9 @@ namespace zero_mate::gui // Make sure the logo was loaded successfully. if (images[0].pixels != nullptr) { - glfwSetWindowIcon(window, 1, images); + #if !defined(__APPLE__) + glfwSetWindowIcon(window, 1, images) + #endif } // Free the junk of allocated memory.