【OpenGL】01-配置环境
工具:VS2017+glfw-3.4.bin.WIN32
1 下载glfw
官网:https://www.glfw.org/download.html
2 配置VS2017
新建空项目,创建源文件application.cpp;右键属性
常规
在项目路径下新建Dependencies,将下载好的glfw-3.4.bin.WIN32解压到Dependencies下;这里配置的时候,可以使用相对路径(又学到了)
链接器
输入
加对应的库
glfw3.lib
opengl32.lib
User32.lib
Gdi32.lib
Shell32.lib
这里还学到了如果缺少xxx库,直接在bing上
链接:glClear 函数 (Gl.h) - Win32 apps | Microsoft Learn
加对应的库即可。
3 测试
复制这里的代码:Documentation | GLFW
#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);
// 画三角形
glBegin(GL_TRIANGLES);
glVertex2f(-0.5f, -0.5f);
glVertex2f(0.0f, 0.5f);
glVertex2f(0.5f, -0.5f);
glEnd();
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
结果