No rendering on child windows created by SetParent native api method

Hi,
glfw 3.3.2
windows 10
mingw32

I am creating a unified window system and using native api using SetParent function.

SetParent(glfwGetWin32Window(child), glfwGetWin32Window(parent));

It’s working perfectly fine and all the child windows seamlessly become one with the main window. All the child windows are created with no decoration. However, the problem is that when rendering, nothing appears. I’m setting the context using glfwMakeContextCurrent(child) just before rendering on the child window but nothing appears.
After searching on google I even tried this:

glfwMakeContextCurrent( window );   
auto hglrc = glfwGetWGLContext(window);
auto current_dc = wglGetCurrentDC();
wglMakeCurrent(current_dc, hglrc);

still no luck!!! If I don’t use the SetParent call then everything renders perfectly but that’s not the purpose. I would appreciate if someone point out the correct way to do it.
Cheers

Hi PrashantSaxena ,

Welcome to the GLFW forum.

I don’t know enough about child windows and OpenGL since when I’ve needed this behaviour I’ve simply closed the second window and rendered the window content to a region of the main window directly - this is also how the popular Dear ImGui docking branch works.

I did find a bit of code on Github using GLFW and SetParent, which I can’t find again (sorry). However it appeared to be resting some style attributes similar to the post below:

Perhaps that might work for you?

Good luck,
Doug.

Did anyone manage to figure this out? I tried the solution posted above and it didn’t work.

Hello Majisto
Well to be honest if you are seriously interested in parent-child stuff then better you go native and leave glfw. glfw was never designed to do this kind of stuff. Yes, you can make a child window but there is no point in doing so when all your windows are floating on your desktop screen.
Initially, I tried a lot to make this work in glfw but in the last, I gave up because it was not worth going that road. Later I programmed a multi-window manager individually using native api on all three major OS, Linux, OSX and MSWIN. It was kind of re-inventing the wheel but you can trust my words, it was worth it.

Why I did do so? Nowadays one can easily buy a 4k or 8k monitor and they are becoming part of mainstream rapidly. Even if you enable vertical sync, wait for events and do all kind of optimizations in glfw or the same, refreshing 4k-8k screen at 60 times per second is not at all a good idea. This issue is greatly discussed in a post at ImGui where users were complaining about the constant buzzing of gpu and cpu fans even when the system is laying idle.

Prashant

Adding idle handling (for minimized state and also no input or animation) code to a GLFW app is fairly trivial. This GLFW with Runtime Compiled C++ and Dear ImGui example has a section in the readme with a link to the code on power saving. I would also add a check for whether your windows are GLFW_ICONIFIED and disable rendering and GUI for them if they are.