feat: open window with GLFW on Windows

This commit is contained in:
Cat Flynn 2023-07-23 17:46:53 +02:00
parent 43ce32922b
commit c0c1e8be74
2 changed files with 44 additions and 4 deletions

View File

@ -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)
add_executable(${PROJECT_NAME} hello.cpp)
if(WIN32)
target_link_libraries(${PROJECT_NAME} glfw3)
endif()

View File

@ -8,11 +8,39 @@
// cd build
// cmake ..
// cmake --build .
// The last step compiles the executable - this can also be done from Visual
// Studio
#include <iostream>
// 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 <GLFW/glfw3.h>
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;
}