From c0c1e8be744bfeda2b48dc8724775d193af579f3 Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Sun, 23 Jul 2023 17:46:53 +0200 Subject: [PATCH] feat: open window with GLFW on Windows --- CMakeLists.txt | 16 ++++++++++++++-- hello.cpp | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 303e443..84a4227 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,17 @@ cmake_minimum_required(VERSION 3.27) +project(HelloGLFW) -project(HelloWorld) +# Define platform-specific paths and libraries +if(WIN32) + set(GLFW_PATH "C:/libs/glfw-3.3.8.bin.WIN64") + include_directories(${GLFW_PATH}/include) + link_directories(${GLFW_PATH}/lib-vc2022) +elseif(UNIX OR APPLE) + message(FATAL_ERROR "Linux and macOS platforms are not supported yet.") +endif() -add_executable(${PROJECT_NAME} hello.cpp) \ No newline at end of file +add_executable(${PROJECT_NAME} hello.cpp) + +if(WIN32) + target_link_libraries(${PROJECT_NAME} glfw3) +endif() \ No newline at end of file diff --git a/hello.cpp b/hello.cpp index 858a0c0..ff9c8f7 100644 --- a/hello.cpp +++ b/hello.cpp @@ -8,11 +8,39 @@ // cd build // cmake .. // cmake --build . +// The last step compiles the executable - this can also be done from Visual +// Studio -#include +// Install GLFW 3.3.8 +// https://www.glfw.org/download.html +// On Windows: +// extract the downloaded .zip file to "C:/libs"; this is currently expected +// by our CMakeLists.txt. + +// To run in VS +// Set startup project in Solution Explorer + +#include int main() { - std::cout << "Hello, World!" << std::endl; + if (!glfwInit()) + return -1; + + GLFWwindow* window = glfwCreateWindow(640, 480, "Hello GLFW", NULL, NULL); + if (!window) + { + glfwTerminate(); + return -1; + } + + glfwMakeContextCurrent(window); + + while (!glfwWindowShouldClose(window)) + { + glfwPollEvents(); + } + + glfwTerminate(); return 0; } \ No newline at end of file