Skip to content
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

Custom DX9: backend: certain Widgets do not get clipped inside the Window properly #6980

Closed
ClonkAndre opened this issue Nov 3, 2023 · 1 comment
Labels

Comments

@ClonkAndre
Copy link

ClonkAndre commented Nov 3, 2023

Version/Branch of Dear ImGui:

Version: 1.89.8 (18980)
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_win32 + custom imgui_impl_dx9 (Was modified to use shaders instead of fixed function DX9)
Compiler: VS2022 MSVC
Operating System: Windows 11

My Issue/Question:

I'm using a dx9 device end scene hook with a custom imgui_impl_dx9 backend to get Dear ImGui to work with GTA IV.
It all works fine, except that some Widgets (Like the Listbox and the items inside the Listbox) will not stay inside the Window when you scroll. Basically the whole clipping behaviour is acting weird.

A video of that behaviour can be seen below where i'm testing this with the demo window.

Any help would be appreciated! Thanks!

Screenshots/Video

imgui.mp4

Code

My OnBeforeD3D9DeviceEndScene Method

	static void OnBeforeD3D9DeviceEndScene(IDirect3DDevice9* d3d9Device)
	{
		// Initialize ImGui if not initialized yet
		InitializeImGui(d3d9Device);

		// ImGui is not initialized, return.
		//if (!ImGuiStates::s_bIsImGuiInitialized)
		//	return;

		// Get ImGuiIO
		ImGuiIO& io = ImGui::GetIO(); (void)io;

		// Get the main viewport of ImGui
		/*ImGuiViewport* vp = ImGui::GetMainViewport();*/

		// Show cursor and disable mouse forever for testing
		io.MouseDrawCursor = true;
		ImGuiStates::s_bImGuiWantsMouseDisabled = true;

		// Create new ImGui Frame
		ImGui_ImplDX9_NewFrame();
		ImGui_ImplWin32_NewFrame();
		ImGui::NewFrame();

		ImGui::ShowDemoWindow();

		// End ImGui Frame and draw
		ImGui::EndFrame();
		ImGui::Render();
		ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
	}

The InitializeImGui Method

	static void InitializeImGui(IDirect3DDevice9* d3d9Device)
	{
		if (ImGuiStates::s_bIsImGuiInitialized)
			return;
		if (ImGuiStates::s_bStopTryingToInitializeImGui)
			return;

		D3DDEVICE_CREATION_PARAMETERS creationParams;
		d3d9Device->GetCreationParameters(&creationParams);

		// Setup ImGui stuff
		IMGUI_CHECKVERSION();
		ImGui::CreateContext();
		ImGuiIO& io = ImGui::GetIO(); (void)io;
		io.IniFilename = NULL;

		// Initialize the win32 backend
		ImGui_ImplWin32_Init(creationParams.hFocusWindow);

		// Initialize the dx9 backend
		ImGui_ImplDX9_Init(d3d9Device);

		ImGuiStates::s_bIsImGuiInitialized = true;
	}
@ocornut
Copy link
Owner

ocornut commented Nov 3, 2023

Your rendering backend is not honoring the ImDrawCmd::ClipRect field correctly.
Perhaps the SetScissorRect() call has no effect in your situation for some reason, in spite of bd->pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE); being called. I don't know the reason. Perhaps you can replicate scissoring in the vertex shader.

There's a DX9+Shader backend at #3874 which didn't seem to mention this issue.

This is not our backend nor our code so we can't really provide support for it.

@ocornut ocornut closed this as completed Nov 3, 2023
@ocornut ocornut changed the title Certain Widgets do not get clipped inside the Window properly Custom DX9: backend: certain Widgets do not get clipped inside the Window properly Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants