gpt4 book ai didi

c++ - 使用 glad with a QOpenGLWidget 加载 OpenGL 函数指针

转载 作者:搜寻专家 更新时间:2023-10-31 02:10:36 32 4
gpt4 key购买 nike

所以我正在阅读一些 OpenGL,我想使用 QOpenGLWidget 进行绘图,以便稍后创建一些其他有用的 UI 元素。我正在使用 glad用于解析指向 OpenGL 的函数指针,但我不知道如何使用 Qt 的 getProcAddress 函数!

在我的 QOpenGLWidget 子类的 initializeGL() 函数中,我尝试过:

if(gladLoadGLloader((GLADloadproc) currentContext()->getProcAddress) {}

但由于 Qt 的函数重载,所以没有成功。当我使用

if(gladLoadGL()) {}

也不行。我的包括:

#include <glad\glad.h>
#include "OpenGLViewport.h"
#include <QDebug>
#include <QOpenGLContext>

我搜索了 Mr. Google,并仔细查看了 Qt 文档,但一无所获。我想使用 GLAD 只是为了让我的渲染代码不会太紧密地绑定(bind)到 Qt,以防我以后想切换。

编辑:我的目标是将非实例化 OpenGL 函数与 Qt 一起使用(尽管如果我没记错的话,文档中另有建议)。因为那样我就可以无缝地切换到 GLFW 来提供窗口等。

最佳答案

将解决方案从问题移动到答案:

ANSWER: So it turns out I just had some things mixed up, this is how I got it to work, in case anyone has the same problem:

  1. add glad.c in your project
  2. add the necessary headers to your include directory
  3. the .cpp file of your QOpenGLWidget subclass should have following components:

// Subclass.cpp
#include <glad/glad.h>
// important, subclass header file after glad!!
// otherwise glad won't "hook"
#include "Subclass.h"

void Subclass::initializeGL()
{
if(gladLoadGL()) initialized = true; // initialized is a class member here
else; // handle errors
}

void Subclass::paintGL()
{
if(initialized); // render here
}

关于c++ - 使用 glad with a QOpenGLWidget 加载 OpenGL 函数指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44968303/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com