PDA

View Full Version : Mulitple openGL windows



tcsvw5
28th February 2006, 17:21
Hello,

I'm writing an app where I need multiple openGL windows running. This windows are created dynamically by the user. The problem is as soon as the second window opens the first stops processing mouse events and never repaints. The second window works fine but the first stops. I'm hoping this is just something stupid i've done wrong and there is an easy fix.
Any ideas?
Travis

jacek
28th February 2006, 17:23
Could you post the code that opens that new window?

yogeshm02
28th February 2006, 17:24
As far as i understand only one 3d accelerated window can be active at a time.

tcsvw5
28th February 2006, 17:26
CGraphContainer* tmp = new CGraphContainer(); tmp->GetGraph()->SetPowerSystem(m_graph->GetPowerSystem());
tmp->GetGraph()->ConnectToServer("dell1.cs.umr.edu", 1208);
tmp->GetGraph()->SetHistory(m_graph->GetHistory());
tmp->show();
m_graphList.append(tmp);

CGraphContainer extends QMainWindow and is pretty basic just creates a new CGraph object which extends QGLWidget.

tcsvw5
28th February 2006, 17:31
Well, it works fine when I have two separate instances of the application running, just not when I have two windows within the same app.

Travis

jacek
28th February 2006, 17:34
As far as i understand only one 3d accelerated window can be active at a time.
This shouldn't be a problem. See opengl/textures example.

jacek
28th February 2006, 17:41
CGraphContainer* tmp = new CGraphContainer(); tmp->GetGraph()->SetPowerSystem(m_graph->GetPowerSystem());
tmp->GetGraph()->ConnectToServer("dell1.cs.umr.edu", 1208);
tmp->GetGraph()->SetHistory(m_graph->GetHistory());
tmp->show();
m_graphList.append(tmp);
There's nothing suspicious here. Maybe you block the event loop somewhere? Do you return from the method that shows that new window?

Which Qt version do you use?

KShots
1st March 2006, 20:36
I doubt there's anything wrong with your constructor. I ran into something similar with my MDI OGL app. Look at your input processor. Make sure you call updateGL() at the end - it will make that window's OpenGL context the current device context, then update that window. Remember, it will only update when you tell it to update. You either go with event-based updates (preferred) or timer-based updates. Your other window will use the same function (I'm assuming) and work accordingly.

Also, if you don't need to update the display, but you do need data from it, use the makeCurrent() function to make your QGLWidget's device context the current context.

tcsvw5
1st March 2006, 21:39
I am using Qt 3.2.1 and both windows have a timer based update scheme every 100ms if needed. The odd thing is that sometimes for a short period of time both windows operate together correctly but eventually the first window stops working.

Travis

jacek
1st March 2006, 22:19
How do you trigger the updates? Do you use QTimer?

KShots
1st March 2006, 23:12
Then what you need to check is your timer function. Make sure it calls your QGLWidget's updateGL() function on every timer interrupt. I'm 99.9% sure this is what you're running into based on those symptoms.

tcsvw5
2nd March 2006, 14:34
Yes, I'm using a QTimer to handle this, and it does call updateGL appropriately.
When i break into paintGL both objects get rerendered, however the first qglwidget remains black. This seems to always happen after I resize the first window. Up until then it works fine (handles mouse events; drags the display), but one I resize that first window it goes blank. The second window however works great, no problems.

jacek
2nd March 2006, 16:20
This seems to always happen after I resize the first window.
What do you do when that widget is resized? Did you reimplement the resizeEvent()?

nikikko
2nd March 2006, 17:52
Do you call makeCurrent ?
I have the same problem one day, and the solution is to call makeCurrent in the QGLWidget before updateGL.

tcsvw5
2nd March 2006, 21:05
In resizeGL I don't call updateGL. Doesn't that happen automatically?
The thing is when only one window is open and I resize it, it is updated correctly. It only happens when I have 2 (or more presumably) windows open.

No I don't call makeCurrent before calling updateGL. That shouldn't be necessary though since the correct context is always guarrenteed current in paintGL.

Also I'm using multiple QMainWindows for each of the frames housing my QGLWidgets. Is that possibly related to the problem?

Travis

tcsvw5
2nd March 2006, 21:09
Essientially my app is going to be a graph of a power grid where you are able to see the power flowing through the various lines. What I want is to be able to click a button on the toolbar and pop up another view of the system (with different settings).
So I have the first 'main' window which other windows will be created from. Now when I start two of theses windows from my main function everything appears to work correctly. However when i create a new window from within the first 'main' window (after a toolbar button click for example) i encounter the problems i mentioned before. And it is the exact same code as was used in the main function.

Any ideas?
Travis

tcsvw5
2nd March 2006, 21:12
Actually I take that back it doesn't appear to work even when the code is just in my main function.

Travis

tcsvw5
2nd March 2006, 21:25
It seems that multiple QFrame based windows works fine, but the QMainWindow doesn't.
Any ideas?

KShots
3rd March 2006, 14:53
Unfortunately, I can only speculate. I suspect that you may be running into problems through the use of multiple QMainWindows. Generally, you'd only want one of those. Might I suggest sticking your OpenGL windows into a QWorkspace, contained within a single QMainWindow? This would allow you to move the windows around inside the application, which may or may not be desirable. It also provides an easy way to add or remove OpenGL views (again, may or may not be desirable in your application).

If you don't want to use a QWorkspace to contain each QGLWidget, just use a QWidget for each QGLWidget (adding whatever else you need to the QWidget). You shouldn't need multiple QMainWindows.

tcsvw5
3rd March 2006, 17:57
Yeah that is probably the way this will have to go. Thanks for your help.

One last question.
I've also got a QPopupMenu set up as a right click menu on my openGl widgets however after the user selects an option on the popup menu (or clicks elsewhere to get rid of it) the openGL only renders under the portion of the screen where the popup menu had been.
Similarly this happens when I drag another window over my openGL widget, the openGL only seems to render under the area which was 'covered up' before.
This is happening with QT's openGL examples as well.
Is there a way aroudn this?

Thanks,
Travis