19 #include <QOpenGLShaderProgram> 20 #include <QOpenGLFunctions> 21 #include <QOpenGLContext> 46 qDebug() <<
"GLShaderTextured::initializeGL: error in vertex shader: " <<
m_program->log();
50 qDebug() <<
"GLShaderTextured::initializeGL: error in fragment shader: " <<
m_program->log();
53 m_program->bindAttributeLocation(
"vertex", 0);
54 m_program->bindAttributeLocation(
"texCoord", 1);
57 qDebug() <<
"GLShaderTextured::initializeGL: error linking shader: " <<
m_program->log();
74 m_texture->setMinificationFilter(QOpenGLTexture::Linear);
75 m_texture->setMagnificationFilter(QOpenGLTexture::Linear);
82 qDebug(
"GLShaderTextured::subTexture: no texture defined. Doing nothing");
86 QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
88 f->glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
93 draw(GL_TRIANGLE_FAN, transformMatrix, textureCoords, vertices, nbVertices);
96 void GLShaderTextured::draw(
unsigned int mode,
const QMatrix4x4& transformMatrix, GLfloat *textureCoords, GLfloat *vertices,
int nbVertices)
99 qDebug(
"GLShaderTextured::draw: no texture defined. Doing nothing");
103 QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
108 f->glEnableVertexAttribArray(0);
109 f->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
110 f->glEnableVertexAttribArray(1);
111 f->glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, textureCoords);
112 f->glDrawArrays(mode, 0, nbVertices);
113 f->glDisableVertexAttribArray(0);
131 "uniform highp mat4 uMatrix;\n" 132 "attribute highp vec4 vertex;\n" 133 "attribute highp vec2 texCoord;\n" 134 "varying mediump vec2 texCoordVar;\n" 136 " gl_Position = uMatrix * vertex;\n" 137 " texCoordVar = texCoord;\n" 142 "uniform lowp sampler2D uTexture;\n" 143 "varying mediump vec2 texCoordVar;\n" 145 " gl_FragColor = texture2D(uTexture, texCoordVar);\n" QOpenGLShaderProgram * m_program
void initTexture(const QImage &image, QOpenGLTexture::WrapMode wrapMode=QOpenGLTexture::Repeat)
void drawSurface(const QMatrix4x4 &transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices)
void subTexture(int xOffset, int yOffset, int width, int height, const void *pixels)
static const QString m_vertexShaderSourceTextured
QOpenGLTexture * m_texture
void draw(unsigned int mode, const QMatrix4x4 &transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices)
static const QString m_fragmentShaderSourceTextured