feat: add OpenGL window on Windows

This commit is contained in:
Cat Flynn 2023-07-23 18:21:44 +02:00
parent c0c1e8be74
commit 4c94e0f047
2 changed files with 13 additions and 2 deletions

View File

@ -1,11 +1,15 @@
cmake_minimum_required(VERSION 3.27) cmake_minimum_required(VERSION 3.27)
project(HelloGLFW) project(HelloOpenGL)
# Define platform-specific paths and libraries # Define platform-specific paths and libraries
if(WIN32) if(WIN32)
# GLFW
set(GLFW_PATH "C:/libs/glfw-3.3.8.bin.WIN64") set(GLFW_PATH "C:/libs/glfw-3.3.8.bin.WIN64")
include_directories(${GLFW_PATH}/include) include_directories(${GLFW_PATH}/include)
link_directories(${GLFW_PATH}/lib-vc2022) link_directories(${GLFW_PATH}/lib-vc2022)
# OpenGL
find_package(OpenGL REQUIRED)
elseif(UNIX OR APPLE) elseif(UNIX OR APPLE)
message(FATAL_ERROR "Linux and macOS platforms are not supported yet.") message(FATAL_ERROR "Linux and macOS platforms are not supported yet.")
endif() endif()
@ -14,4 +18,5 @@ add_executable(${PROJECT_NAME} hello.cpp)
if(WIN32) if(WIN32)
target_link_libraries(${PROJECT_NAME} glfw3) target_link_libraries(${PROJECT_NAME} glfw3)
target_link_libraries(${PROJECT_NAME} OpenGL::GL)
endif() endif()

View File

@ -21,13 +21,14 @@
// Set startup project in Solution Explorer // Set startup project in Solution Explorer
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <gl/GL.h>
int main() int main()
{ {
if (!glfwInit()) if (!glfwInit())
return -1; return -1;
GLFWwindow* window = glfwCreateWindow(640, 480, "Hello GLFW", NULL, NULL); GLFWwindow* window = glfwCreateWindow(640, 480, "Hello GL", NULL, NULL);
if (!window) if (!window)
{ {
glfwTerminate(); glfwTerminate();
@ -38,6 +39,11 @@ int main()
while (!glfwWindowShouldClose(window)) while (!glfwWindowShouldClose(window))
{ {
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents(); glfwPollEvents();
} }