PDA

View Full Version : fullscreen opengl



k2
2nd February 2009, 15:57
How can I create a borderless OpenGL window that covers the whole screen? Currently I'm working in Vista but I would like it to work anywhere.

I have inherited from QGLWidget and gave it no parent so it would be a top level window. I'm currently drawing a fullscreen quad in my paintGL() function. Since Qt doesn't seem to have the ability to change the video mode, I do that using win32 function calls similar to here (http://support.microsoft.com/kb/308216).

Part of the problem is, I would like this window to be on my second monitor in a dual-monitor setup, and I'll have other Qt windows on the first monitor.

I detect the geometry of the second monitor just fine using:



int i = QApplication::desktop()->primaryScreen();
int j = 0;
for (j = 0; j < QApplication::desktop()->numScreens(); ++j) {
if (j != i)
break;
}
const QRect rect = QApplication::desktop()->screenGeometry(j);


I then:



setGeometry(rect);
updateGeometry();


Which seems to work, except I can see the border of the window on my primary monitor. Also, I can minimize and move the window on the second monitor, which I would like to prevent.

I have tried:


this->showFullscreen();

This leaves a black bar above my fullscreen quad that seems to be about the size of the title bar if the title bar was visible.

I have also tried:



setFixedSize(w, h);
setWindowFlags(Qt::FramelessWindowHint);


which fails to create the QGLWidget because the QGLContext fails to create. Apparently you cannot create a frameless OpenGL widget?

I have also tried this->resize(w, h) and this->show() but none of these options seem to create what I want: a fullscreen, borderless/frameless, OpenGL window.

Anyone have any ideas? Thank you.

wysota
2nd February 2009, 16:21
showFullScreen() should be working fine. If it doesn't then maybe that's because of those native calls you used to change the resolution or because of the dual head setup (which would suggest a bug in Qt). See what happens if you run the application on a single screen and/or without changing the resolution.

k2
2nd February 2009, 19:30
If I do:



setGeometry(rect);
showFullScreen();
show();


Then the window correctly moves to the 2nd monitor, and removes the frame/border, but has a black bar above my fullscreen quad (presumably the size of the title bar).

I removed the change screen resolution code, it's not the problem I think.

When I move it to just one monitor (removing the setGeometry() call), I end up having my two windows: my main QApplication window (which has child widgets, etc), and my second, fullscreen OpenGL window behind it. When I click on the OpenGL window to focus on it, the black bar goes away. When I click anywhere on my second monitor, the black bar reappears.

So, I think this is a bug/feature/behavior of Qt. When the window has focus, it's "really" fullscreen, otherwise there is an invisible black bar the size of the title bar. I can't get the bar to go away when I use my second monitor for anything, nor can I get it to go away when I launch my QGLWidget to open on the second monitor (which is why I have the setGeometry() call, to move it to the second monitor).

Any other ideas? That was very helpful, but it looks like I have to either live with a black bar over my fullscreen app, or more likely live with the window borders leaking over to my first monitor.

Perhaps I can get different behavior from something other than QGLWidget? Maybe QDialog?

wysota
3rd February 2009, 00:23
Is the main window set to be always on top? Could you try it on a different machine, possibly with a different graphics chip?

k2
30th April 2009, 18:15
I realize this post is old but for anyone else who may benefit:

I solved this by using a QGraphicsView as the top level window, instead of a QGLWidget directly. You set the viewport of the QGraphicsView to be a QGLWidget, and you set the scene to be a QGraphicsScene, and you do your OpenGL rendering in the QGraphicsScene::drawBackground() function.

See this for more information:

http://doc.trolltech.com/qq/qq26-openglcanvas.html

I can create a fullscreen/borderless window using Qt::FramelessWindowHint as the window flags as long as the top level widget is a QGraphicsView instead of a raw QGLWidget. Don't ask me why. I am using Vista/ATi at the moment, haven't tested on other platforms.

The screen resolution changing (video mode change) is still done by non-Qt code. Once the resolution is set I can stretch the Qt window across it using setGeometry() as above. Note that this is not "true" fullscreen as it stretches the window over the windows taskbar. True fullscreen could probably be had with libSDL or another library, and then mixing it with Qt.

Edit: I forgot to mention that I don't use the showFullscreen() function, just the setGeometry() function. The black bar does not appear when the window (on the second monitor) doesn't have focus.