[Qt-interest] where do you initialize Opengl?
John McClurkin
jwm at nei.nih.gov
Mon Nov 2 17:46:59 CET 2009
Don't send replys to me personally. Post all messages to the list. That
way others may have a chance to respond.
> i got qt warning "recursive repaint detected". and then found out that
> it was because my initialization failed. the initialization was called
> twice even though i have flag in the scene init().
A flag in scene.init() won't prevent the function from being called. The
idea is to use the flag to force scene.init() to return without
executing anything after the first call.
> qt seems to use multi threads. because before the first initialization
> was over, qt starts another initialization which is sparked by the
> updateGL() function which is fired by a keypressevent.
Qt doesn't use multiple threads. It allows you to create them, but if
you don't, there will be only one thread.
> the thing is that, my initialization takes a while, and during that
> time, if i press a key, the program will trap into the keyevent
> function, which will call update(). and since the first initializeGL()
> hasn't finished, another initializeGL() begins
If scene.init() takes a long time, you shouldn't call it in the
initializeGL() function but find a way to call it after the
initializeGL() function. If the user can't (or shouldn't be able to) do
anything until the scene.init() function completes, you probably need to
block user input until the function completes.
On Sat, Oct 31, 2009 at 1:15 PM, John McClurkin <jwm at nei.nih.gov> wrote:
> Shi Yan wrote:
>> hello guys,
>>
>> i'm writing a simple 3D CAD tool. i'm using the Model-view pattern. i
>> have several qglwidgets representing different cameras viewing the
>> same scene and a singleton class, which i call a "Scene".
>>
>> inside this "Scene" class, i define the geometry that needs to be
>> rendered and initialize GLSL shader language, etc.
>>
>> the problem where should i call Scene.init() ?
>>
>> one option is calling it within the initializeGL() function of a
>> qglwidgets. but there are many qglwidgets in my program. if i call
>> scene.init() inside initializeGL(), then the initialization will
>> execute several times.
>>
>> however, if i call scene initialization somewhere else (for example in
>> the main function), it will fail, because the opengl context hasn't
>> been set up yet:
>>
>> main()
>> {
>> QApplication app(argc, argv);
>> MainWindow mainWindow;
>> scene.init();
>> mainWindow.showMaximized();
>> return app.exec();
>> }
>>
>>
>> is there anyway to initialize opengl related settings right after QT
>> sets up the opengl?
>>
>> i think QT should pop up a signal after setting up Opengl. this signal
>> should be emitted by a global object, say QGLContext.
>>
>> and then, i can write a slot, once the opengl is ready, i call my
>> initialization function.
>>
>> hope you can give me some advice.
>>
>> is the Qt team reading this ? what do you think about the
>> "Opengl-ready signal"?
>>
>>
>> thanks.
> Include a flag in your Scene.init() function that only allows the code
> to execute one time.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
--
Dept. of Computer Science
University of California, Davis
Homepage:http://wwwcsif.cs.ucdavis.edu/~yans/
More information about the Qt-interest-old
mailing list