c++ OpenGL之GLFW/glfw3.h:windows+vs配置步骤

参考链接:
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文件夹

  1. 解压第一步从官网上下载的文件
    在这里插入图片描述
  2. 选择“include”文件夹和对应vs文件夹,例如“lib-vc2017”,将其复制粘贴到项目下刚创建的“GLFW”文件夹
    在这里插入图片描述

四、配置vs项目属性(“项目->xxx属性”)

  1. 按下图的选项配置C/C++常规,编辑添加附加包含目录(输入$(SolutionDir)Dependencies\GLFW\include即可)
    ps. $(SolutionDir)能计算当前的工作目录;要选择所有配置,win32
    在这里插入图片描述
  2. 按下图选项配置链接器,编辑添加附加库目录(输入$(SolutionDir)Dependencies\GLFW\lib-vc2017即可)
    在这里插入图片描述
  3. 按下图选项配置链接器输入,编辑添加附加依赖项(输入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窗口,成功!
在这里插入图片描述

  • 8
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值