参考链接:
https://www.youtube.com/watch?v=OR4fNpBjmq8&list=PLlrATfBNZ98foTJPJ_Ev03o2oq3-GGOS2&index=2
一、官网下载
链接:https://www.glfw.org/download.html
选择32位(32-bit windows binaries)下载:
二、创建vs项目(需要用到glfw的项目)
1. 在该工程目录下新建文件夹,命名为“Dependencies”
2. 在“Dependencies”
文件夹下新建文件夹,命名为“GLFW”
三、将所需文件添加入上述GLFW
文件夹
- 解压第一步从官网上下载的文件
- 选择
“include”
文件夹和对应vs文件夹,例如“lib-vc2017”
,将其复制粘贴到项目下刚创建的“GLFW”
文件夹
四、配置vs项目属性(“项目->xxx属性”)
- 按下图的选项配置C/C++常规,编辑添加附加包含目录(输入
$(SolutionDir)Dependencies\GLFW\include
即可)
ps. $(SolutionDir)能计算当前的工作目录;要选择所有配置,win32
- 按下图选项配置链接器,编辑添加附加库目录(输入
$(SolutionDir)Dependencies\GLFW\lib-vc2017
即可)
- 按下图选项配置链接器输入,编辑添加附加依赖项(输入
glfw3.lib;opengl32.lib;User32.lib;Gdi32.lib;%(AdditionalDependencies)
即可)
五、测试
官网上复制代码,运行:
#include <GLFW/glfw3.h>
int main(void)
{
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;
}
出现Hello World窗口,成功!