I want to draw in QOpenGLWidget, processing data and call repaint() in mousePressEvent() function:
QPoint point[2];
QImage img=QImage(1000,800,QImage::Format_Grayscale8);
void Widget::mousePressEvent(QMouseEvent *event)
{
point[0]=event->pos();
point[1]=point[0]+QPoint(10,10);
repaint();
}
Now repaint widget in paintGL():
void Widget::paintGL()
{
vao->release();
vbo->release();
QPainter painter;
painter.begin(image);
painter.drawLine(point[0],point[1]);
painter.end();
painter.begin(this);
painter.drawImage(0,0,*del->tmpImages[1]);
painter.beginNativePainting();
vao->bind();
vbo->bind();
glViewport(0,0,200,200);
glDrawArrays(GL_TRIANGLE_STRIP,0,8);
painter.endNativePainting();
painter.end();
}
I have three questions.
why I have to release vao and vbo to paint widget with QPainter in paintGL(), if not, Qpainter doesn't work.
widget can't paint textures in paintGL() when use QPainter and OpenGL API at the same time. It works well when just call OpenGL API.
When I repaint widget frequently (click widget frequently, calling mousePressEvent() and repaint()), some repaint event are ignored by Qt.If call repaint(), QWidget will repaint immediately, so how can I force Qt to repaint QOpenGLWidget just like calling repaint() to repaint QWidget?
releaseonvaoandvboat the end of your function. - Andrejs CainikovsQWidget::updatethanQWidget::repaint(see also this one). If you want to store the renderd textures and you need all frames (which would not be visible on screen), you might prefer some offscreen-rendering solution. - pasbi