安装GLFW3
Debian系
sudo apt install libglfw3-dev
Arch系
sudo Pacman -S glfw3-x11
CMakeLists.txt
在CMakeLists.txt最后加上如下两句
find_package(glfw3 REQUIRED )
target_link_libraries(项目名 GL glfw)
测试程序
摘自官方文档 Example code
会显示一个黑色无内容窗口
#include <GLFW/glfw3.h>
int main()
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}