Corey D
Corey D

Reputation: 4689

How are QGLWidget's glXXX function calls handled?

How does Qt handle the function calls to various OpenGL functions such as glVertex3f in a QGLWidget?

Are these calls part of the QGLWidget object or are they strictly the global namespace OpenGL functions?

What is the best practice for drawing on a QGLWidget from a separate class?

Upvotes: 1

Views: 1027

Answers (2)

datenwolf
datenwolf

Reputation: 162367

Those gl… functions are just the regular OpenGL functions, or if a extension wrapper is being used the macro names resolving to the wrapper's symbols. QGLWidget takes care of OpenGL context creation and management, just like GLUT or GLFW do.

QGLWidget offers the member function QGLWidget::makeCurrent which selects the QGLWidget instance's OpenGL context being the current context in the thread from which QGLWidget::makeCurrent is called. QGLWidget::swapBuffers issues the double buffer swap. After you're done using the OpenGL context, say at the end of a renderer function, call QGLWidget::doneCurrent which will detach the context from the current thread; this is neccesary to make OpenGL work in multithreaded programs – if you make sure that all OpenGL operations are done from the very same thread, you may omit the call to QGLWidget::doneCurrent.

Of course in a true OOP fashion program, you should pass a reference to the other class to your derivation of QGLWidget and call that one's drawing function from the QGLWidget's drawing handler.

Upvotes: 3

baysmith
baysmith

Reputation: 5212

They are global namespace OpenGL functions.

Call the drawing function of the other class in the paintGL() function.

void MyGLWidget::paintGL()
{
    other->draw();
}

Upvotes: 1

Related Questions