要安装哪个包才能获取头文件 glad.h?

要安装哪个包才能获取头文件 glad.h?

我正在尝试编译这个例子https://learnopengl.com/Getting-started/Hello-Window

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

我已经安装了libglfw3-dev,但仍然缺少glad.h头文件。搜索packages.ubuntu.com没有结果。有一个github 页面但据我所知glad它没有提供。glad.h

答案1

感谢 @dc37 对 webservice 的评论!以下是我所做的:转到网络服务并下载所需的文件:


在此处输入图片描述


勾选“本地文件”选项,点击右下角的“生成”按钮,


在此处输入图片描述


将文件下载glad.zip到当前目录并解压。

创建一个测试程序 test.cpp

#include <iostream>
#include "glad.h"
#include <GLFW/glfw3.h>  
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);
    //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    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;
}

编译它(记得先安装libglfw3-dev):

g++ -c glad.c 
g++ test.cpp -o my_test glad.o -lglfw -ldl

运行:

$ ./my_test

(屏幕上显示一个空白窗口)

相关内容