mirror of
https://github.com/kevinporetti/UnrealImGui.git
synced 2025-01-18 08:20:32 +00:00
Added some useful info into the readme about render textures. Also updated it to reflect new change from OP
This commit is contained in:
parent
2b8f3e55c3
commit
48b1abd1e1
65
README.md
65
README.md
@ -21,6 +21,7 @@ Fork Additions/Fixes
|
||||
- Added ImPlot v0.13 WIP
|
||||
- `ImGui::IsKey*` now functional with all known ImGui keys.
|
||||
- Updated input handling flow to be [standard compliant](https://github.com/ocornut/imgui/issues/4921) with Dear ImGui 1.87 which makes ImGui react better at low FPS. Will add `IMGUI_DISABLE_OBSOLETE_KEYIO` preprocessor once I've ripped out old style input.
|
||||
- Allowed `UTexture` for Texture Manager so render targets can also be rendered to quads rather than just being limited to using `UTexture2D` instances.
|
||||
|
||||
Status
|
||||
------
|
||||
@ -43,12 +44,76 @@ On top of reading the base repository's [How to Set up](https://github.com/segro
|
||||
PrivateDefinitions.Add(string.Format("IMPLOT_API=DLLIMPORT"));
|
||||
```
|
||||
|
||||
# Additional Knowledge
|
||||
|
||||
Using ImPlot
|
||||
------------
|
||||
It's pretty easy to use ImPlot, it's pretty much the same drill as using Dear ImGui with the UnrealImGui plugin. You can see documentation on how to use ImPlot here: [ImPlot](https://github.com/epezent/implot).
|
||||
|
||||
The only thing you won't need to do is call the `ImPlot::CreateContext()` and `ImPlot::DestroyContext` routines as they're already called when ImGui's context is created within UnrealImGui's guts.
|
||||
|
||||
Drawing a UTextureRenderTarget2D
|
||||
----
|
||||
One might want to render viewports into the world in an ImGui window. You can do this pretty simply by generating a `UTextureRenderTarget2D` then assigning that to a `ASceneCapture2D` actor in your world. Here's some sample code for generating an correctly managing the `UTextureRenderTarget2D`:
|
||||
```cpp
|
||||
void Init()
|
||||
{
|
||||
TextureRenderTarget = NewObject<UTextureRenderTarget2D>();
|
||||
if(IsValid(TextureRenderTarget))
|
||||
{
|
||||
TextureRenderTarget->InitAutoFormat(512, 512);
|
||||
TextureRenderTarget->UpdateResourceImmediate(true);
|
||||
}
|
||||
|
||||
// ... Generate a unique TextureName here
|
||||
// Register this render target as an ImGui interop handled texture
|
||||
ImGuiTextureHandle = FImGuiModule::Get().FindTextureHandle(TextureName);
|
||||
if(!ImGuiTextureHandle.IsValid())
|
||||
{
|
||||
if(IsValid(TextureRenderTarget))
|
||||
{
|
||||
ImGuiTextureHandle = FImGuiModule::Get().RegisterTexture(TextureName, TextureRenderTarget, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~Class()
|
||||
{
|
||||
// Requires releasing to avoid memory leak
|
||||
FImGuiModule::Get().ReleaseTexture(ImGuiTextureHandle);
|
||||
}
|
||||
|
||||
void Render()
|
||||
{
|
||||
// Actually submit the draw command to ImGui to render the quad with the texture
|
||||
if(ImGuiTextureHandle.IsValid())
|
||||
{
|
||||
ImGui::Image(ImGuiTextureHandle.GetTextureId(), {512.f, 512.f});
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then generating the `ASceneCapture2D`:
|
||||
```cpp
|
||||
void Init()
|
||||
{
|
||||
FActorSpawnParameters SpawnInfo;
|
||||
SceneCapture2D = World->SpawnActor<ASceneCapture2D>(FVector::ZeroVector, FRotator::ZeroRotator, SpawnInfo);
|
||||
SceneCaptureComponent2D->TextureTarget = TextureRenderTarget;
|
||||
SceneCaptureComponent2D->UpdateContent();
|
||||
|
||||
// Need to use this in order to force capture to use tone curve and also set alpha to scene alpha (1)
|
||||
SceneCaptureComponent2D->CaptureSource = ESceneCaptureSource::SCS_FinalToneCurveHDR;
|
||||
}
|
||||
```
|
||||
|
||||
### Troubleshooting
|
||||
If you're using a scene capture and your quad is not drawing at all, make sure your scene capture "Capture Source" is set to "Final Color (with tone curve) in Linear sRGB gamut" to avoid alpha being set to 0 (since there's no way to instruct ImGui to ignore alpha without modding the core UnrealImGui plugin).
|
||||
|
||||
If you're getting crashes or seg faults during rendering, make sure you're using `UPROPERTY()` on your class variables!
|
||||
|
||||
# Misc
|
||||
|
||||
See also
|
||||
--------
|
||||
- [Original Project by segross](https://github.com/segross/UnrealImGui)
|
||||
|
Loading…
Reference in New Issue
Block a user