Fullscreen Undecorated Window Flashing On Focus Change

Started by jakj, October 21, 2012, 15:31:20

Previous topic - Next topic

jakj

Java 7u7 64-bit, Windows 7 64-bit, LWJGL 2.8.4, nVidia GTX 460

The following code creates a simple undecorated window that works perfectly fine, except that when both losing and gaining focus from the OS, the entire desktop (both the window itself and my other monitor) flicker once or twice. No other rendering glitches are apparent. If I make the window even one pixel smaller (in either dimension) than my primary monitor, it does not do this, but it also does not draw over the taskbar. If I explicitly give dimensions to a DisplayMode constructor, the same behaviour results: Flickering and drawing over taskbar if the size of my screen; No flickering and not drawing over taskbar if not the size of my screen.

(The intended behaviour is matching the size of my screen, no flickering, and drawing over the taskbar.)

System . setProperty ( "org.lwjgl.opengl.Window.undecorated" , "true" ) ;

		try
		{
			Display . setDisplayMode ( Display . getDesktopDisplayMode ( ) ) ;

			Display . create ( new PixelFormat ( ) , new ContextAttribs ( 4 , 2 ) . withProfileCore ( true ) . withForwardCompatible ( true ) ) ;
		}
		catch ( LWJGLException Exception )
		{
			Log . Log ( Exception ) ;

			Terminate . Abnormally ( ) ;
		}


matanui159

I'm not really sure what you are asking but when I start up a fullscreen program my screen flashes a few times. I think it is just changing the display or initialising the display or something else low-level. I just guessed that is what supposed to happen...

Well anyway, I don't know, I don't know nothing, I don't know if I don't know nothing... ???
ALGORITHM
A word used by programmers when they do not want to explain what they did.

WEE :)

matanui159

Also as an extra note...

I'm not sure but I think a few games do the same thing...

Again, I don't know if I don't know nothing... ???
ALGORITHM
A word used by programmers when they do not want to explain what they did.

WEE :)

senberg

Necro time.

So, I ran into this problem and I've been googling like crazy. I figured out the solution and implemented it and just wanted to share it for future googlers.

The problem is that if you have a non-full screen window that is positioned at 0,0 and covers all pixels of the screen windows will try to redirect the frame buffers for performance directly to the window. If a windows window has the flag WS_POPUP set while using this logic the screen will flickers when you focus and unfocus the window. The solution is to not set that flag, unfortunately this is buried deep in the lwjql code and I had to use the following semi hack to actually get to the windows window from the glfw window. If someone has a nicer looking solution, feel free to share :)

// in your application configuration, use config.setInitialVisible(false);

// in your create() method

    @Override
    public void create() {
        preventFlickering();

        ....
    }

    private void preventFlickering() {
        long hGLFWwindow = GLFW.glfwGetCurrentContext();
        long hWnd = GLFWNativeWin32.glfwGetWin32Window(hGLFWwindow);
        long style = User32.GetWindowLongPtr(hWnd, User32.GWL_STYLE);
        style &= ~User32.WS_POPUP;
        User32.SetWindowLongPtr(hWnd, User32.GWL_STYLE, style);
        GLFW.glfwShowWindow(hGLFWwindow);
    }