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.
For anything beyond GL 1.1 (and glActiveTexture
is beyond that), you have to use OpenGL's extension mechanism. Qt can do that for you all under the hood, have a look at the QAbstractOpenGLFunctions
class hierarchy
You can get the context the widget has created via QOpenGLWidget::context
and the QAbstractOpenGLFunctions of the context via QOpenGLContext::versionFunctions()
. There is also the older QOpenGLFunctions
class available via QOpenGLContext::functions()
which is limited to GL ES 2.0 (and the smathcing ubset of desktop GL 2.0), but would be enough for glActiveTexture()
.