[Qt-interest] Where to initialize GLEW?

Joe Liu passer.by007gg at gmail.com
Mon Jun 29 16:19:01 CEST 2009


Hi Samuel,

Are you sure 'QGLWidget use context sharing'? I have two GLWindow classes:
CGLWnd1, CGLWnd2 which are both derived from class QGLWidget.

In intializeGL() of each GLWindow class, I generate a texture by using
glGenTexture(), like this:

class CGLWnd1 : public QGLWidget
{
    void initializeGL()
   {
       int tex;
       glGenTexture(1, &tex);
       cout<<tex;
   }
};

class CGLWnd2 : public QGLWidget
{
    void initializeGL()
   {
       int tex;
       glGenTexture(1, &tex);
       cout<<tex;
   }
};

CGLWnd1 a;
CGLWnd2 b;

a.initializeGL();
b.initializeGL();

The result outputs are the same: 1;

If the QGLWidget use context sharing, I think the generated texture won't
have the same texture id;

What is your opinion?

Thanks~~


2009/6/29 Joe Liu <passer.by007gg at gmail.com>

> Thanks Samuel,
>
> I would like to implement my own FBO class.
>
> So the QGLWidget use the context sharing mechanism. I am going to read more
> about it.
>
> Thanks again for your suggestions~~
>
> 2009/6/29 Samuel Rødal <sroedal at trolltech.com>
>
> 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
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090629/d546d3e9/attachment.html 


More information about the Qt-interest-old mailing list