1

Why can't the ImGui::Image() function fill the entire screen when it displays an image in the viewport, can the ImGui::GetWindowDrawList()->AddImage() function fill the entire screen??

Pic 1

using ImGui::GetWindowDrawList()->AddImage()

Pic 2

using ImGui::Image()

void CImGuiMgr::render_copyRTTex()
{
    Vec2 RenderResolution = CDevice::GetInst()->GetRenderResolution();
    Ptr<CTexture> pCopyTex = CRenderMgr::GetInst()->GetRTCopyTex();

    // current size
    ImVec2 vViewportSize = ImGui::GetContentRegionAvail();
    Vec2 vResolution = CDevice::GetInst()->GetRenderResolution();
    ImVec2 Resolution = { vResolution.x,vResolution.y };
    ImVec2 LeftTopUv;
    ImVec2 RightBottom;

    LeftTopUv.x = 0.0f;
    LeftTopUv.y = 0.0f;
    RightBottom.x = 1.0f;
    RightBottom.y = 1.0f;

    if (ImGui::Begin("Custom Image Viewer"))
    {
        float fContentAspectRatio = vViewportSize.x / vViewportSize.y;
        float fImageAspectRatio = RenderResolution.x / RenderResolution.y;

        if (fContentAspectRatio > fImageAspectRatio)
        {
            float imageWidth = vViewportSize.y * fImageAspectRatio;
            float xPadding = (vViewportSize.x - imageWidth) / 2;
            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + xPadding);
            ImGui::Image(pCopyTex->GetSRV().Get(), ImVec2(imageWidth, vViewportSize.y), ImVec2(0, 0), ImVec2(1, 1));
        }
        // Scale the image vertically if the content region is taller than the image
        else
        {
            float imageHeight = vViewportSize.x / fImageAspectRatio;
            float yPadding = (vViewportSize.y - imageHeight) / 2;
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + yPadding);
            ImGui::Image(pCopyTex->GetSRV().Get(), ImVec2(vViewportSize.x, imageHeight), ImVec2(0, 0), ImVec2(1, 1));
        }



        // use image
        ImGui::SetNextWindowSize(vViewportSize);
        
        {
        // draw image
        ImGui::Image(pCopyTex->GetSRV().Get(), vViewportSize, LeftTopUv, RightBottom);
        }
    }
}
void CImGuiMgr::render_copyRTTex()
{
    Vec2 RenderResolution = CDevice::GetInst()->GetRenderResolution();
    Ptr<CTexture> pCopyTex = CRenderMgr::GetInst()->GetRTCopyTex();

    // current size
    ImVec2 vViewportSize = ImGui::GetContentRegionAvail();
    Vec2 vResolution = CDevice::GetInst()->GetRenderResolution();
    ImVec2 Resolution = { vResolution.x,vResolution.y };
    ImVec2 LeftTopUv;
    ImVec2 RightBottom;

    LeftTopUv.x = 0.0f;
    LeftTopUv.y = 0.0f;
    RightBottom.x = 1.0f;
    RightBottom.y = 1.0f;


    if (ImGui::Begin("Custom Image Viewer"))
    {
        ImGui::GetWindowDrawList()->AddImage(
            pCopyTex->GetSRV().Get(),
            ImGui::GetCursorScreenPos(),
            ImGui::GetWindowPos() + ImGui::GetWindowSize(),
            ImVec2(0, 0), ImVec2(1, 1));

        ImGui::End();

    }
}

2 case in here. '// use addimage' and '// use image'

When using the image() function, the above aspect ratio acquisition code was used.

I don't know why the motion is different.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.