This is a MonoGame 3.8 sample that demonstrates how to use RenderTarget2D to render graphics to a texture and then manipulate that texture before drawing it to the screen. This sample showcases render-to-texture techniques that are commonly used for post-processing effects, screen capture, and dynamic texture generation.
The RenderTarget2D sample creates a scene with textures (checker pattern and logo), renders them to a render target, and then displays the result on the screen with various transformations and effects.
This project has been modernized to use .NET 8.0 and MonoGame 3.8.* with support for the following platforms:
- Windows (
net8.0-windows) - DirectX backend - DesktopGL (
net8.0) - OpenGL backend for cross-platform desktop - Android (
net8.0-android) - Mobile Android devices - iOS (
net8.0-ios) - Mobile iOS devices
- .NET 8.0 SDK or later
- For Android development: Android SDK with API Level 21+ (Android 5.0)
- For iOS development: Xcode and iOS 11.0+ support
- Visual Studio 2022 or Visual Studio Code with C# extension
- Open
RenderTarget2DSample.slnin Visual Studio 2022 - Select your target platform project as the startup project
- Build and run (F5)
- Open the project folder in VS Code
- Use the Command Palette (Ctrl+Shift+P) and run "Tasks: Run Task"
- Choose from available tasks:
build-windows- Build Windows versionbuild-desktopgl- Build DesktopGL versionbuild-android- Build Android versionrun-windows- Build and run Windows versionrun-desktopgl- Build and run DesktopGL version
dotnet build RenderTarget2D.Windows.csproj
dotnet run --project RenderTarget2D.Windows.csprojdotnet build RenderTarget2D.DesktopGL.csproj
dotnet run --project RenderTarget2D.DesktopGL.csprojdotnet build RenderTarget2D.Android.csproj
# Deploy to connected Android device/emulator
dotnet publish RenderTarget2D.Android.csproj -f net8.0-androiddotnet build RenderTarget2D.iOS.csproj
# Requires Xcode and Mac for deploymentGame1.cs- Main game class with render target logicProgram.cs- Entry points for different platformsMainActivity.cs- Android-specific activityContent/- Game assets (.xnb files)Properties/- Platform-specific manifests and settingsResources/- Android-specific resources
This project uses pre-compiled .xnb content files located in the ../CompiledContent/ directory. The content includes:
checker.xnb- Checker pattern texturelogo.xnb- Logo texture
The project does not include a Content.mgcb file and uses the existing compiled content directly.
- RenderTarget2D Creation - How to create and configure render targets
- Render-to-Texture - Drawing graphics to a texture instead of the screen
- Texture Manipulation - Using rendered textures as input for further rendering
- Cross-Platform Compatibility - Single codebase supporting multiple platforms
- Modern .NET 8.0 target frameworks
- NuGet package references for MonoGame framework
- Platform-specific optimizations
- Updated graphics pipeline
If you get content loading errors, ensure that the ../CompiledContent/ directory exists with the required .xnb files for your target platform.
- Ensure you have the correct .NET 8.0 SDK installed
- For Android: Verify Android SDK and build tools are properly configured
- For iOS: Ensure Xcode and iOS development tools are installed (Mac only)
- Try the DesktopGL version if Windows DirectX version has issues
- Ensure your graphics drivers are up to date
This sample is part of the MonoGame samples collection and follows the same licensing terms as MonoGame.