[Qt-interest] Where to initialize GLEW?

Samuel Rødal sroedal at trolltech.com
Mon Jun 29 09:17:37 CEST 2009


Joe Liu wrote:
> Hi,
> 
> I would like to implement my FBO class with GLEW; As you know, users 
> should invoke glewInit() after an OpenGL rendering context is created 
> and before calling any glew functions.
> 
> Since I use QGLWidget as the base class of my opengl window class, and 
> my GLWindow might have more than one instances, so if I put glewInit() 
> in function initializeGL(), it will be called for multiple times. I 
> think that is ugly.
> 
> What is the right manner to call glewInit() in a Qt OpenGL program? Is 
> there any way to check whether the GLEW is initialized or not?
> 
> BTW, what will glewInit() do exactly? Is it associated with GL Rendering 
> Context? And How does the QGLWidget manage the Rendering Context?
> 
> Thank for your time~~
> 
> 
> Joe

Calling glewInit() will initialize function pointers related to the 
available OpenGL extensions, and let you query which extensions are 
available. See http://glew.sourceforge.net/basic.html

If you want to use GLEW from multiple contexts you should have a look at 
the Multiple Rendering Contexts section at 
http://glew.sourceforge.net/advanced.html

As long as your QGLWidgets use context sharing I don't think it should 
be necessary to use GLEW MX, though I'm not certain on this.

For the single context case you can call glewInit() either 
initializeGL() or right after the QGLWidget has been constructed (in the 
latter case you need to call QGLWidget::makeCurrent() first, this 
happens automatically before initializeGL() is called).

Btw, there's a QGLFramebufferObject class in Qt already, are you sure 
you need to implement your own?

--
Samuel



More information about the Qt-interest-old mailing list