ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
59.76k stars 10.17k forks source link

Blank screen when porting to DirectX 8 #6564

Open luxploit opened 1 year ago

luxploit commented 1 year ago

Version/Branch of Dear ImGui:

Version: 1.89.7 WIP (655aae5) Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_dx8.cpp + imgui_impl_win32.cpp Compiler: MSVC (Visual Studio 2015) Operating System: Windows 11 22H2

My Issue

I've been trying to port ImGui to DirectX 8.1b. So far I've managed to spawn the window and draw the background color, however none of the ImGui windows itself are displaying. They are however being created and are clickable, as I've set ImGuiDebugLogFlags_EventMask_ on DebugLogFlags to see if they were even being created.

I've attached the ported code aswell as the Installer for the DirectX 8.1b. To compile this however you will need to add an environment variable called DXSDK81 as the older DirectX SDK doesn't set one by itself. Additionally you may need to edit the line typedef void * POINTER_64 PVOID64; in winnt.h, as compiling with the DirectX 8.1 SDK causes an error on some machines, to typedef void * POINTER_64, * PVOID64;. This requires changing ownership of the file (Located at C:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h` from SYSTEM to your own user, and giving yourself the "Full Control" permission flag.

Attachments example_win32_directx8.zip

image image

ocornut commented 1 year ago

Hello,

Not much of this is a dear imgui question. You are essentially asking us to debug your DX8 code here.

I personnally don’t know DX8 but hope you get it working, I see no reason for it to not work.

GamingMinds-DanielC commented 1 year ago

It has been ages since I used DX8. At a quick glance I couldn't see any obvious mistakes in your backend. I don't know how good RenderDoc is with DX8, but you should give it a try. If it works with that version, it's a great tool to debug rendering of any kind.

luxploit commented 1 year ago

image I seem to have fixed the core rendering issue, I didn't set the stream source correctly. Now I have to find an alternative to SetScissorRect, to fix the clipping, as that API doesn't exist on DirectX 8

GamingMinds-DanielC commented 1 year ago

As an alternative, you can set the render viewport and a properly configured projection matrix.

ocornut commented 1 year ago

Using a vertex shader may be more natural.

luxploit commented 1 year ago

As an alternative, you can set the render viewport and a properly configured projection matrix.

image image

I've been trying with clip it using the viewport, didn't quite work out.

 // Clip overflow using viewport
const RECT r = { (LONG)clip_min.x, (LONG)clip_min.y, (LONG)clip_max.x, (LONG)clip_max.y };

D3DVIEWPORT8 clipped_viewport = {
    r.left, r.top,
    r.right - r.left,
    r.bottom - r.top,
    0.f, 1.f
};
bd->pd3dDevice->SetViewport(&clipped_viewport);
GamingMinds-DanielC commented 1 year ago

That looks strange. Did you adjust the projection as well? And did you reset the viewport to the old value at the end?

luxploit commented 1 year ago

I reset the viewport after calling DrawIndexedPrimitive, but I didn't adjust the matrix as I don't know how to.

ocornut commented 1 year ago

Even if you can get it to work this way (and I think you can) I suspect altering viewport may be flushing too many things in the pipeline, I would recommend using a vertex shader.

GamingMinds-DanielC commented 1 year ago

I don't think a vertex shader would help much since it doesn't know about the triangles that the vertex is part of.

As for the adjustment of the projection matrix:: just as it is set up at the end of your ImGui_ImplDX8_SetupRenderState() function, but with the clip rect taken into account.

Another alternative would be to set up four clip planes using IDirect3DDevice8::SetClipPlane(). The documentation states how to set up the clip planes. Don't forget to enable them in the render states.

luxploit commented 1 year ago

I'll try out using clip planes later today.

leeqiufeng commented 1 year ago

I'll try out using clip planes later today.

hello , have you fixed imgui with dx8 ?

luxploit commented 1 year ago

I have not worked on this for a while no. But you're welcome to try it out, I'll upload the latest zip of my dx8 port later this week when I return home.

leeqiufeng commented 1 year ago

Looking forward to your new version