# Fullscreen window blinking

**URL:** <https://discourse.glfw.org/t/fullscreen-window-blinking/1538>\
**Category:** support\
**Created:** [April 15, 2020, 3:54pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538 "2020-04-15T15:54:23Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdegrande](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/sdegrande/32/326_2.png) [@sdegrande](https://discourse.glfw.org/u/sdegrande)\
**Post date:** [April 15, 2020, 3:54pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/1 "2020-04-15T15:54:23Z")

</div>

Hi.

I’m using GLFW for a VR painting project at work.

I use threads to async-load heavy 3D Models, with their own opengl context, created using an invisible window, as proposed in the GLFW doc. The temp windows are created and destructed in the main thread. It works well.

But, on windows (10), if the main window (main thread) is fullscreen, there is a black blink when a temp window is destructed. There is no such issue on Linux. I traced it down to the call to win32 DestroyWindow().

So my question is : do you expect to add (more or less soon) a function to create an opengl context without creating a window ?

---

<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:** [April 19, 2020, 12:09pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/2 "2020-04-19T12:09:56Z")

</div>

There was an issue for this which is now closed:

> <https://github.com/glfw/glfw/issues/648>
>
> GLFW is described as:
> GLFW is an Open Source, multi-platform library for creating windows with OpenGL contexts and receiving input and events.
> I've...

Background loading of models on a seperate thread with OpenGL without using a seperate context is possible, mainly by loading the model and textures into memory and then creating the required OpenGL state on the context thread, as it’s usually the file loading and processing which takes the time.

You can also use persistent mapping, or map the buffer on the main thread and then copy the data on another thread.

---

<div class="post-metadata">

**Author:** ![sdegrande](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/sdegrande/32/326_2.png) [@sdegrande](https://discourse.glfw.org/u/sdegrande)\
**Post date:** [April 21, 2020, 8:33am UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/3 "2020-04-21T08:33:18Z")

</div>

Thanks for your reply.

That issue was rather about creating a gl context without creating a window, if I’m not wrong ?

I’m aware of the other ways to load 3D models using threads. I was just wondering if it is expected to add calls to ‘directly’ create shared gl context, based on an already opened window (so that you already have the window context, pixel format and so on, needed to create a gl context).

---

<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:** [April 21, 2020, 9:28am UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/4 "2020-04-21T09:28:24Z")

</div>

> [@sdegrande](#):
>
> That issue was rather about creating a gl context without creating a window, if I’m not wrong ?

Yes, since your original question was:

> [@sdegrande](#):
>
> So my question is : do you expect to add (more or less soon) a function to create an opengl context without creating a window ?

So if I understand it your actual question is _“do you expect to add a function to create multiple OpenGL contexts for one window?”_.

I don’t expect this to be added unless there is a large demand or someone is willing to undertake the work across all OS GLFW supports. This is relatively easy on windows but I don’t know about some of the other platforms.

---

<div class="post-metadata">

**Author:** ![sdegrande](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/sdegrande/32/326_2.png) [@sdegrande](https://discourse.glfw.org/u/sdegrande)\
**Post date:** [April 21, 2020, 1:26pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/5 "2020-04-21T13:26:56Z")

</div>

> [@dougbinks](#):
>
> Yes, since your original question was:…

Ah, yes, sorry. My english is not that good, and the question was indeed not precise enough…

> [@dougbinks](#):
>
> So if I understand it your actual question is _“do you expect to add a function to create multiple OpenGL contexts for one window?”_ .

Exactly !

> [@dougbinks](#):
>
> I don’t expect this to be added…

Ok. Thanks for your reply and for your great work (I could possibly help with the GLX port, if ever needed).

---

<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:** [April 24, 2020, 2:53pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/6 "2020-04-24T14:53:03Z")

</div>

Coming back to this it would seem to me that an easier solution for you would be to keep the invisible window open and re-use it when you need to load another model.

If you’re interested in working on a multiple contexts for one window then I would create an issue and/or start an implementation with your favourite platform as a proof of concept. There is a related issue:

> <https://github.com/glfw/glfw/issues/1501>
>
> Does GLFW intend to support splitting one window into multiple contexts (i.e. subwindows)? There's a similar thing in GLUT and would...

---

<div class="post-metadata">

**Author:** ![sdegrande](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/sdegrande/32/326_2.png) [@sdegrande](https://discourse.glfw.org/u/sdegrande)\
**Post date:** [April 29, 2020, 8:48am UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/7 "2020-04-29T08:48:40Z")

</div>

Yes, one hidden window could be kept and reused. Or even a pool of hidden windows could be used to enable parallel loading of several models (can be useful in some cases). But that’s more or less a ‘trick’, right ?

So yes, multiple contexts for one window would be the preferable solution (imho)… If you agree to start writing a POC for Windows (by defining the API and possibly the datastuct to record the contexts), I’m definitely willing to help. We are coding for Windows/Mingw-w64 and Linux, but I could also potentially have a look at macos (I’ve got a MacMini).

---

<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:** [April 29, 2020, 3:49pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/8 "2020-04-29T15:49:42Z")

</div>

> [@sdegrande](#):
>
> But that’s more or less a ‘trick’, right ?

I wouldn’t call it a ‘trick’ - it is a robust and workable approach.

I have submitted an issue for this:

> <https://github.com/glfw/glfw/issues/1687>
>
> The following thread on discourse discusses a need for multiple contexts for a w…indow:
> https://discourse.glfw.org/t/fullscreen-window-blinking/1538/4
> 
> I am unsure about the overall benefit of multiple contexts for OpenGL these days, and I think it's best to keep GLFW as lean as possible, however this is something which is currently not possible to do with GLFW without altering core GLFW code so I think it's reasonable to consider.
> 
> Potential approaches:
> 
> 1. Expose the required OS specific information via the GLFW native API, for example on Windows WGL requires the device context \`window-\>context.wgl.dc\` which is not currently exposed. Users could then write their own OS specific code to create contexts.
> 2. Add \`GLFWUserContext\* glfwCreateUserGLContext(GLFWwindow\* window)\` and supporting functions, see below. I have named these User Contexts to differentiate from the GLFW context created along with the window.
> 
> For 2 we would need
> \`\`\`
> // Create a new context for a window
> GLFWUserContext\* glfwCreateUserGLContext(GLFWwindow\* window);
> 
> // Delete a context
> void glfwDestroyUserContext(GLFWUserContext\* context);
> 
> // Make a context current
> void glfwMakeUserContextCurrent(GLFWUserContext\* context);
> 
> // Get current context - returns NULL if primary window context is current,
> // in which case glfwGetCurrentContext would return window, and
> // glfwGetCurrentContext will return NULL if a user context is current.
> GLFWUserContext\* glfwGetCurrentUserContext(void);
> \`\`\`
> 
> I can create the Windows versions of the API, and sdegrande can help with the GLX and potentially Mac.
> 
> This is potentially related to #1501

However I am unsure adding to the GLFW API for this is a good idea given that there are other, perhaps better, solutions.

---

<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:** [June 7, 2020, 6:27pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/9 "2020-06-07T18:27:43Z")

</div>

I now have an initial implementation on Windows:

> <https://github.com/glfw/glfw/issues/1687#issuecomment-638399075>
>
> The following thread on discourse discusses a need for multiple contexts for a window:
> https://discourse.glfw.org/t/fullscreen-window-blinking/1538/4
> I am unsure about the overall benefit of...

If you are able to confirm this meets your needs I’ll progress with the other OS implementations.

---

<div class="post-metadata">

**Author:** ![sdegrande](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/sdegrande/32/326_2.png) [@sdegrande](https://discourse.glfw.org/u/sdegrande)\
**Post date:** [July 1, 2020, 4:03pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/10 "2020-07-01T16:03:10Z")

</div>

Sorry, I’ll only be able to check next week, when we’ll be authorized to return at work.

---

<div class="post-metadata">

**Author:** ![sdegrande](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/sdegrande/32/326_2.png) [@sdegrande](https://discourse.glfw.org/u/sdegrande)\
**Post date:** [July 7, 2020, 12:52pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/11 "2020-07-07T12:52:57Z")

</div>

I finally had the opportunity to test your patch.  
It works like a charm, and was super easy to implement.

As you mentioned in the FR, `glfwGetCurrentUserContext()` is not needed (at least in my case), given that I create one user context per thread (used to async-load a 3D model) and so I keep a reference to the created user context in each thread.

Thanks a lot for your work !

Do you expect to include it in the next 3.3 release, anytime soon ? Or at least on your master branch ?

---

<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:** [July 7, 2020, 2:03pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/12 "2020-07-07T14:03:43Z")

</div>

Excellent - I’ll start implementing the other OS variants when I get time.

> [@sdegrande](#):
>
> Do you expect to include it in the next 3.3 release, anytime soon ?

First we need to implement this for other OS, write the documentation and release notes, then there will be a pull request followed by a review and merging. This can take some time, there are 46 open Pull Requests, some of them going back years - this is an open source community driven project so giving any timing is difficult.

This is a fairly simple branch to maintain, so my advice would be to fork GLFW, create your own branch and then merge my branch or just cherry pick the changes so you can keep control of your own version.

> [@sdegrande](#):
>
> Or at least on your master branch

I presume you mean the GLFW master branch, in which case as above this takes time.

---

<div class="post-metadata">

**Author:** ![sdegrande](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/sdegrande/32/326_2.png) [@sdegrande](https://discourse.glfw.org/u/sdegrande)\
**Post date:** [July 8, 2020, 2:29pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/13 "2020-07-08T14:29:12Z")

</div>

> [@dougbinks](#):
>
> this is an open source community driven project so giving any timing is difficult.

I’m also in the dev team of a FOSS project, so I fully understand. No worry at all !

Thanks for your work.

---

<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:** [July 8, 2020, 6:50pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/14 "2020-07-08T18:50:52Z")

</div>

Great - do you have any priorities for the OS implementations you need?

---

<div class="post-metadata">

**Author:** ![sdegrande](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/sdegrande/32/326_2.png) [@sdegrande](https://discourse.glfw.org/u/sdegrande)\
**Post date:** [July 9, 2020, 2:50pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/15 "2020-07-09T14:50:11Z")

</div>

WGL and GLX are what we currently use.  
We are currently working on a port to Vulkan, but it will take some months before it will be ready.

I had a look to glx\_context,c, expecting to propose you a GLX implementation, but as far as I can see, it would need to keep track of the FBConfig chosen when the main window was created, and so probably a change of a current struct (store the FBConfig into window-\>context.glx ?). Such a ‘deep change’ is not something that I can do without an ack of the dev-leader…

---

<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:** [July 9, 2020, 3:38pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/16 "2020-07-09T15:38:15Z")

</div>

I’ll take a look at GLX shortly - probably over the weekend.

Vulkan is quite different to OpenGL, and the window is created without a context then a Vulkan window surface is created which is used to present the render to the screen. There is no direct equivalent of the OpenGL context, and many functions are thread safe. Thus there isn’t a need (or even a potential) for this API to be ported to Vulkan.

---

<div class="post-metadata">

**Author:** ![sdegrande](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/sdegrande/32/326_2.png) [@sdegrande](https://discourse.glfw.org/u/sdegrande)\
**Post date:** [July 9, 2020, 4:05pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/17 "2020-07-09T16:05:26Z")

</div>

> [@dougbinks](#):
>
> I’ll take a look at GLX shortly - probably over the weekend.

Great ! Thanks !

> [@dougbinks](#):
>
> Thus there isn’t a need (or even a potential) for this API to be ported to Vulkan.

Ok, Thanks for the information. I’m not the one working on the Vulkan port, so I do not (yet) know a lot about 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:** [July 17, 2020, 2:06pm UTC](https://discourse.glfw.org/t/fullscreen-window-blinking/1538/18 "2020-07-17T14:06:46Z")

</div>

I’ve updated the issue and would appreciate feedback on the new naming proposal:

> <https://github.com/glfw/glfw/issues/1687#issuecomment-660125799>
>
> The following thread on discourse discusses a need for multiple contexts for a window:
> https://discourse.glfw.org/t/fullscreen-window-blinking/1538/4
> I am unsure about the overall benefit of...
