From b12be852a82a0439fcad4da47854efa118527ac1 Mon Sep 17 00:00:00 2001 From: KerelOlivier Date: Sat, 16 Apr 2022 02:36:48 +0200 Subject: [PATCH] setup opengl window --- CMakeLists.txt | 12 +++++++++++- main.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b09192..ee14a08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,4 +3,14 @@ project(Voronoi_2) set(CMAKE_CXX_STANDARD 20) -add_executable(Voronoi_2 main.cpp src/datastructures/Beachline.cpp src/datastructures/Beachline.h src/datastructures/DCEL.cpp src/datastructures/DCEL.h src/types/point.h src/types/event.h src/types/node.h src/utils/intersection.h src/utils/circle.h) +find_package(glfw3 3.3 REQUIRED) + + +add_executable(Voronoi_2 main.cpp src/datastructures/Beachline.cpp + src/datastructures/Beachline.h src/datastructures/DCEL.cpp + src/datastructures/DCEL.h src/types/point.h + src/types/event.h src/types/node.h + src/utils/intersection.h src/utils/circle.h glad.c) +include_directories(./includes) + +target_link_libraries(Voronoi_2 glfw) diff --git a/main.cpp b/main.cpp index 0ab7f9b..7054659 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,48 @@ #include +#include +#include + +void framebuffer_size_callback(GLFWwindow* window, int width, int height); + int main() { std::cout << "Hello, World!" << std::endl; + + glfwInit(); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); + + GLFWwindow* window = glfwCreateWindow(800, 600, "Voronoi", NULL, NULL); + if (window == NULL) { + std::cout << "Failed to create GLFW window" << std::endl; + glfwTerminate(); + return -1; + } + glfwMakeContextCurrent(window); + + if(gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) == 0) { + std::cout << "Failed to initialize GLAD" << std::endl; + return -1; + } + + glViewport(0, 0, 800, 600); + + glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); + + while(!glfwWindowShouldClose(window)) { + glfwPollEvents(); + glClearColor(0.2f, 0.3f, 0.3f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glfwSwapBuffers(window); + } + + return 0; } + +void framebuffer_size_callback(GLFWwindow* window, int width, int height) { + glViewport(0, 0, width, height); +}