LearnOpenGL 学习记录-入门章-你好 窗口

LearnOpenGL 学习记录 入门章 你好 窗口

夹杂着中英混淆和个人碎碎念,拿来参考需谨慎

入门章 你好 窗口

引入头文件

#include <glad/glad.h>
#include <GLFW/glfw3.h>

其中glad说是GLAD是用来管理OpenGL的函数指针的 有啥用得看后面了

进入main函数

    //初始化
    glfwInit();

    //glfwWindowHint 配置 GLFW

    /*
    基于OpenGL 3.3版本展开讨论的,所以我们需要告诉GLFW我们要使用的OpenGL版本是3.3
    主版本号(Major)和次版本号(Minor)
    */
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

    //核心模式(Core-profile)。明确告诉GLFW我们需要使用核心模式意味着我们只能使用OpenGL功能的一个子集
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

初始化opengl,设定主版本号和次版本号,使用其核心功能
创建窗口

    //创建一个窗口对象
    GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
    if (window == NULL)
    {
        std::cout << "Failed to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);

其中

GLFWAPI GLFWwindow* glfwCreateWindow(
    int width, 
    int height, 
    const char* title, 
    GLFWmonitor* monitor, 
    GLFWwindow* share);

width height title is easy to understand, monitor 是设置全屏的参数,NULL代表使用窗口,share share The window whose context to share resources with, or NULL to not share resources.

什么时候会返回空?
还没遇到过

然后是初始化glad

    //glad初始化
    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
    {
        std::cout << "Failed to initialize GLAD" << std::endl;
        return -1;
    }

GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname);传了个函数进去?

This function returns whether the Vulkan loader and any minimally functional ICD have been found.
还不太懂

    //视口的尺寸
    glViewport(0, 0, 800, 600);
    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

其中

void framebuffer_size_callback(GLFWwindow* window, int width, int height);

创建了一个修改大小的回调函数

循环渲染

while(!glfwWindowShouldClose(window))
{
    glfwSwapBuffers(window);
    glfwPollEvents();    
}

glfwSwapBuffers : sets the swap interval for the current OpenGL or OpenGL ES context
glfwPollEvents:处理事件

退出

glfwTerminate();
return 0;

最终效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值