【问题标题】:glActiveTexture in Qt and QGLWidget?Qt 和 QGLWidget 中的 glActiveTexture?
【发布时间】:2015-05-02 23:13:06
【问题描述】:

我有一个关于 OpenGL+GLEW 的小应用程序。现在,我正在尝试用 QT(而不是 GLEW)重写它。但我有一个问题。 IDE 写道:

'glActiveTexture' was not declared in this scope glActiveTexture(TextureUnit); ^

这是 .cpp 文件中的代码:

#include <iostream>
#include "texture.h"

Texture::Texture(GLenum TextureTarget, std::string& FileName)
{
    m_textureTarget = TextureTarget;
    m_fileName      = FileName;
}

bool Texture::Load()
{
    // A lot of code for reading the picture.
}

void Texture::Bind(GLenum TextureUnit)
{
    glActiveTexture(TextureUnit);
    glBindTexture(m_textureTarget, m_textureObj);
}

这是来自 .h 文件的代码。

#ifndef TEXTURE_H
#define TEXTURE_H

#include <string>
#include <QGLWidget>

class Texture
{
public:
    Texture(GLenum TextureTarget, std::string& FileName);

    bool Load();

    void Bind(GLenum TextureUnit);

private:
    std::string m_fileName;
    GLenum m_textureTarget;
    GLuint m_textureObj;
    unsigned int width, height;
    unsigned char * data;
};


#endif  /* TEXTURE_H */

我开始认为 Qt 不具备这样的功能。 我怎么解决这个问题? 我很高兴有任何想法。

【问题讨论】:

    标签: qt opengl glew qglwidget qt5.3


    【解决方案1】:

    对于 GL 1.1 以外的任何内容(glActiveTexture 超出此范围),您必须使用 OpenGL 的扩展机制。 Qt 可以在幕后为大家做到这一点,看看QAbstractOpenGLFunctions 类层次结构

    您可以通过QOpenGLWidget::context 获取小部件创建的上下文,并通过QOpenGLContext::versionFunctions() 获取上下文的 QAbstractOpenGLFunctions。还有旧的QOpenGLFunctions 类可通过QOpenGLContext::functions() 获得,它仅限于GL ES 2.0(以及桌面GL 2.0 的smathcing 子集),但对于glActiveTexture() 来说已经足够了。

    【讨论】:

    • 我应该添加#include 并写一些类似QOpenGLFunctions_4_3_Core::glActiveTexture(TextureUnit); 的东西。还是它以不寻常的方式工作?
    • 阅读我链接的文档。你不能只是静态地使用它。在创建 GL 上下文之后,必须在运行时查询这些指针。
    • @user3051029:也许您还发现this blog post 也很有帮助(尤其是“功能,无处不在的功能!”部分)。
    • 旧类实际上只在发布版本中支持 GLES 2 的系统上加载 glActiveTexture。在任何情况下,调试构建都会以某种方式进行,但是发布得到了空指针
    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多