Qt和QGLWidget中的glActiveTexture?

时间:2015-05-02 23:13:07

标签: qt opengl glew qglwidget qt5.3

我在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没有提供这样的功能。 我怎么解决这个问题? 我很乐意接受任何想法。

1 个答案:

答案 0 :(得分:1)

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

您可以通过QOpenGLWidget::context获取窗口小部件创建的上下文,通过QOpenGLContext::versionFunctions()获取上下文的QAbstractOpenGLFunctions。还有一个较早的QOpenGLFunctions课程可以通过QOpenGLContext::functions()获得,仅限于GL ES 2.0(以及桌面版GL 2.0的粉丝版本),但对于glActiveTexture()来说已经足够了。