feat: open window with GLFW on Windows
This commit is contained in:
parent
43ce32922b
commit
c0c1e8be74
|
@ -1,5 +1,17 @@
|
||||||
cmake_minimum_required(VERSION 3.27)
|
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()
|
32
hello.cpp
32
hello.cpp
|
@ -8,11 +8,39 @@
|
||||||
// cd build
|
// cd build
|
||||||
// cmake ..
|
// cmake ..
|
||||||
// cmake --build .
|
// 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()
|
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;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue