0

I have a small application on OpenGL+GLEW. Now, I am trying to rewrite it with QT(instead of GLEW). But I have a problem. IDE writes:

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

Here is that code in .cpp file:

#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);
}

Here is code from .h file.

#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 */

I am starting to think that Qt doesn't present such capabilities. How can I solve this problem? I would be glad to any ideas.

4

1 回答 1

1

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

您可以通过 获取小部件创建的QOpenGLWidget::context上下文和上下文的 QAbstractOpenGLFunctions QOpenGLContext::versionFunctions()。还有一个旧QOpenGLFunctions类可用QOpenGLContext::functions(),仅限于 GL ES 2.0(以及桌面 GL 2.0 的 smathcing 子集),但对于glActiveTexture().

于 2015-05-02T23:47:30.547 回答