-
使用VS 新建空项目
我用的是2017 -
创建一个空的测试文件 测试能正常运行C++
按F5有正常输出
-
下载GLFW
根据你生成的应用程序的目标平台选择一个编译好的二进制文件就好。我这里选择32位。(当然你也可以使用源码进行编译。)
下载后解压是这样的。选择你自己的版本,我是用2017。
- 将GLFW文件保存到项目里
创建一个目录Dependencies\GLFW 保存 上面步骤解压得到的include 和 lib-vc2017
- 将GLFW 包含链接到工程里
包含:
链接:
在附加依赖库上,增加;glfw32.lib;opengl32.lib就行。
- 运行GLFW例子代码
我们copy 官网的例子代码到我们的文件里运行
#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;
}
- 第一个窗口
运行上面的代码,你会看到一个黑色的窗口。
恭喜你成功了