OpenGL学习笔记 – 迷途通

OpenGL学习笔记

12月 9, 2022                      👁️ 59

B站:
https://www.bilibili.com/video/BV11e4y1T7Ky

第1期 OpenGL入门Hello World环境配置

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

//1.下载glfw
//2.下载glad
//3.新建空项目,
//把include, lib放好
//4.把include, lib添加到项目中
//5.包含头文件,包含库文件,输入依赖
//6.把glad.c添加到项目中。
//7.写代码

void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
    glViewport(0, 0, width, height);
}

int main()
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

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

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

    glViewport(0, 0, 800, 600);

    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

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

    glfwTerminate();

    return 0;
}

发表回复

您的电子邮箱地址不会被公开。