From 4c94e0f047a9583286d58036a4a92d46dc810a7f Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Sun, 23 Jul 2023 18:21:44 +0200 Subject: [PATCH] feat: add OpenGL window on Windows --- CMakeLists.txt | 7 ++++++- hello.cpp | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 84a4227..201cc05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,15 @@ cmake_minimum_required(VERSION 3.27) -project(HelloGLFW) +project(HelloOpenGL) # Define platform-specific paths and libraries if(WIN32) + # GLFW set(GLFW_PATH "C:/libs/glfw-3.3.8.bin.WIN64") include_directories(${GLFW_PATH}/include) link_directories(${GLFW_PATH}/lib-vc2022) + + # OpenGL + find_package(OpenGL REQUIRED) elseif(UNIX OR APPLE) message(FATAL_ERROR "Linux and macOS platforms are not supported yet.") endif() @@ -14,4 +18,5 @@ add_executable(${PROJECT_NAME} hello.cpp) if(WIN32) target_link_libraries(${PROJECT_NAME} glfw3) + target_link_libraries(${PROJECT_NAME} OpenGL::GL) endif() \ No newline at end of file diff --git a/hello.cpp b/hello.cpp index ff9c8f7..ea8bb5f 100644 --- a/hello.cpp +++ b/hello.cpp @@ -21,13 +21,14 @@ // Set startup project in Solution Explorer #include +#include int main() { if (!glfwInit()) return -1; - GLFWwindow* window = glfwCreateWindow(640, 480, "Hello GLFW", NULL, NULL); + GLFWwindow* window = glfwCreateWindow(640, 480, "Hello GL", NULL, NULL); if (!window) { glfwTerminate(); @@ -38,6 +39,11 @@ int main() while (!glfwWindowShouldClose(window)) { + glClearColor(1.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glfwSwapBuffers(window); + glfwPollEvents(); }