Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in
read-only mode
.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
I have a widget subclass QOpenGLWidget and I want to combine openGL and QPainter in the paintGL function, but it not work. Here is the code:
void paintGL()
glEnable(GL_MULTISAMPLE);
glEnable(GL_BLEND);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
m_pImageRender->paint();
glDisable(GL_BLEND);
glDisable(GL_MULTISAMPLE);
QPainter painter(this);
painter.fillRect(QRect(100, 100, 100, 100), QColor("#ff0000"); // without the following line, this line work
painter.drawImage(rect(), m_oImage, QRect(0, 0, m_oImage.width(), m_oImage.height()); // after add this line, the screen display nothing, just black
The openGL painting code is like below:
m_pShaderProgram->bind();
m_pVertexBuffer->bind();
m_pIndexBuffer->bind();
m_pShaderProgram->setUniformValue("projection", m_mtProjection);
m_pShaderProgram->setUniformValue("scale", m_fScale);
m_pShaderProgram->setUniformValue("offset", m_vecOffset);
int textureUnits[m_nImageCount], display[m_nImageCount];
float cmin[m_nImageCount], cmax[m_nImageCount];
QVector4D color[m_nImageCount];
for (int i = 0;i < m_nImageCount;i++)
textureUnits[i] = i;
display[i] = m_vecDisplay[i];
cmin[i] = m_vecClipMin[i];
cmax[i] = m_vecClipMax[i];
color[i] = QVector4D(m_vecColor[i].red() / 255.0, m_vecColor[i].green() / 255.0, m_vecColor[i].blue() / 255.0, 1.0);
m_pShaderProgram->setUniformValueArray("utexture", textureUnits, m_nImageCount);
m_pShaderProgram->setUniformValueArray("display", display, m_nImageCount);
m_pShaderProgram->setUniformValueArray("rgbcolor", color, m_nImageCount);
m_pShaderProgram->setUniformValueArray("cmin", cmin, m_nImageCount, 1);
m_pShaderProgram->setUniformValueArray("cmax", cmax, m_nImageCount, 1);
for (int i = 0;i < m_nImageCount;i++)
if (m_vecTexture[i])
m_vecTexture[i]->bind(i);
m_pShaderProgram->enableAttributeArray(0);
m_pShaderProgram->setAttributeBuffer(0, GL_FLOAT, 0, 2, 4 * sizeof(GLfloat));
m_pShaderProgram->enableAttributeArray(1);
m_pShaderProgram->setAttributeBuffer(1, GL_FLOAT, 2 * sizeof(GLfloat), 2, 4 * sizeof(GLfloat));
m_pOpenGLCore->glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
for (int i = 0;i < m_nImageCount;i++)
if (m_vecTexture[i])
m_vecTexture[i]->release(i);
m_pShaderProgram->release();
m_pVertexBuffer->release();
m_pIndexBuffer->release();
So, what may cause the problem?