arnaud-jamin / Cog

Cog is a set of debug tools for Unreal Engine built on top of Dear ImGui
MIT License
357 stars 44 forks source link

Font Displays Corrupted on XSX/PS5 #28

Open JOSKevinW opened 10 months ago

JOSKevinW commented 10 months ago

We've recently integrated Cog into our Unreal Engine using 5.2.1. We've encountered the font looks corrupted when on the XSX and PS5 platforms; they look correct on Windows. When we increase the DpiScale, it still looks incorrect. Do you expect that this would work on these other platforms too?

arnaud-jamin commented 10 months ago

Hello,

I was not able to test on other platforms than PC. I do not have any devkit.

Sorry.

arnaud-jamin commented 10 months ago

Btw, the code handling the font in Cog is very small. Imgui is handling 99% of it.

JOSKevinW commented 9 months ago

This appears to be addressed by replacing the texture loading code in FCogImguiContext::BuildFont.

It's also notable that the texture format is not PF_R8G8B8A8, it is 4 bytes per pixel, not 8.

`FontAtlasTexture = UTexture2D::CreateTransient(TextureWidth, TextureHeight); FontAtlasTexture->UpdateResource();

auto SrcDataCleanup = [](uint8* Data) { delete[] Data; };

FUpdateTextureRegion2D* TextureRegion = new FUpdateTextureRegion2D(0, 0, 0, 0, TextureWidth, TextureHeight);
auto DataCleanup = [SrcDataCleanup](uint8* Data, const FUpdateTextureRegion2D* UpdateRegion)
{
    delete UpdateRegion;
};
FontAtlasTexture->UpdateTextureRegions(0, 1u, TextureRegion, BytesPerPixel * TextureWidth, BytesPerPixel, TextureDataRaw, DataCleanup);`

As a separate issue, Cog rendered on console is very small as opposed to PC. I adapted SCogImguiWidget::OnPaint's calculation of Transform to match what imGui's Unreal integration does. The original code only accounts for transform and not scale.

FSlateRenderTransform displayPosition(DrawData.DisplayPos); const FSlateRenderTransform& WidgetToScreen = AllottedGeometry.GetAccumulatedRenderTransform(); const FSlateRenderTransform Transform = FCogImguiHelper::RoundTranslation(displayPosition.Concatenate(WidgetToScreen));

arnaud-jamin commented 9 months ago

Thanks a lot for the research! Don't hesitate to make a pull request!

Sorry I didn't reply sooner, was too busy.

JailbreakPapa commented 1 month ago

This appears to be addressed by replacing the texture loading code in FCogImguiContext::BuildFont.

It's also notable that the texture format is not PF_R8G8B8A8, it is 4 bytes per pixel, not 8.

`FontAtlasTexture = UTexture2D::CreateTransient(TextureWidth, TextureHeight); FontAtlasTexture->UpdateResource();

auto SrcDataCleanup = [](uint8* Data) { delete[] Data; };

FUpdateTextureRegion2D* TextureRegion = new FUpdateTextureRegion2D(0, 0, 0, 0, TextureWidth, TextureHeight);
auto DataCleanup = [SrcDataCleanup](uint8* Data, const FUpdateTextureRegion2D* UpdateRegion)
{
  delete UpdateRegion;
};
FontAtlasTexture->UpdateTextureRegions(0, 1u, TextureRegion, BytesPerPixel * TextureWidth, BytesPerPixel, TextureDataRaw, DataCleanup);`

As a separate issue, Cog rendered on console is very small as opposed to PC. I adapted SCogImguiWidget::OnPaint's calculation of Transform to match what imGui's Unreal integration does. The original code only accounts for transform and not scale.

FSlateRenderTransform displayPosition(DrawData.DisplayPos); const FSlateRenderTransform& WidgetToScreen = AllottedGeometry.GetAccumulatedRenderTransform(); const FSlateRenderTransform Transform = FCogImguiHelper::RoundTranslation(displayPosition.Concatenate(WidgetToScreen));

Thanks for these fixes! we just started using cog and were wondering why fonts were messing up.