OpenGL calls with beforeRendering() and afterRendering() : sample code ?
-
Hi,
Actually I'm an openGL newbie. I'm trying to tweak the openglunderqml example to change the openGL calls at QQuickWindow::beforeRendering() and QQuickWindow::afterRendering() since I need to diplay something in front of a qml app. I don't want to use a shader but draw a simple box using "classic" opengl functions in Squircle::paint() :
glViewport(0,0,window->width(), window->height());
glColor3f(1.0f, 0.0f, 0.0f);
glRectf(-0.5f,0.5f,0.5f,-0.5f);What I don't understand is :
- Why the box is flashing like hell when called beforeRendering(), and disappears when the window is resized
- Why is the box simply not there when called form afterRendering() ? I tried to use glOrtho to make sure it is visible, with no success.
Il'll also need to achieve text rendering there using opengl, however it is not in the context of a QGlWidget and no renderText() is available. Would there be a way to do it using Qt, for example with a QGLWidget created with the same context as the QtQuick Scene Graph ?
-
The code with glOrtho I tried to make sure I render on top of the qml :
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrthof(0, width(), 0, height(), -5, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();Still no progress on my side...
-
Just found exactly what I want here :
http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.htmlA QPainter with QOpenGLPaintDevice can paint on the OpenGL context in beforeRendering or afterRendering :
@
if(!m_device)
m_device = new QOpenGLPaintDevice;
m_device->setSize(size());QPainter painter(m_device);
painter.setPen(Qt::blue);
painter.drawText(QRect(0,0,width(),height()), Qt::TextDontClip, "Hello World");
@However I still don't know why bare opengl instructions don't work as expected ! I'm actually exploring what the QOpenGLPaintDevice does using the glintercept tool.