Closed PsychoCoffee closed 2 years ago
This typically indicates that the size of your swap chain does not match the size of the window.
If you compare the sizes used between the swap chain and Dear ImGui do they match? IE:
DXGI_SWAP_CHAIN_DESC description;
if (g_pSwapChain->GetDesc(&description) != S_OK) // Substitute g_pSwapChain for your swap chain
printf("GetDesc failed!\n");
ImVec2 dearImGuiSize = ImGui::GetIO().DisplaySize;
printf("DXGI: %ux%u Dear ImGui: %dx%d\n", description.BufferDesc.Width, description.BufferDesc.Height, (int)dearImGuiSize.x, (int)dearImGuiSize.y);
Most likely the swap chain is wrong and Dear ImGui is correct. Make sure you're handling WM_SIZE
correctly.
This typically indicates that the size of your swap chain does not match the size of the window.
If you compare the sizes used between the swap chain and Dear ImGui do they match? IE:
DXGI_SWAP_CHAIN_DESC description; if (g_pSwapChain->GetDesc(&description) != S_OK) // Substitute g_pSwapChain for your swap chain printf("GetDesc failed!\n"); ImVec2 dearImGuiSize = ImGui::GetIO().DisplaySize; printf("DXGI: %ux%u Dear ImGui: %dx%d\n", description.BufferDesc.Width, description.BufferDesc.Height, (int)dearImGuiSize.x, (int)dearImGuiSize.y);
Most likely the swap chain is wrong and Dear ImGui is correct. Make sure you're handling
WM_SIZE
correctly.
I don't know exactly where to look, but I put the code in the part where I initialize DirectX11. When I run the program now, it is instantly giving me CreateContext errors. "No current context, did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?"
When it comes to viewports and swapchains, I know nothing (hence why I am getting this error).
DXGI_SWAP_CHAIN_DESC scd = { 0 };
scd.BufferDesc.Width = this->windowWidth;
scd.BufferDesc.Height = this->windowHeight;
scd.BufferDesc.RefreshRate.Numerator = 60;
scd.BufferDesc.RefreshRate.Denominator = 1;
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
scd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
scd.SampleDesc.Count = 1;
scd.SampleDesc.Quality = 0;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.BufferCount = 1;
scd.OutputWindow = hwnd;
ImGuiContext* ctx1 = ImGui::GetCurrentContext();
ImGui::SetCurrentContext(ctx1);
ImVec2 dearImGuiSize = ImGui::GetIO().DisplaySize;
printf("DXGI: %ux%u Dear ImGui: %dx%d\n", scd.BufferDesc.Width, scd.BufferDesc.Height, (int)dearImGuiSize.x, (int)dearImGuiSize.y);
if(windowedMode)
scd.Windowed = TRUE;
else
scd.Windowed = FALSE;
scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
I don't know exactly where to look,
Add the print code in your main loop to display the value after resizing. The purpose of this code is to display and compare both values while running.
When it comes to viewports and swapchains, I know nothing (hence why I am getting this error).
Refer to examples/example_win32_directx11/
. You app needs to react to WM_SIZE event and resize its buffers.
Closing as answered. @PsychoCoffee let us know if that solved your issue.
Version/Branch of Dear ImGui:
Version: 1.89 WIP Branch: master
Back-end/Renderer/Compiler/OS
Back-ends: .cpp: imgui.cpp, imgui_draw.cpp, imgui_impl_dx11.cpp, imgui_impl_win32.cpp, imgui_tables.cpp, imgui_widgets.cpp, .h: imconfig.h, imgui.h, imgui_impl_dx11.h, imgui_impl_win32.h, imgui_internal.h, imstb_rectpack.h, imstb_textedit.h, imstb_truetype.h Compiler: (Don't know, must be on default for Visual Studio 2022) Operating System: Windows 10
My Issue/Question: Working with ImGui Buttons on bigger supported screen resolutions (1920x1080, or 2560x1440) messes up ImGui. What happens is that the buttons don't register when you click directly on them, but on a random part of the screen. Also, the ImGui Text also looks under scaled, and everything else. Is there an easy way to auto scale text / font with a provided resolution?
Screenshots/Video