Do I need glActiveTexture and glBindTexture in Qt5?
-
example 1
@void ch2HelloWorld::paintGL()
{
qglClearColor(Qt::black);
glClear(GL_COLOR_BUFFER_BIT);program_.enableAttributeArray( "vert" ); program_.setAttributeBuffer( "vert", GL_FLOAT, 0, 4, sizeof(GLfloat) * 6); program_.enableAttributeArray( "vertTexCoord" ); program_.setAttributeBuffer( "vertTexCoord", GL_FLOAT, 4 * sizeof(GLfloat), 2, sizeof(GLfloat) * 6); // bind the texture and set the "tex" uniform in the fragment shader //glActiveTexture(GL_TEXTURE0); //glBindTexture(GL_TEXTURE_2D, texture_addr_); program_.setUniformValue("tex", 0); glDrawArrays(GL_TRIANGLES, 0, 3); program_.disableAttributeArray("vert"); program_.disableAttributeArray("vertTexCoord"); //glBindTexture(GL_TEXTURE_2D, 0);
}@
example 2
@
void ch2HelloWorld::paintGL()
{
qglClearColor(Qt::black);
glClear(GL_COLOR_BUFFER_BIT);program_.enableAttributeArray( "vert" ); program_.setAttributeBuffer( "vert", GL_FLOAT, 0, 4, sizeof(GLfloat) * 6); program_.enableAttributeArray( "vertTexCoord" ); program_.setAttributeBuffer( "vertTexCoord", GL_FLOAT, 4 * sizeof(GLfloat), 2, sizeof(GLfloat) * 6); // bind the texture and set the "tex" uniform in the fragment shader glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture_addr_); program_.setUniformValue("tex", 0); glDrawArrays(GL_TRIANGLES, 0, 3); program_.disableAttributeArray("vert"); program_.disableAttributeArray("vertTexCoord"); glBindTexture(GL_TEXTURE_2D, 0);
}@
Both of them are work
But if I unbind the texture without calling glActiveTexture and glBindTexture at the end
in the paintGL, the texture on the frame buffer will disappear.Should I call glActiveTexture and glBindTexture before setUniformValue?
Which one is a recommend solution in Qt5.1?