-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Win32+OpenGL] ImGui Window goes pink when dragged out of the parent window #2600
Comments
Hello, |
The GLFW one works just fine, but I am not sure what is broken in my code since they both use the same win32 api. I thought I might have been the context changing but I tried that with this code // Update and Render additional Platform Windows
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
auto backUpDC = g_Device;
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
g_Device = backUpDC;
wglMakeCurrent(g_Device, g_GLDeviceContext);
} and still got the same result. I am not sure what I am doing wrong |
Hi, I'm curious about the |
Ah, it's in the viewport branch. Sorry for bothering. |
Hi @Rex-22, |
Hi @joramas, |
Hello, I have been having the same problem as detailed here. I believe that a large part of the problem is that there are four functions that are called inside imgui when drawing the viewports. The code that does the drawing can be seen here from imgui.cpp:
However, the imgui_impl_win32.cpp does not set these in its platform interface initialization code:
This is an issue as the only code that gets called is the code for the RenderWindow for the Renderer if you are using imgui_impl_opengl3.cpp as I am. This code does this:
No where in the code are buffers or contexts being swapped. Therefore, what I did was to add these two functions to the Win32 code:
and
and then registered them by adding these two lines to imgui_impl_win32.cpp in InitPlatformInterface
Before doing this, I had a situation where my window would still be drawn, but in the bottom left corner of the main window. In addition, I would get a solid black box draw wherever I dragged the window outside. After adding this code, I no longer get the additional drawing of the window inside the main window. I also obviously added members to the viewport data structure for Win32 to track the hDC and GL rendering context to be able to switch them later. I also added them to the destructor for the struct to be able to automatically delete or release them. I do not believe that this is a Win32 and OpenGL issue as the samples work for glfw. Under the hood, glfw is simply using Win32 and OpenGL. While I haven't yet found the issue, I do think that it is possible to find and fix. |
You were absolutely right that the main issue deals with Win32+GL implimentation issues. I finally figured it out after some digging. The thing people are missing is that ImGui uses a shared texture to render multiple viewports. As that is the way it should be. But in order to share the texture between two HGLRC (OpenGl context), you need to explicitedly tell them that they are allowed. When you do that via wglSharedList, everything should work as intended. If you'd like, I can see if I can make an example project with all the necessary changes to have it work. |
I would love to see your example solution as I have worked many hours on this. For one project, I ultimately just switch to using GLFW (helps with cross-platform anyway), but for my other, I don't want to do that. |
Okay, so following the advice posted by @danec020, I added wglSharedList to the code. Now, I can drag a window outside the main window and it doesn't turn pink/black! However, a copy of the window is still drawn (flashing) in the main window. When you drag a window back in, it just disappears. Here is a demonstration of the issue: imgui_impl_win32.cpp:
I made no changes to imgui_impl_opengl3.cpp. This is, I feel, much closer to getting this to work, but I am not sure why the windows are still drawn inside the main window (they aren't if you drag them out, close the program, and restart) or why they disappear when dragging them back in. They still exist because you can drag them back out again if you can find them, so it is a rendering issue. Additionally, after posting this, I also found that if you minimize after moving a window out of the main window and then restore the window, the main window will only be drawn as black. It does not matter if you put the window back in or not. This does not happen if a second window has never been created. |
Sorry @jdunlap about not posting the code earlier but I've been busy. I wanted to try and submit a pull request before posting but since you are back at it I will drop the files here. My solution works without issues. I am thinking your flickering window issue as well as the black rendering issue is coming from your implementation of your window. Specifically how your window is managed and when/what context is set during the rendering. I briefly checked over your code and it looks like you got the gist of what I was saying to do with the context sharing. Anyhow, here is the code for everything to get a working example and from here you should be able to find out what you are missing. :) Just in case I changed something in the opengl file (which I shouldn't have needed to.) I did a lot of poking around and there might be some unnecessary changes. That was the reason i didn't want to share code yet, just in case some changes that don't need to be there are still included. But I know there are others who might find this useful right now so use at your discretion! Also please note that in my implementation I am using multiple HGLRCs(contexts) for each window but you could in theory just use one. Hope this helps bud! Have fun with it! Edit: Formatting was a nightmare so I added a Zip instead. @ocornut You are correct, a zip is much easier. Thanks! |
@danec020 Perhaps you should attack a ZIP file instead of pasting five billion lines :) |
@ocornut I created a pull request for the changes needed for this to work with an example project. Let me know if I need to do anything else to make it easier for you to merge in. (If you wish to merge it in. :) ) |
@danec Thanks! It is working now. I don't think you could have found my problem as it seems to be that I was not saving the context and making sure it got switch back in my rendering code in main.cpp. Once I fixed that, it works like a charm! Thank you for the pushes in the right directions. Don't worry about not posting the code. It gave me time to work through it myself once you told me where to look. |
Will this patch be applied (some months past since...). I had the same problem with my win32/opengl implementation. I am using the base examples. After applying the changes with my diff tool from danec020 to the latest imgui_impl_win32(.h, .cpp) it finally works. Would help newcomers like me a lot. |
@larioteo What you actually do? Because i have the same problem :D |
@KennyProgrammer Another issue that occured on my pc was related to a known bug with sound driver service. If you have the same problem look here: #3321 |
@larioteo I find another bug, when you tried to resize imgui window (i. e when window already outside the win32 window) its glitching. I don't know, maybe i doing something wrong but i cant found the solution. |
@KennyProgrammer If you need my full implementation i can send you the link to my repo with the full code (its anyway public available). The code now works perfectly. |
@larioteo Yes, it really was the solution to this problem! Thank you. There are no flights, so everything works. If there are any more problems with OpenGL + Win32, I will let you know. |
Something interesting I've noticed is that when you move an ImGui panel into it's own window while using Win32 and OpenGL 3, it doesn't have a rendering context. |
Yea, and when you move ImGui outside the main Win32 window, it's a little laggy to move around. This is not particularly critical, just compared to GLFW + ImGui, it is noticeably felt. |
@danec020 if im using a multiple context , there is no low fps , do you know what is the problem? |
I had the same issue and after applying the changes from @larioteo 's patch file it still does not work. The viewport is not black anymore so this is working but the screen is still flickering. Does someone have still the same issue? Here is the code I used: (imgui_impl_win32.cpp, imgui_impl_opengl3.cpp) |
@Cankar001 ImGui with Patches: https://github.com/larioteo/omnia/tree/master/3rd-Party/.Library/imgui/backends GuiBuilder and GuiLayer: https://github.com/larioteo/omnia/tree/master/Source/Omnia/UI Please be aware that I didn't updated ImGui for a while. |
@larioteo Thank you very much, going to take a deeper look at it :D |
@larioteo Unfortunately I wasn't able to get it to work. My flickering still remains and our code is very similar now, the imgui_impl_win32.cpp is pretty much the same and the imgui_impl_opengl3.cpp just contains the stencil test flag and another blend function. Any ideas why this is happening? I ran out of ideas now.. :( |
The hardware, what graphics card and driver you have installed? |
@larioteo Geforce GTX 1060 with 6gb VRAM and I am on the latest driver version. |
ImGuiBug.mp4Here is the recording of the current behavior, as you can see the tabs are still flickering and I can't resize or move them at all, if I detach them from their layout. I am not quite sure if the holes in the sphere are related to ImGui or the Framebuffer, because I have the same scene seperately from the LevelEditor and in that scene there are no holes at all. |
I have no flickering with GLFW and I can move and resize all the tabs without problems, just the Win32 implementation keeps having problems |
This is just strange because under GLFW there is also raw Win32 and in theory there should be no problems. It's just that GLFW is, so to speak, at one level higher in abstraction. Here, rather, the problem is in the ImGui implementation for Win32, you need to look there. |
@KennyProgrammer You are right, I took a look into GLFW and it is indeed just a wrapper around Win32. I'm going to take a deeper look into ImGui in general then 👍 |
Does my implementation run on your PC? Cause also don't use glfw and there are also no issues. |
I would like to point out that glfw has a specific implementation in ImGUI, so it may have functionality with OpenGL that the Win32 implementation is missing. |
Each window created in imgui_impl_win32.cpp now creates an openGL context which shares its display list space with the primary window's. IMGUI_IMPL_WIN32_OPENGL3 must be defined to use this fix.
Hope no one minds if I revive this issue! Using @larioteo's insights, I developed a fix that works good for the latest commit of the docking branch (at the moment, 505f19e). My version of the fix is here: theOtherMichael@4955f4b However, it doesn't preserve the separation of the OpenGL and Win32 backends, and it requires defining I'm still brand new to Dear ImGui. Does anyone with more experience have ideas about making this fix less hack-ey? The main problems I have are:
If I can turn this into a more elegant fix going, I'd love to submit this as a pull request. |
ImGui_ImplWin32_Init() now optionally accepts a render context handle, and IMGUI_IMPL_WIN32_OPENGL3 is no longer a necessary define.
So, after studying the the GLFW implementation a bit more, I figured out a better way to do this. I now have a solution that adds support for OpenGL + Win32 which shouldn't break anything at all for anyone: theOtherMichael@31aedf7 I've submitted a pull request. |
I've been experimenting this issue recently (for the first time honestly, in the older versions I don't remember to see it happening before). I've tried both of the @theOtherMichael solutions and neither worked for me unfortunately, in fact, in the second version my application crashes when I drag the window outside. I'm gonna try an older solution to see if everything goes well. Until I have more time to dig into the implementation of GLFW to understand it better (I'm not even using glfw, I'm writing my own framework). |
Are you using the latest commit on the fix branch (#5170)? If you are, I'd be interested in seeing your crashing code. I've been working with this fix for a while now and haven't encountered issues yet. |
I've copied both the ".cpp" and ".h" from the ImGui repository and pasted into my project. Now I've no problems at all. But for some reason, I can't drag the (ImGui) windows outside the main window of my application, I'm not sure why but I think its because I got the files from the master branch and not the docking one. It's fine for me anyways, I adjusted the dock space so.. Since I can dock the (ImGui) windows I'm all good being this way. |
Closed/solved, see #3218 (comment) |
Version/Branch of Dear ImGui:
Version: 1.71 WIP
Branch: docking/596d81a9
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_opengl3.cpp + imgui_impl_win32.cpp
Compiler: MSVC 19.20.27508.1
Operating System: Windows 10
My Issue/Question:
When I move the window outside of the main window, it turns pink and only renders the content in the main window. This only happens when using the win32 api. With GLFW it is working as intended
Screenshots/Video
Standalone, minimal, complete and verifiable example:
The text was updated successfully, but these errors were encountered: