Question

Since QGLWidget cannot be used for OpenGL / ES, i am left with QWidget in Qt for widgets to render opengl. Reference

if i have the following renderView function to render in the current window, i am looking for "that" function that will be called repeatedly by qt for QWidget to refresh screen so that i can call renderView in that function by overloading it.

any idea how to do this or common work around?

Original problem: I do not want to call renderView in a timer of 1 MilliSec or even 16.66 Milli sec as per the screen refresh rate.

class MyWindow
{
    void renderView()
    {   
        if(DeviceContext && RenderingContext)
        {
            wglMakeCurrent(m_hdc, m_hrc); //Set current context

            glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
            glClear(GL_COLOR_BUFFER_BIT);       
            // glViewPort.... and render using shaders

            SwapBuffers(m_hdc); // Double buffering thats why
        }   
    }
};

class MyWidget : public QWidget, public MyWindow
{
     // What is the function called repeatedly to refresh the screen
     // so that i would ask that function to call renderView
};

Thanks in advance!

Was it helpful?

Solution

Since QGLWidget cannot be used for OpenGL / ES

Right, we need to clear up some confusion before going further down the road...

It can be. This widget was invented to extend the usual QWidget interface with OpenGL desktop and embedded support. Please refer to the following example to see yourself it is possible to use this widget for OpenGL ES functionality:

OpenGL Hello GL ES Example

Now, we can come to the point to answer your question. What you should probably reimplement is the following protected method.

void QGLWidget::paintGL() [virtual protected]

This virtual function is called whenever the widget needs to be painted. Reimplement it in a subclass.

While we are at discussing it, please also check the protected initialization method:

void QGLWidget::initializeGL() [virtual protected]

This virtual function is called once before the first call to paintGL() or resizeGL(), and then once whenever the widget has been assigned a new QGLContext. Reimplement it in a subclass.

This function should set up any required OpenGL context rendering flags, defining display lists, etc.

In fact, you could even deal with overlays with this interface as per the following protected methods:

void QGLWidget::paintOverlayGL() [virtual protected]

This virtual function is used in the same manner as paintGL() except that it operates on the widget's overlay context instead of the widget's main context. This means that paintOverlayGL() is called whenever the widget's overlay needs to be painted. Reimplement it in a subclass.

and

void QGLWidget::initializeOverlayGL() [virtual protected]

This virtual function is used in the same manner as initializeGL() except that it operates on the widget's overlay context instead of the widget's main context. This means that initializeOverlayGL() is called once before the first call to paintOverlayGL() or resizeOverlayGL(). Reimplement it in a subclass.

This function should set up any required OpenGL context rendering flags, defining display lists, etc. for the overlay context.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top