66using EmptyKeys . UserInterface . Generated ;
77using EmptyKeys . UserInterface . Input ;
88using EmptyKeys . UserInterface . Media ;
9+ using EmptyKeys . UserInterface . Media . Imaging ;
910using GameUILibrary ;
1011using Microsoft . Xna . Framework ;
1112using Microsoft . Xna . Framework . Content ;
@@ -20,10 +21,13 @@ namespace BasicUI_MonoGame_Win_Desktop
2021 /// </summary>
2122 public class Game1 : Game
2223 {
24+ private readonly Random random = new Random ( ) ;
25+
2326 GraphicsDeviceManager graphics ;
2427
2528 private int nativeScreenWidth ;
2629 private int nativeScreenHeight ;
30+ private RenderTarget2D renderTarget ;
2731
2832 private BasicUI basicUI ;
2933 private DebugViewModel debug ;
@@ -125,6 +129,17 @@ protected override void LoadContent()
125129 RelayCommand resizeCommand = new RelayCommand ( new Action < object > ( OnResize ) ) ;
126130 KeyBinding resizeBinding = new KeyBinding ( resizeCommand , KeyCode . R , ModifierKeys . Control ) ;
127131 basicUI . InputBindings . Add ( resizeBinding ) ;
132+
133+ renderTarget = new RenderTarget2D ( GraphicsDevice ,
134+ 100 ,
135+ 100 ,
136+ false ,
137+ GraphicsDevice . PresentationParameters . BackBufferFormat ,
138+ DepthFormat . Depth24Stencil8 ) ;
139+
140+ viewModel . RenderTargetSource = new BitmapImage ( ) ;
141+ var texture = Engine . Instance . Renderer . CreateTexture ( renderTarget ) ;
142+ viewModel . RenderTargetSource . Texture = texture ;
128143 }
129144
130145 private void OnResize ( object obj )
@@ -192,6 +207,15 @@ protected override void Update(GameTime gameTime)
192207 /// <param name="gameTime">Provides a snapshot of timing values.</param>
193208 protected override void Draw ( GameTime gameTime )
194209 {
210+ GraphicsDevice . SetRenderTarget ( renderTarget ) ;
211+ Color color = new Color ( ) ;
212+ color . A = 255 ;
213+ color . R = ( byte ) random . Next ( 0 , 255 ) ;
214+ color . G = ( byte ) random . Next ( 0 , 255 ) ;
215+ color . B = ( byte ) random . Next ( 0 , 255 ) ;
216+ GraphicsDevice . Clear ( color ) ;
217+ GraphicsDevice . SetRenderTarget ( null ) ;
218+
195219 GraphicsDevice . Clear ( Color . CornflowerBlue ) ;
196220
197221 basicUI . Draw ( gameTime . ElapsedGameTime . TotalMilliseconds ) ;
0 commit comments