标签: glad

如果我使用 Glad 而不是 GLEW,我会错过什么吗?

我想使用 OpenGL,但我不知道如何设置 GLEW。如果我要使用 Glad,我会失去一些东西吗?我可以从使用 GLEW 的教程中学习吗?

opengl glew glad

16
推荐指数
1
解决办法
2万
查看次数

如何修复来自glad.c的符号'dlclose@@GLIBC_2.2.5'的未定义引用

我正在按照https://learnopengl.com/ 上的教程学习 Opengl,但在 使用 cmake 设置依赖项时遇到问题(请参阅创建窗口)。

我的 CMakeLists.txt 基于GLFW 文档

cmake_minimum_required(VERSION 3.14)
project(openglTuto)


include_directories(include)
add_executable(gltuto src/main.c src/glad.c)

find_package(glfw3 3.3 REQUIRED)
find_package(OpenGL REQUIRED)

target_link_libraries(gltuto glfw)
target_include_directories(gltuto PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(gltuto ${OPENGL_gl_LIBRARY})

Run Code Online (Sandbox Code Playgroud)

CMake 成功构建了我的配置,但 ninja 无法编译并打印错误。

[1/1] 链接 C 可执行文件 gltuto

失败: gltuto : && /usr/bin/cc CMakeFiles/gltuto.dir/src/main.co CMakeFiles/gltuto.dir/src/glad.co -o gltuto /usr/lib/libglfw.so.3.3 && :

/usr/bin/ld: CMakeFiles/gltuto.dir/src/glad.co: 未定义对符号“dlclose@@GLIBC_2.2.5”的引用

/usr/bin/ld: /usr/lib/libdl.so.2: 添加符号时出错:命令行中缺少 DSO

collect2: 错误: ld 返回 1 个退出状态

忍者:构建停止:子命令失败。

c opengl cmake glfw glad

9
推荐指数
1
解决办法
2万
查看次数

如何修复“函数 _main 中引用的未解析外部符号 _gladLoadGLLoader”和“未解析的外部符号 _glad_glViewport”?

构建程序时,我不断收到未解决的外部符号错误。但是,程序编译得很好。我正在使用 GLFW 和 GLAD 库。

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

#include <iostream>

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

//#undef main
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, "LearningOpenGL", NULL, NULL);

    if (window == NULL) {
        std::cout << "Failed To Create Window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);

    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

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

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

    glViewport(0, 0, …
Run Code Online (Sandbox Code Playgroud)

c++ opengl glfw glad

8
推荐指数
1
解决办法
5829
查看次数

在 glfwDestroyWindow 处提交稀疏纹理的第一页会崩溃

以下 OpenGL/GLFW/GLAD 代码(MCVE 版本)使进程崩溃,并在 nvoglv64.dll 中出现以下访问冲突异常:

0x00007FFC731F586F (nvoglv64.dll) in ConsoleApplication2.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x0000000000024AA8.
Run Code Online (Sandbox Code Playgroud)

glfwDestroyWindow(window)下面的代码清单末尾的调用中,我不知道为什么。glTexPageCommitmentARB当不调用或使用commitof调用它时,此调用不会崩溃GL_FALSE/0

我现在已经阅读了ARB_sparse_texture的规范三遍,检查了每个参数的条件glTexPageCommitmentARB(x,y,z,宽度,高度,内部格式页面大小的深度倍数),我有点确定我已经遵循有关如何正确使用该功能的所有说明。我之前还使用调试上下文和调试消息回调检查了任何 OpenGL 错误,但没有输出。

更多信息:

  • 操作系统:Windows 10 x64 (20H2)
  • 驱动程序:Nvidia 461.09 (DCH)
  • GLAD 配置:OpenGL 4.3 核心 + ARB_sparse_texture + ARB_sparse_texture2
  • GLFW:来自 Git 提交0b9e48fa3df9c18的全新本地 MSVC x64 版本构建

下面代码中调用之前的 fprintfglTexPageCommitmentARB在程序结束时崩溃之前打印以下输出:

256 128 1 32768
Run Code Online (Sandbox Code Playgroud)
0x00007FFC731F586F (nvoglv64.dll) in ConsoleApplication2.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x0000000000024AA8.
Run Code Online (Sandbox Code Playgroud)

我是否在这里遗漏了任何内容,或者只是驱动程序或 GLFW …

c opengl glfw glad

5
推荐指数
0
解决办法
347
查看次数

ImGui 与高兴的 openGL 加载程序抛出分段错误(核心转储)

我是 ImGui 库的新手,最近我一直在尝试其中包含的示例。一切都像魅力一样,直到我更改了(我想使用的加载器)gl3w的包含(和功能)。glad当我在两个加载器之间交换时,我在文件内遇到了分段错误异常imgui_impl_glfw_gl3.cpp。我发现一篇文章表明,这可能是由于某些函数无法“绑定”并产生空指针而发生的。

我发现错误在 第216行的代码中line 216imgui_impl_glfw_gl3.cpp

glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
Run Code Online (Sandbox Code Playgroud)

我还将包含文件从 更改imgui_impl_glfw_gl3.cppgl3wglad但没有结果。

这是我正在执行的主要函数(这是使用glad的imgui的基本opengl3示例):

#include "gui/imgui.h"
#include "gui/imgui_impl_glfw_gl3.h"
#include <stdio.h>
#include <glad/glad.h>    // This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you.
#include <GLFW/glfw3.h>

static void error_callback(int error, const char* description)
{
    fprintf(stderr, "Error %d: %s\n", error, description);
}

int main(int, char**)
{
    // Setup …
Run Code Online (Sandbox Code Playgroud)

c++ opengl glfw imgui glad

3
推荐指数
1
解决办法
6131
查看次数

“gladLoadGL”有问题。我收到一个错误,说它不需要 1 个参数

我正在尝试做一些 openGL 教程(https://www.glfw.org/docs/latest/quick_guide.html#quick_example),其中一个功能是gladLoadGL。代码行是“gladLoadGL(glfwGetProcAddress);” 但是,当我尝试运行时,出现错误“C2660 'gladLoadGL':函数不接受 1 个参数”。

我试过在线搜索,但似乎没有人遇到与我相同的问题。我查看了glad.h 文件,该函数有一个警告“未找到函数定义gladLoadGL”,这可能是我的问题的来源。当我生成高兴的代码 ( https://glad.dav1d.de/ ) 时,我在语言 C/C++、规范 OpenGL、gl 版本 4.6、配置文件核心和生成加载器中的设置被打勾。

gladLoadGL(glfwGetProcAddress);
Run Code Online (Sandbox Code Playgroud)

opengl glad

3
推荐指数
1
解决办法
3252
查看次数

包含glad.h时出现分段错误

我正在按照 GLFW 指南开始,但我似乎无法让它与 GLAD 一起运行。

这是我的 C 文件 (prac.c)

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

void error_callback(int error, const char* description) {
  fprintf(stderr, "Error %d: %s\n", error, description);
}

int main(void) {
  GLFWwindow* window;

  if(!glfwInit()) return -1;

  glfwSetErrorCallback(error_callback);

  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
  window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
  if(!window) {
    glfwTerminate();
    return -1;
  } 

  glfwMakeContextCurrent(window);

  printf("OpenGL version: %s\n", glGetString(GL_VERSION));

  gladLoadGL();

  while(!glfwWindowShouldClose(window)) {
    glClear(GL_COLOR_BUFFER_BIT);

    glfwSwapBuffers(window);

    glfwPollEvents();
  }

  glfwDestroyWindow(window);
  glfwTerminate();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

我通过运行以下命令的 Makefile 来编译它:

gcc -Wall -lglfw -lGL …
Run Code Online (Sandbox Code Playgroud)

c opengl segmentation-fault glfw glad

3
推荐指数
1
解决办法
1351
查看次数

EBO 和 VAO 之间的 OpenGL 绑定顺序

我正在尝试创建 opengl 三角形,但遇到了一些问题。

EBO:ElementArrayBufferObject VAO:VertexArrayObject

当我尝试在绑定 VAO 之前绑定 EBO 时,它会导致错误,我不知道为什么。

我的代码:

// Generate the VAO and VBO with only 1 object each
glGenVertexArrays(1, &VAO);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

// Make the VAO the current Vertex Array Object by binding it
glBindVertexArray(VAO);
Run Code Online (Sandbox Code Playgroud)

它在渲染时引起问题。

如果我像这样修复代码。

// Generate the VAO and VBO with only 1 object each
glGenVertexArrays(1, &VAO);

// Make the VAO the current Vertex Array Object by binding it
glBindVertexArray(VAO);
    
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
Run Code Online (Sandbox Code Playgroud)

它按我的预期工作。

我真的不知道为什么不在 VAO …

c++ opengl buffer vertex glad

3
推荐指数
1
解决办法
1786
查看次数

调用 glGetString 时访问冲突错误

我正在使用 SDL2 + GLAD 在 C++ 中创建一个 OpenGL 应用程序。在我的主函数中,我有以下代码:

#include <iostream>
#include <SDL.h>

#include <glad\glad.h>

int main(int argc, char *argv[]) {
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        std::cout << "SDL could not be initialized.";
        return 1;
    }

    SDL_GL_LoadLibrary(nullptr);

    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

    SDL_Window *window = SDL_CreateWindow("Hello world", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 500, 500, SDL_WINDOW_OPENGL);

    if (window == nullptr) {
        std::cout << "SDL could not open window";
        return 1;
    }

    const SDL_GLContext context = SDL_GL_CreateContext(window);

    if (context == …
Run Code Online (Sandbox Code Playgroud)

c++ opengl sdl-2 glad

2
推荐指数
1
解决办法
939
查看次数

当 Visual Studio 未以管理员身份运行时(GLFW/glad 应用程序),KernelBase.dll 异常代码 0x0EEDFADE(但没有崩溃)

我使用的是 Visual Studio 2019,并有以下简单的 OpenGL 程序作为最小示例(使用 GLFW 和 GLAD):

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

void error_callback(int error, const char* description) {
    std::cout << "GLFW error: " << description << " (" << error << ")\n";
}

int main() {
    if (!glfwInit()) exit(-1);
    glfwSetErrorCallback(error_callback);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    GLFWwindow* window = glfwCreateWindow(640, 480, "GLFW Test Application", nullptr, nullptr);
    if (!window) exit(-1);
    glfwMakeContextCurrent(window);
    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) exit(-1);
    glViewport(0, 0, 640, 480);
    glClearColor(0.6f, 0.6f, 0.1f, 1.f);
    while (!glfwWindowShouldClose(window)) {
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers(window); …
Run Code Online (Sandbox Code Playgroud)

c++ glfw visual-c++ visual-studio-2019 glad

2
推荐指数
1
解决办法
6087
查看次数

为什么应该使用外部 OpenGL 加载器函数而不是 GLAD 的内置加载器?

我已经使用 GLAD 和 SFML 一段时间了,而且我一直在使用 GLAD 的内置函数加载器,gladLoadGL它对我来说工作得很好。现在我正在查看 GLFW,它在他们的指南和 Khronos opengl wiki 上都说您应该使用它gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)。有什么特别的原因吗?

opengl glfw glad

2
推荐指数
1
解决办法
3366
查看次数

访问冲突执行位置 0x0000000000000000。带有 GLAD 和 GLFW 的 OpenGL

我一直在尝试按照learnopengl.comglfw.org 上的说明创建一个使用 GLAD 和 GLFW 的 OpenGL 窗口。乍一看,根据文档,这足以使窗口正常工作:

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

using namespace std;

// framebuffer size callback function
void resize(GLFWwindow* window, int width, int height)
{
    glViewport(0, 0, width, height);
}

void render(GLFWwindow* window) {

    // here we put our rendering code
    
}

void main() {

    int width = 800;
    int height = 600;

    // We initialzie GLFW
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    // Now that it is initialized, we …
Run Code Online (Sandbox Code Playgroud)

c++ opengl glfw glad

2
推荐指数
1
解决办法
334
查看次数

由于 GLAD 错误,无法在 Ubuntu 中编译 OpenGL 程序

我成功安装了GLWF。我可以证明,由于该程序可以编译:

#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 …
Run Code Online (Sandbox Code Playgroud)

opengl compiler-errors glfw glad

1
推荐指数
1
解决办法
3794
查看次数