Results 1 to 5 of 5

Thread: fullscreen opengl

  1. #1
    Join Date
    Feb 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default fullscreen opengl

    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.

    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:

    Qt Code:
    1. int i = QApplication::desktop()->primaryScreen();
    2. int j = 0;
    3. for (j = 0; j < QApplication::desktop()->numScreens(); ++j) {
    4. if (j != i)
    5. break;
    6. }
    7. const QRect rect = QApplication::desktop()->screenGeometry(j);
    To copy to clipboard, switch view to plain text mode 

    I then:

    Qt Code:
    1. setGeometry(rect);
    2. updateGeometry();
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. this->showFullscreen();
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. setFixedSize(w, h);
    2. setWindowFlags(Qt::FramelessWindowHint);
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: fullscreen opengl

    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.

  3. #3
    Join Date
    Feb 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: fullscreen opengl

    If I do:

    Qt Code:
    1. setGeometry(rect);
    2. showFullScreen();
    3. show();
    To copy to clipboard, switch view to plain text mode 

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: fullscreen opengl

    Is the main window set to be always on top? Could you try it on a different machine, possibly with a different graphics chip?

  5. #5
    Join Date
    Feb 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: fullscreen opengl

    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.

Similar Threads

  1. OpenGL and Qt Question
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2009, 18:04
  2. Qt Embedded + OpenGL problem
    By EeroS in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 7th October 2008, 14:32
  3. QT + OpenGL + Thread => aaaahhhhh !
    By anthibug in forum Qt Programming
    Replies: 7
    Last Post: 26th July 2008, 13:36
  4. openGL in Qtopia core
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 18th July 2008, 11:26
  5. Qtopia Core & OpenGL ES?
    By zelko in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th May 2007, 07:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.