# Correct order for making fullscreen with poll events and window refresh, etc

**URL:** <https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069>\
**Category:** support\
**Created:** [January 21, 2018, 11:56pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069 "2018-01-21T23:56:26Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![IanLilleyT](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/ianlilleyt/32/162_2.png) [@IanLilleyT](https://discourse.glfw.org/u/IanLilleyT)\
**Post date:** [January 21, 2018, 11:56pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/1 "2018-01-21T23:56:26Z")

</div>

My project has an option to toggle between fullscreen and windowed mode through the user interface. The main problem is when I go into fullscreen mode, I momentarily see the window mid-transition to fullscreen (I can briefly see a windows 7 style title bar, random glitches, etc). This is not a major issue, but solving it will help me understand the interaction between GLFW and my own code better. I’m on Windows 10 and Nvidia (latest for both). There are no GL or GLFW errors. The application is single-threaded. I have windowWidth, windowHeight, and goToFullscreen global variables.

My loop looks like:

**Update**

- updates core code and UI with windowWidth and windowHeight. sets goToFullscreen to either true or false.

**Render**

- sets viewport to windowWidth and windowHeight and renders the scene

**glfwSwapBuffers**

**glfwPollEvents**

- can trigger GLFWwindowrefreshfun (inside which calls Render and glfwSwapBuffers again, useful for any type of window resize, not just fullscreen)

**MakeFullscreen**

- if goToFullscreen is true, calls glfwSetWindowMonitor(glfwWindow, monitor, 0, 0, videoMode-\>width, videoMode-\>height, videoMode-\>refreshRate);
- automatically triggers GLFWframebuffersizefun, which updates windowWidth and windowHeight

**RendererResize**

- called whenever windowWidth or windowHeight changes from previous frame, including when resizing window manually, or when graphics quality changes (doesn’t affect UI):
- glFinish(probably unnecessary)
- internal GL FBO/texture resize

Here’s a printout during a fullscreen (starting and ending with random normal frames):

> – frame count 677 –  
> Update at 1280 720  
> Render at 1280 720  
> glfwSwapBuffers  
> glfwPollEvents  
> – frame count 678 –  
> Update at 1280 720  
> Render at 1280 720  
> glfwSwapBuffers  
> glfwPollEvents  
> MakeFullscreen  
> GLFWframebuffersizefun at 1296 759  
> GLFWframebuffersizefun at 1920 1080  
> RenderResize at 1920 1080  
> – frame count 679 –  
> Update at 1920 1080  
> Render at 1920 1080  
> glfwSwapBuffers  
> glfwPollEvents  
> GLFWwindowrefreshfun at 1920 1080 (\*1)  
> Render at 1920 1080  
> glfwSwapBuffers  
> – frame count 680 –  
> Update at 1920 1080  
> Render at 1920 1080  
> glfwSwapBuffers  
> glfwPollEvents

When I move the MakeFullscreen and RenderResize checks BEFORE the glfwPollEvents, I get:

> – frame count 363 –  
> Update at 1280 720  
> Render at 1280 720  
> glfwSwapBuffers  
> glfwPollEvents  
> – frame count 364 –  
> Update at 1280 720  
> Render at 1280 720  
> glfwSwapBuffers  
> MakeFullscreen  
> GLFWframebuffersizefun at 1296 759  
> GLFWframebuffersizefun at 1920 1080  
> RenderResize at 1920 1080  
> glfwPollEvents  
> GLFWwindowrefreshfun at 1920 1080  
> Render at 1920 1080 (\*2)  
> glfwSwapBuffers  
> – frame count 365 –  
> Update at 1920 1080  
> Render at 1920 1080  
> glfwSwapBuffers  
> glfwPollEvents

Both versions I can see the glitchy mid-transition state of the window for an instant. The first version effectively ignores the refresh callback (\*1) because the glfwPollEvents that triggers it happens on the next frame. I’m using this version because Update and Render are always in sync with window size. The second version is cleaner but has an intermediate Render that uses out-of-date values from Update (\*2), causing my UI and other things to pop for a frame. The closer refresh seems to make no difference. The glitchy effect is more pronounced in Debug mode where CPU loads are heavier, which might be why I don’t see the problem with GLFW examples.

Overall, I think I have some misconceptions about fullscreen/windowed, framebuffer size and refresh callbacks, swapbuffers, and polling. Or maybe it’s a problem outside of my code or GLFW?

Side questions:

1. Why is there a 1296x759 resize?
2. Why does GLFW recommend calling glfwPollEvents after glfwSwapbuffers? A loop of: {PollEvents, Update, Render, SwapBuffers, CheckClose} doesn’t seem functionally different than {Update, Render, SwapBuffers, PollEvents, CheckClose} except for the first and last frame. The documentation says:

> GLFW needs to communicate regularly with the window system both in order to receive events and to show that the application hasn’t locked up. Event processing must be done regularly while you have visible windows and is normally done each frame after buffer swapping.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [January 22, 2018, 10:52am UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/2 "2018-01-22T10:52:05Z")

</div>

Some answers:

1. I don’t know why you’re seeing a 1296x759 resize. I don’t on the systems I’ve tested on, though I don’t have a Windows 10 machine with NVIDIA GPU installed at the moment.
2. The [glfwPollEvents function](http://www.glfw.org/docs/latest/group__window.html#ga37bd57223967b4211d60ca1a0bf3c832) can stall on some systems as per documentation: “_On some platforms, a window move, resize or menu operation will cause event processing to block._” So it’s a good idea to call it after having swapped the last thing you rendered to the screen. You can also put rendering on a separate thread, though this is obviously more complicated. Putting it first is as you say logically similar, and it’s OK to do this.

I don’t have an answer as to how to achieve a clean fullscreen resize with GLFW or OpenGL. On my AMD GPU with Windows 10 I always get a black screen flicker during transition, and neither GLFW or my app is doing a clear to black so I suspect this is an OpenGL driver issue.

---

<div class="post-metadata">

**Author:** ![elmindreda](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/elmindreda/32/26_2.png) [@elmindreda](https://discourse.glfw.org/u/elmindreda)\
**Post date:** [January 22, 2018, 1:06pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/3 "2018-01-22T13:06:33Z")

</div>

> [@IanLilleyT](#):
>
> Why is there a 1296x759 resize?

Because currently removal of window decorations and resizing to fit the monitor are done separately. It can be done in a single operation but it’ll take some internal restructuring.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [January 22, 2018, 4:42pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/4 "2018-01-22T16:42:48Z")

</div>

Quick note:

Using the github master code for GLFW 3.3 and the [glfwSetWindowAttrib](http://www.glfw.org/docs/3.3/group__window.html#gace2afda29b4116ec012e410a6819033e) I could set the decorated style to false when going fullscreen and reverting on going windowed, and this made window switching slightly nicer.

This could provide a workaround without changing GLFW code if you need improved transitions.

---

<div class="post-metadata">

**Author:** ![IanLilleyT](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/ianlilleyt/32/162_2.png) [@IanLilleyT](https://discourse.glfw.org/u/IanLilleyT)\
**Post date:** [January 22, 2018, 9:09pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/5 "2018-01-22T21:09:38Z")

</div>

Doug, interesting tip but it doesn’t work all the time.

I got master. I did `glfwSetWindowAttrib(glfwWindow, GLFW_DECORATED, GLFW_FALSE)` before `glfwSetWindowMonitor` for fullscreen and after for windowed. I can still see the blue windows 7 style title bar occasionally, hard to say if more or less frequently than before. When I manually step through the code the windows 10 title bar goes away after the attrib call, but it’s difficult to see what’s going on with the actual fullscreen action when the debugger is active.

---

<div class="post-metadata">

**Author:** ![ghuser404](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/ghuser404/32/140_2.png) [@ghuser404](https://discourse.glfw.org/u/ghuser404)\
**Post date:** [January 24, 2018, 3:49pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/6 "2018-01-24T15:49:49Z")

</div>

> I can briefly see a windows 7 style title bar

I have definitely seen this happen. I think I even debugged it and it had something to do with use of styles, but don’t quote me on that. Sadly, I can’t remember why I didn’t report this issue.

---

<div class="post-metadata">

**Author:** ![ghuser404](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/ghuser404/32/140_2.png) [@ghuser404](https://discourse.glfw.org/u/ghuser404)\
**Post date:** [January 24, 2018, 6:41pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/7 "2018-01-24T18:41:52Z")

</div>

@IanLilleyT Can I ask you if your Windows is up-to-date? I tried reproducing the windows-7-style-title-bar thing, but couldn’t. This thing could definitely be affected by Windows update, because recently they seem to have broken the window icon - I have raised an issue in GLFW repo for this: [1163](https://github.com/glfw/glfw/issues/1163)

---

<div class="post-metadata">

**Author:** ![IanLilleyT](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/ianlilleyt/32/162_2.png) [@IanLilleyT](https://discourse.glfw.org/u/IanLilleyT)\
**Post date:** [January 24, 2018, 7:22pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/8 "2018-01-24T19:22:44Z")

</div>

I’m on Windows 10, version 1709. I actually did a windows update in the middle of investigating this problem, but it made no difference. What do you mean by use of styles?

---

<div class="post-metadata">

**Author:** ![ghuser404](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/ghuser404/32/140_2.png) [@ghuser404](https://discourse.glfw.org/u/ghuser404)\
**Post date:** [January 24, 2018, 7:29pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/9 "2018-01-24T19:29:28Z")

</div>

I mean Windows API styles, for example WS\_POPUP.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [January 24, 2018, 7:38pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/10 "2018-01-24T19:38:30Z")

</div>

The Windows 7 style menu bar only popped into existante during full screen  
switch when I used latest GLFW. Released versions did not do this for me.

---

<div class="post-metadata">

**Author:** ![ghuser404](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/ghuser404/32/140_2.png) [@ghuser404](https://discourse.glfw.org/u/ghuser404)\
**Post date:** [January 24, 2018, 7:46pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/11 "2018-01-24T19:46:12Z")

</div>

@dougbinks Do you know how to exactly reproduce it?

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [January 24, 2018, 8:33pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/12 "2018-01-24T20:33:09Z")

</div>

Yes, get latest from git hub and switch from wondowed to fullscreen.

I may have time to investigate why this happens later buy am busy for the  
next few days.

---

<div class="post-metadata">

**Author:** ![ghuser404](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/ghuser404/32/140_2.png) [@ghuser404](https://discourse.glfw.org/u/ghuser404)\
**Post date:** [January 24, 2018, 9:08pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/13 "2018-01-24T21:08:06Z")

</div>

Well, I’ve done this but it is not happening.

---

<div class="post-metadata">

**Author:** ![elmindreda](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/elmindreda/32/26_2.png) [@elmindreda](https://discourse.glfw.org/u/elmindreda)\
**Post date:** [February 7, 2018, 7:33pm UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/14 "2018-02-07T19:33:00Z")

</div>

The fix for the double resize event has been merged.

> <https://github.com/glfw/glfw/commit/d10463ac91e06712438412f3a1a60a7ee4672e71>

---

<div class="post-metadata">

**Author:** ![IanLilleyT](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/ianlilleyt/32/162_2.png) [@IanLilleyT](https://discourse.glfw.org/u/IanLilleyT)\
**Post date:** [February 26, 2018, 1:59am UTC](https://discourse.glfw.org/t/correct-order-for-making-fullscreen-with-poll-events-and-window-refresh-etc/1069/15 "2018-02-26T01:59:27Z")

</div>

For what it’s worth, Microsoft’s very own D3D12 Fullscreen example program has this same issue with the Win7-style title bar (tested on Win10)
