DX11 imgui slightly distorted and mouse position offset

This is 100% my fault, because the example works just fine, but ImGUI is so simple to set up that I’m not sure what I’ve missed. I’m hoping someone else will have seen it before…

ImGUI renders, but everything looks slightly mushed together, particularly noticeable in text. I’m also getting a slight offset to the mouse cursor which is visible when I force on ShowCursor(true) to get the Windows cursor along with ImGui’s cursor. Here’s a quick gif of the problems:

It almost looks like ImGui thinks the window size is different, but I checked and it seems to be accurate. Anyone have any ideas? Thanks!

Edit - it looks like ImGui is offset somehow. It’s clipping everything from the bottom of the window, though I’m still not sure why:

The io.DisplaySize value you are passing to imgui and using in your projection matrix probably doesn’t match the size of the actual Client Area of your window.

Thanks for the incredibly fast response! I just poked through more trying to find where that would’ve happened and noticed something that has to be related – the amount of pixels cut off from the bottom of the window is exactly identical to the window’s title bar size (39px). This is in agreement with my io.DisplaySize reporting a slightly smaller size (by 39px), so I’m guessing ImGui recognizes that a title bar exists and is compensating for the size, but not offsetting the actual draw, so it’s drawing everything 39px too far upward.

Does that sound like a possibility to you? Thanks again for your help.

ImGui doesn’t “recognize that a title bar exists”, it only read io.DisplaySize which you provided.
You provided the wrong size in io.DisplaySize. Look up the difference between “Window Size” (include decoration/title bar etc.) and “Client Size”.

I’m not setting that at all though. It’s being set inside of ImGui_ImplWin32_NewFrame()

I’m following the example DX11 code and it doesn’t touch io.DisplaySize, so I haven’t either.

Finally figured it out, thanks again for all your help! Much appreciated.

Are you able to share how you fixed this issue so others can do it too


I surely can, though it’s pretty uninteresting. I was creating a depth buffer elsewhere using window size instead of client size, which worked without me noticing anything amiss until I brought in imgui which sizes things properly. Ended up finding it via debug layer. Here’s the required change with my old code commented out:

// Create depth/stencil buffer and view
	D3D11_TEXTURE2D_DESC depthStencilDesc;
	//ah hell i should've been using client bounds here instead of window size
	RECT clientRect;
	GetClientRect(mHwnd, &clientRect);

	//depthStencilDesc.Width = ZSettings->windowWidth;
	depthStencilDesc.Width = clientRect.right;
	//depthStencilDesc.Height = ZSettings->windowHeight;
	depthStencilDesc.Height = clientRect.bottom;