I am working on a game that has a Core project and multiple implementation projects that target different platforms. I have created a new target project that uses a DrawableGameComponent to add development tools to the game. This is the Program.cs that I use to launch the game with this component.
private static void Main(string[] args)
{
using var game = new CartridgePlatformerGame();
game.IsMouseVisible = true;
game.Components.Add(new DebuggerComponent(game));
game.Run();
}
I have given the DebuggerComponent its own RenderTarget2D to draw all of the tool elements before drawing it to the game buffer. However, when I call SetRenderTarget to the DebuggerComponent’s target, it clears out all of the visuals of the game.
Here is my Draw(GameTime gt) in my component:
public override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
Game.GraphicsDevice.SetRenderTarget(ImGuiRenderTarget);
Game.GraphicsDevice.Clear(Color.Transparent);
ImGuiRenderer.BeginLayout(gameTime);
foreach (ToolBase tool in Tools)
{
tool.ToolRoutine();
}
ImGuiRenderer.EndLayout();
Game.GraphicsDevice.SetRenderTarget(null);
Artist.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);
Artist.SpriteBatch.Draw(ImGuiRenderTarget, GraphicsDevice.Viewport.Bounds, Color.White);
Artist.SpriteBatch.End();
}
Is there any way to draw to a render target in a DrawableGameComponent without affecting the base game or other DrawableGameComponents?