From 509ac33abe2f0e6a53a9ca7ec864b9bd7e5b36a4 Mon Sep 17 00:00:00 2001 From: Nicolas Guillemot Date: Sun, 11 Oct 2015 16:42:22 -0700 Subject: [PATCH] fix POSITION format (ImDrawVert::pos is 2D, not 4D) the inputlayout incorrectly described the POSITION attribute as being 4D, while ImDrawVert::pos is 2D. This went unnoticed because the buffer binding has a stride of sizeof(ImDrawVert) and the POSITION is treated as a float2 in the vertex shader. If you switch POSITION to float4 in the vertex shader (and actually use the z/w in the matrix multiplication) then everything become wacky-looking since it's interpreting the texture coordinates as z/w. On a similar note: It's weird that the projection matrix takes z and w into consideration when those don't exist in the shader due to positions being float2s. --- examples/directx11_example/imgui_impl_dx11.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/directx11_example/imgui_impl_dx11.cpp b/examples/directx11_example/imgui_impl_dx11.cpp index 41684b33..cf862995 100644 --- a/examples/directx11_example/imgui_impl_dx11.cpp +++ b/examples/directx11_example/imgui_impl_dx11.cpp @@ -328,9 +328,9 @@ bool ImGui_ImplDX11_CreateDeviceObjects() // Create the input layout D3D11_INPUT_ELEMENT_DESC localLayout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; if (g_pd3dDevice->CreateInputLayout(localLayout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK)