Skip to content

Commit

Permalink
Add macOS support
Browse files Browse the repository at this point in the history
Fixed OpenGL incompatibility, fixed setting window icon on macOS (results in exception), fixed INSTALL_RPATH in CMakeList
  • Loading branch information
jonas-s-s-s committed Nov 25, 2024
1 parent 2d11223 commit ae51d11
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 19 additions & 5 deletions src/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ae51d11

Please sign in to comment.