OpenGL 从入门到成魔-第2章-创建 OpenGL 窗口

2020-06-03 15:46:07 浏览数 (1)

注:参考自bilibili系列视频,OpenGL 从入门到成魔-第2章-创建 OpenGL 窗口https://www.bilibili.com/video/BV1Uz411v7mN

创建窗口流程

1.jpg

2.jpg

3.jpg

代码实现

代码语言:javascript复制
#include<glad/glad.h>
#include <GLFW/glfw3.h>

int main() {
    //初始化glfw
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

    int windowWidth = 1280;
    int windowHeight = 720;
    //todo core_profile
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    //创建窗口
    GLFWwindow* window = glfwCreateWindow(windowWidth, windowHeight, "YaoGL", NULL, NULL);

    //OpenGL是单线程运行模式
    //不允许多个线程同时调用
    glfwMakeContextCurrent(window);

    //初始化glad
    gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);

    while (!glfwWindowShouldClose(window)) {
        //todo 绘制操作

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

0 人点赞