OpenGL入门

第一章 OpenGL和GLFW配置

1 OpenGL 和 GLFW简介

OpenGL(英语:Open Graphics Library,译名:开放图形库或者“开放式图形库”)是用于渲染2D3D矢量图形的跨语言跨平台应用程序编程接口(API)

详情见:20分钟让你了解OpenGL——OpenGL全流程详细解读 - 知乎 (zhihu.com)

GLFW是一个开源的多平台库,用于桌面上的OpenGL,OpenGL ES和Vulkan开发。它提供了一个简单的 API,用于创建窗口、上下文和图面、接收输入和事件。

详情见:GLFW: 主页

2 GLFW 下载

下载地址:OpenGL 库|断续器 (glfw.org)

3 项目搭建

使用 vs 创建项目,项目名为glfw

在该项目目录文件下创建Dependecies/GLFW文件夹。

 GLFW文件夹中,包括inlcude文件和lib-vc2019.

 其中inlude就是glfw下载列表的include(将其复制过来)

lib-vc2019则是glfw中的lib-vc2019仅保留glfw3.h。如图所示:

 4 环境搭建

 在glfw中创建src文件,并在src中创建application.cpp

将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);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

右击glfw,选中属性

 a.  在C++  -> 常规  中编辑附加常规目录为:$(SolutionDir)Dependencies\GLFW\include

b. 在linker -> 常规 中编辑附加库目录为:$(SulotionDir)Dependencies\GLFW\lib-vc2019

 c. linker -> input 中编辑附加依赖项为:

glfw3.lib
opengl32.lib
User32.lib
Gdi32.lib
shell32.lib

 三个设置均 点击应用后生效。且在设置时注意 配置和平台的选择;

 5 运行案例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值