Jelajahi Sumber

Ported RenderTarget2D Sample to Android.

CartBlanche 14 tahun lalu
induk
melakukan
a4980a9450

+ 26 - 0
Samples/Android/RenderTarget2D/Activity1.cs

@@ -0,0 +1,26 @@
+using System;
+
+using Android.App;
+using Android.Content;
+using Android.Runtime;
+using Android.Views;
+using Android.Widget;
+using Android.OS;
+
+namespace MonoGame.Samples.RenderTarget2D.Android
+{
+	[Activity (Label = "MonoGame.Samples.RenderTarget2D.Android", MainLauncher = true)]
+	public class Activity1 : Activity
+	{
+		protected override void OnCreate (Bundle bundle)
+		{
+			base.OnCreate (bundle);
+
+			// Create our OpenGL view, and display it
+			GLView1 view = new GLView1 (this);
+			SetContentView (view);
+		}
+	}
+}
+
+

+ 19 - 0
Samples/Android/RenderTarget2D/Assets/AboutAssets.txt

@@ -0,0 +1,19 @@
+Any raw assets you want to be deployed with your application can be placed in
+this directory (and child directories) and given a Build Action of "AndroidAsset".
+
+These files will be deployed with you package and will be accessible using Android's
+AssetManager, like this:
+
+public class ReadAsset : Activity
+{
+	protected override void OnCreate (Bundle bundle)
+	{
+		base.OnCreate (bundle);
+
+		InputStream input = Assets.Open ("my_asset.txt");
+	}
+}
+
+Additionally, some Android functions will automatically load asset files:
+
+Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");

+ 63 - 0
Samples/Android/RenderTarget2D/MonoGame.Samples.RenderTarget2D.Android.csproj

@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>10.0.0</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{DEDD20B5-8F83-46FD-AD05-8F8FCC49FCD6}</ProjectGuid>
+    <ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <OutputType>Library</OutputType>
+    <RootNamespace>MonoGame.Samples.RenderTarget2D.Android</RootNamespace>
+    <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
+    <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
+    <AndroidResgenClass>Resource</AndroidResgenClass>
+    <AndroidApplication>True</AndroidApplication>
+    <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
+    <AssemblyName>MonoGame.Samples.RenderTarget2D.Android</AssemblyName>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ConsolePause>false</ConsolePause>
+    <AndroidLinkMode>None</AndroidLinkMode>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>none</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ConsolePause>false</ConsolePause>
+    <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
+    <AndroidLinkMode>SdkOnly</AndroidLinkMode>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Xml" />
+    <Reference Include="System.Core" />
+    <Reference Include="Mono.Android" />
+    <Reference Include="OpenTK" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Activity1.cs" />
+    <Compile Include="GLView1.cs" />
+    <Compile Include="Resources\Resource.designer.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Resources\AboutResources.txt" />
+    <None Include="Assets\AboutAssets.txt" />
+  </ItemGroup>
+  <ItemGroup>
+    <AndroidResource Include="Resources\layout\Main.axml" />
+    <AndroidResource Include="Resources\values\Strings.xml" />
+    <AndroidResource Include="Resources\drawable\Icon.png" />
+  </ItemGroup>
+  <Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
+</Project>

+ 27 - 0
Samples/Android/RenderTarget2D/Properties/AssemblyInfo.cs

@@ -0,0 +1,27 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes. 
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("MonoGame.Samples.RenderTarget2D.Android")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("savagesoftware")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly, 
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+

+ 44 - 0
Samples/Android/RenderTarget2D/Resources/AboutResources.txt

@@ -0,0 +1,44 @@
+Images, layout descriptions, binary blobs and string dictionaries can be included 
+in your application as resource files.  Various Android APIs are designed to 
+operate on the resource IDs instead of dealing with images, strings or binary blobs 
+directly.
+
+For example, a sample Android app that contains a user interface layout (main.axml),
+an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 
+would keep its resources in the "Resources" directory of the application:
+
+Resources/
+    drawable/
+        icon.png
+
+    layout/
+        main.axml
+
+    values/
+        strings.xml
+
+In order to get the build system to recognize Android resources, set the build action to
+"AndroidResource".  The native Android APIs do not operate directly with filenames, but 
+instead operate on resource IDs.  When you compile an Android application that uses resources, 
+the build system will package the resources for distribution and generate a class called "R" 
+(this is an Android convention) that contains the tokens for each one of the resources 
+included. For example, for the above Resources layout, this is what the R class would expose:
+
+public class R {
+    public class drawable {
+        public const int icon = 0x123;
+    }
+
+    public class layout {
+        public const int main = 0x456;
+    }
+
+    public class strings {
+        public const int first_string = 0xabc;
+        public const int second_string = 0xbcd;
+    }
+}
+
+You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main 
+to reference the layout/main.axml file, or R.strings.first_string to reference the first 
+string in the dictionary file values/strings.xml.

+ 59 - 0
Samples/Android/RenderTarget2D/Resources/Resource.designer.cs

@@ -0,0 +1,59 @@
+// ------------------------------------------------------------------------------
+//  <autogenerated>
+//      This code was generated by a tool.
+//      Mono Runtime Version: 4.0.30319.1
+// 
+//      Changes to this file may cause incorrect behavior and will be lost if 
+//      the code is regenerated.
+//  </autogenerated>
+// ------------------------------------------------------------------------------
+
+namespace MonoGame.Samples.RenderTarget2D.Android
+{
+	
+	
+	public partial class Resource
+	{
+		
+		public partial class Attribute
+		{
+			
+			private Attribute()
+			{
+			}
+		}
+		
+		public partial class Drawable
+		{
+			
+			// aapt resource value: 0x7f020000
+			public const int Icon = 2130837504;
+			
+			private Drawable()
+			{
+			}
+		}
+		
+		public partial class Layout
+		{
+			
+			// aapt resource value: 0x7f030000
+			public const int Main = 2130903040;
+			
+			private Layout()
+			{
+			}
+		}
+		
+		public partial class String
+		{
+			
+			// aapt resource value: 0x7f040000
+			public const int app_name = 2130968576;
+			
+			private String()
+			{
+			}
+		}
+	}
+}

TEMPAT SAMPAH
Samples/Android/RenderTarget2D/Resources/drawable/Icon.png


+ 8 - 0
Samples/Android/RenderTarget2D/Resources/layout/Main.axml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+</LinearLayout>
+

+ 4 - 0
Samples/Android/RenderTarget2D/Resources/values/Strings.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+	<string name="app_name">MonoGame.Samples.RenderTarget2D.Android</string>
+</resources>

+ 260 - 251
Samples/MacOS/RenderTarget2DSample/Game1.cs

@@ -1,251 +1,260 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Audio;
-using Microsoft.Xna.Framework.Content;
-using Microsoft.Xna.Framework.GamerServices;
-using Microsoft.Xna.Framework.Graphics;
-using Microsoft.Xna.Framework.Input;
-using Microsoft.Xna.Framework.Media;
-
-namespace RenderTarget2DSample
-{
-	/// <summary>
-	/// This is the main type for your game
-	/// </summary>
-	public class Game1 : Microsoft.Xna.Framework.Game
-	{
-		/// <summary>
-		/// The GraphicsDeviceManager is what creates and automagically manages the game's GraphicsDevice.
-		/// </summary>
-		GraphicsDeviceManager graphics;
-
-		/// <summary>
-		/// We use SpriteBatch to draw all of our 2D graphics.
-		/// </summary>
-		SpriteBatch spriteBatch;
-
-		/// <summary>
-		/// This is the rendertarget we'll be drawing to.
-		/// </summary>
-		RenderTarget2D renderTarget;
-
-		/// <summary>
-		/// This is a texture we'll be using to load a picture of Seamus the dog.
-		/// </summary>
-		Texture2D mooTheMerciless;
-
-		/// <summary>
-		/// This is a texture we'll be using to load a picture of a tileable wood surface.
-		/// </summary>
-		Texture2D wood;
-		bool oneTimeOnly = true;
-
-		/// <summary>
-		/// The constructor for our Game1 class.
-		/// </summary>
-		public Game1 ()
-		{
-			// Create the GraphicsDeviceManager for our game.
-			graphics = new GraphicsDeviceManager (this);
-
-			// Set the root directory of the game's ContentManager to the "Content" folder.
-			Content.RootDirectory = "Content";
-		}
-
-		/// <summary>
-		/// Allows the game to perform any initialization it needs to before starting to run.
-		/// This is where it can query for any required services and load any non-graphic
-		/// related content.  Calling base.Initialize will enumerate through any components
-		/// and initialize them as well.
-		/// </summary>
-		protected override void Initialize ()
-		{
-			// We don't have anything to initialize.
-
-			base.Initialize ();
-		}
-
-		/// <summary>
-		/// LoadContent will be called once per game and is the place to load
-		/// all of your content.
-		/// </summary>
-		protected override void LoadContent ()
-		{
-
-			// Create a new SpriteBatch, which can be used to draw textures.
-			spriteBatch = new SpriteBatch (GraphicsDevice);
-
-			// Create a rendertarget that matches the back buffer's dimensions, does not generate mipmaps automatically
-			// (the Reach profile requires power of 2 sizing in order to do that), uses an RGBA color format, and
-			// has no depth buffer or stencil buffer.
-			renderTarget = new RenderTarget2D (GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth,
-				GraphicsDevice.PresentationParameters.BackBufferHeight, false, SurfaceFormat.Color, DepthFormat.None);
-
-			// Load in the picture of Seamus.
-			mooTheMerciless = Content.Load<Texture2D> ("MooTheMerciless");
-
-			// Load in our wood tile.
-			wood = Content.Load<Texture2D> ("wood");
-		}
-
-		/// <summary>
-		/// UnloadContent will be called once per game and is the place to unload
-		/// all content.
-		/// </summary>
-		protected override void UnloadContent ()
-		{
-			// While not strictly necessary, you should always dispose of assets you create
-			// (excluding those you load the the ContentManager) when those assets implement
-			// IDisposable. RenderTarget2D is one such asset type, so we dispose of it properly.
-			if (renderTarget != null) {
-				// We put this in a try-catch block. The reason is that if for some odd reason this failed
-				// (e.g. we were using threading and nulled out renderTarget on some other thread),
-				// then none of the rest of the UnloadContent method would run. Here it doesn't make a
-				// difference, but it's good practice nonethless.
-				try {
-					renderTarget.Dispose ();
-					renderTarget = null;
-				} catch {
-				}
-			}
-		}
-
-		/// <summary>
-		/// Allows the game to run logic such as updating the world,
-		/// checking for collisions, gathering input, and playing audio.
-		/// </summary>
-		/// <param name="gameTime">Provides a snapshot of timing values.</param>
-		protected override void Update (GameTime gameTime)
-		{
-			// Allows the game to exit. If this is a Windows version, I also like to check for an Esc key press. I put
-			// it within an #if WINDOWS .. #endif block since that way it won't run on other platforms.
-			if (GamePad.GetState (PlayerIndex.One).Buttons.Back == ButtonState.Pressed
-			//#if WINDOWS
- || Keyboard.GetState ().IsKeyDown (Keys.Escape)
-//#endif
-) {
-				this.Exit ();
-			}
-
-			// We don't have any update logic since this is just an example usage of RenderTarget2D
-
-			base.Update (gameTime);
-		}
-
-		/// <summary>
-		/// This is called when the game should draw itself.
-		/// </summary>
-		/// <param name="gameTime">Provides a snapshot of timing values.</param>
-		protected override void Draw (GameTime gameTime)
-		{
-			
-			// A one time only flag to help test for memory leaks
-			if (oneTimeOnly) {
-				
-				oneTimeOnly = false;
-
-				// Set renderTarget as the surface to draw to instead of the back buffer
-				GraphicsDevice.SetRenderTarget (renderTarget);
-
-				// Clear the renderTarget. By default it's all a bright purple color. I like to use Color.Transparent to
-				// enable easy alpha blending.
-				GraphicsDevice.Clear (Color.Transparent);
-				Vector2 woodPosition = Vector2.Zero;
-
-				// Begin drawing
-				spriteBatch.Begin ();
-
-				int xBlank = 0;
-				int yBlank = 0;
-
-				// Use nested do-whiles to fill the rendertarget with tiles. We use some trickery to draw every other tile
-				do {
-					do {
-						// We use the modulus operator to get the remainder of dividing xBlank by 2. If xBlank is odd, it'll
-						// return 1 and the spriteBatch.Draw call gets skipped. If it's even, it'll return 0 so
-						// spriteBatch.Draw will get called and it'll draw a tile there.
-						if (xBlank % 2 == 0) {
-							spriteBatch.Draw (wood, woodPosition, Color.White);
-						}
-						// Increment xBlank by one so that every other tile will get drawn.
-						xBlank++;
-						// Increase the X coordinate of where we'll draw the wood tile in order to progressively draw
-						// each column of tiles.
-						woodPosition.X += wood.Width;
-
-						// We draw so long as woodPosition.X is less than our renderTarget's width
-					} while (woodPosition.X < renderTarget.Width);
-
-					// We increment yBlank by one. Why is explained below.
-					yBlank++;
-
-					// We use the modulus operater to get the remainder of dividing yBlank by 2. If yBlank is odd, we reset
-					// xBlank to 1. If it's even, we reset xBlank to 0. This way each row shifts by one so that the tiles
-					// are drawn in a checkered pattern rather than in columns.
-					if (yBlank % 2 == 0) {
-						xBlank = 0;
-					} else {
-						xBlank = 1;
-					}
-
-					// Reset woodPosition.X to zero so that we start drawing from the beginning of the next row.
-					woodPosition.X = 0;
-
-					// Increase the Y coord of where we'll draw the wood tile in order to progressively draw each
-					// row of tiles.
-					woodPosition.Y += wood.Height;
-
-					// We draw so long as woodPosition.Y is less than our renderTarget's width
-				} while (woodPosition.Y < renderTarget.Height);
-
-				// Now that we've drawn the wood tiles, we draw Moo the Merciless. We draw him centered in the rendertarget.
-				spriteBatch.Draw (mooTheMerciless, 
-				new Vector2 ((renderTarget.Width / 2f) - (mooTheMerciless.Width / 2f), (renderTarget.Height / 2f) - (mooTheMerciless.Height / 2f)), 
-				Color.White);
-
-				// End the spriteBatch draw.
-				spriteBatch.End ();
-
-				// Switch back to drawing onto the back buffer
-				GraphicsDevice.SetRenderTarget (null);
-			}
-			// Now that we're back to drawing onto the back buffer, we want to clear it. If we had done so earlier
-			// then when we switched to drawing to the render target, the old back buffer would've just be filled with
-			// that bright purple color when we came back to it.
-			GraphicsDevice.Clear (Color.CornflowerBlue);
-
-			// Ok. At this point we have everything we drew in renderTarget, which we can use just like a regular Texture2D.
-			// To make it look more interesting, we're going to scale up and down based on total elapsed time.
-			float scale = 1.0f;
-
-			if (gameTime.TotalGameTime.TotalSeconds % 10 < 5.0) {
-				// We're running on a ten second scale timer. For the first five second we scale down from 1f to
-				// no less than 0.01f.
-				scale = MathHelper.Clamp (1f - (((float)gameTime.TotalGameTime.TotalSeconds % 5) / 5f), 0.01f, 1f);
-			} else {
-				// For the second five seconds, we scale up from no less than 0.01f up to 1f.
-				scale = MathHelper.Clamp (((float)gameTime.TotalGameTime.TotalSeconds % 5) / 5f, 0.01f, 1f);
-			}
-
-			// Start spriteBatch again (this time drawing to the back buffer)
-			spriteBatch.Begin ();
-
-			// Now we draw our render target to the back buffer so that it will get displayed on the screen. We
-			// position it in the center of the screen, but we make the origin be the center of the render target
-			// such that it actually gets drawn centered (as opposed to shrinking and exanding with the left corner
-			// in the center). We use our scale computation, and specify no SpriteEffects and an unused 0f for layer
-			// depth
-			spriteBatch.Draw (renderTarget, 
-				new Vector2 (GraphicsDevice.PresentationParameters.BackBufferWidth / 2, GraphicsDevice.PresentationParameters.BackBufferHeight / 2), 
-				null, Color.White, 0f, new Vector2 (renderTarget.Width / 2, renderTarget.Height / 2), scale, 
-				SpriteEffects.None, 0f);
-
-			// End our spriteBatch call.
-			spriteBatch.End ();
-
-			base.Draw (gameTime);
-		}
-	}
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+#if ANDROID
+using Android.App;
+#endif
+
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Audio;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.GamerServices;
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Input;
+using Microsoft.Xna.Framework.Media;
+
+namespace RenderTarget2DSample
+{
+	/// <summary>
+	/// This is the main type for your game
+	/// </summary>
+	public class Game1 : Microsoft.Xna.Framework.Game
+	{
+		/// <summary>
+		/// The GraphicsDeviceManager is what creates and automagically manages the game's GraphicsDevice.
+		/// </summary>
+		GraphicsDeviceManager graphics;
+
+		/// <summary>
+		/// We use SpriteBatch to draw all of our 2D graphics.
+		/// </summary>
+		SpriteBatch spriteBatch;
+
+		/// <summary>
+		/// This is the rendertarget we'll be drawing to.
+		/// </summary>
+		RenderTarget2D renderTarget;
+
+		/// <summary>
+		/// This is a texture we'll be using to load a picture of Seamus the dog.
+		/// </summary>
+		Texture2D mooTheMerciless;
+
+		/// <summary>
+		/// This is a texture we'll be using to load a picture of a tileable wood surface.
+		/// </summary>
+		Texture2D wood;
+		bool oneTimeOnly = true;
+
+		/// <summary>
+		/// The constructor for our Game1 class.
+		/// </summary>
+#if ANDROID 
+		public Game1 (Activity activity) : base (activity)
+#else 
+        public Game1 ()  
+#endif
+		{
+			// Create the GraphicsDeviceManager for our game.
+			graphics = new GraphicsDeviceManager (this);
+
+			// Set the root directory of the game's ContentManager to the "Content" folder.
+			Content.RootDirectory = "Content";
+		}
+
+		/// <summary>
+		/// Allows the game to perform any initialization it needs to before starting to run.
+		/// This is where it can query for any required services and load any non-graphic
+		/// related content.  Calling base.Initialize will enumerate through any components
+		/// and initialize them as well.
+		/// </summary>
+		protected override void Initialize ()
+		{
+			// We don't have anything to initialize.
+
+			base.Initialize ();
+		}
+
+		/// <summary>
+		/// LoadContent will be called once per game and is the place to load
+		/// all of your content.
+		/// </summary>
+		protected override void LoadContent ()
+		{
+
+			// Create a new SpriteBatch, which can be used to draw textures.
+			spriteBatch = new SpriteBatch (GraphicsDevice);
+
+			// Create a rendertarget that matches the back buffer's dimensions, does not generate mipmaps automatically
+			// (the Reach profile requires power of 2 sizing in order to do that), uses an RGBA color format, and
+			// has no depth buffer or stencil buffer.
+			renderTarget = new RenderTarget2D (GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth,
+				GraphicsDevice.PresentationParameters.BackBufferHeight, false, SurfaceFormat.Color, DepthFormat.None);
+
+			// Load in the picture of Seamus.
+			mooTheMerciless = Content.Load<Texture2D> ("MooTheMerciless");
+
+			// Load in our wood tile.
+			wood = Content.Load<Texture2D> ("wood");
+		}
+
+		/// <summary>
+		/// UnloadContent will be called once per game and is the place to unload
+		/// all content.
+		/// </summary>
+		protected override void UnloadContent ()
+		{
+			// While not strictly necessary, you should always dispose of assets you create
+			// (excluding those you load the the ContentManager) when those assets implement
+			// IDisposable. RenderTarget2D is one such asset type, so we dispose of it properly.
+			if (renderTarget != null) {
+				// We put this in a try-catch block. The reason is that if for some odd reason this failed
+				// (e.g. we were using threading and nulled out renderTarget on some other thread),
+				// then none of the rest of the UnloadContent method would run. Here it doesn't make a
+				// difference, but it's good practice nonethless.
+				try {
+					renderTarget.Dispose ();
+					renderTarget = null;
+				} catch {
+				}
+			}
+		}
+
+		/// <summary>
+		/// Allows the game to run logic such as updating the world,
+		/// checking for collisions, gathering input, and playing audio.
+		/// </summary>
+		/// <param name="gameTime">Provides a snapshot of timing values.</param>
+		protected override void Update (GameTime gameTime)
+		{
+			// Allows the game to exit. If this is a Windows version, I also like to check for an Esc key press. I put
+			// it within an #if WINDOWS .. #endif block since that way it won't run on other platforms.
+			if (GamePad.GetState (PlayerIndex.One).Buttons.Back == ButtonState.Pressed
+			//#if WINDOWS
+ || Keyboard.GetState ().IsKeyDown (Keys.Escape)
+//#endif
+) {
+				this.Exit ();
+			}
+
+			// We don't have any update logic since this is just an example usage of RenderTarget2D
+
+			base.Update (gameTime);
+		}
+
+		/// <summary>
+		/// This is called when the game should draw itself.
+		/// </summary>
+		/// <param name="gameTime">Provides a snapshot of timing values.</param>
+		protected override void Draw (GameTime gameTime)
+		{
+			
+			// A one time only flag to help test for memory leaks
+			if (oneTimeOnly) 
+			{				
+				oneTimeOnly = false;
+
+				// Set renderTarget as the surface to draw to instead of the back buffer
+				GraphicsDevice.SetRenderTarget (renderTarget);
+
+				// Clear the renderTarget. By default it's all a bright purple color. I like to use Color.Transparent to
+				// enable easy alpha blending.
+				GraphicsDevice.Clear (Color.Transparent);
+				Vector2 woodPosition = Vector2.Zero;
+
+				// Begin drawing
+				spriteBatch.Begin ();
+
+				int xBlank = 0;
+				int yBlank = 0;
+
+				// Use nested do-whiles to fill the rendertarget with tiles. We use some trickery to draw every other tile
+				do {
+					do {
+						// We use the modulus operator to get the remainder of dividing xBlank by 2. If xBlank is odd, it'll
+						// return 1 and the spriteBatch.Draw call gets skipped. If it's even, it'll return 0 so
+						// spriteBatch.Draw will get called and it'll draw a tile there.
+						if (xBlank % 2 == 0) {
+							spriteBatch.Draw (wood, woodPosition, Color.White);
+						}
+						// Increment xBlank by one so that every other tile will get drawn.
+						xBlank++;
+						// Increase the X coordinate of where we'll draw the wood tile in order to progressively draw
+						// each column of tiles.
+						woodPosition.X += wood.Width;
+
+						// We draw so long as woodPosition.X is less than our renderTarget's width
+					} while (woodPosition.X < renderTarget.Width);
+
+					// We increment yBlank by one. Why is explained below.
+					yBlank++;
+
+					// We use the modulus operater to get the remainder of dividing yBlank by 2. If yBlank is odd, we reset
+					// xBlank to 1. If it's even, we reset xBlank to 0. This way each row shifts by one so that the tiles
+					// are drawn in a checkered pattern rather than in columns.
+					if (yBlank % 2 == 0) {
+						xBlank = 0;
+					} else {
+						xBlank = 1;
+					}
+
+					// Reset woodPosition.X to zero so that we start drawing from the beginning of the next row.
+					woodPosition.X = 0;
+
+					// Increase the Y coord of where we'll draw the wood tile in order to progressively draw each
+					// row of tiles.
+					woodPosition.Y += wood.Height;
+
+					// We draw so long as woodPosition.Y is less than our renderTarget's width
+				} while (woodPosition.Y < renderTarget.Height);
+
+				// Now that we've drawn the wood tiles, we draw Moo the Merciless. We draw him centered in the rendertarget.
+				spriteBatch.Draw (mooTheMerciless, 
+				new Vector2 ((renderTarget.Width / 2f) - (mooTheMerciless.Width / 2f), (renderTarget.Height / 2f) - (mooTheMerciless.Height / 2f)), 
+				Color.White);
+
+				// End the spriteBatch draw.
+				spriteBatch.End ();
+
+				// Switch back to drawing onto the back buffer
+				GraphicsDevice.SetRenderTarget (null);
+			}
+			// Now that we're back to drawing onto the back buffer, we want to clear it. If we had done so earlier
+			// then when we switched to drawing to the render target, the old back buffer would've just be filled with
+			// that bright purple color when we came back to it.
+			GraphicsDevice.Clear (Color.CornflowerBlue);
+
+			// Ok. At this point we have everything we drew in renderTarget, which we can use just like a regular Texture2D.
+			// To make it look more interesting, we're going to scale up and down based on total elapsed time.
+			float scale = 1.0f;
+
+			if (gameTime.TotalGameTime.TotalSeconds % 10 < 5.0) {
+				// We're running on a ten second scale timer. For the first five second we scale down from 1f to
+				// no less than 0.01f.
+				scale = MathHelper.Clamp (1f - (((float)gameTime.TotalGameTime.TotalSeconds % 5) / 5f), 0.01f, 1f);
+			} else {
+				// For the second five seconds, we scale up from no less than 0.01f up to 1f.
+				scale = MathHelper.Clamp (((float)gameTime.TotalGameTime.TotalSeconds % 5) / 5f, 0.01f, 1f);
+			}
+
+			// Start spriteBatch again (this time drawing to the back buffer)
+			spriteBatch.Begin ();
+
+			// Now we draw our render target to the back buffer so that it will get displayed on the screen. We
+			// position it in the center of the screen, but we make the origin be the center of the render target
+			// such that it actually gets drawn centered (as opposed to shrinking and exanding with the left corner
+			// in the center). We use our scale computation, and specify no SpriteEffects and an unused 0f for layer
+			// depth
+			spriteBatch.Draw (renderTarget, 
+				new Vector2 (GraphicsDevice.PresentationParameters.BackBufferWidth / 2, GraphicsDevice.PresentationParameters.BackBufferHeight / 2), 
+				null, Color.White, 0f, new Vector2 (renderTarget.Width / 2, renderTarget.Height / 2), scale, 
+				SpriteEffects.None, 0f);
+
+			// End our spriteBatch call.
+			spriteBatch.End ();
+
+			base.Draw (gameTime);
+		}
+	}
+}

+ 1 - 1
Samples/MacOS/RenderTarget2DSample/RenderTarget2DSample.csproj

@@ -6,7 +6,7 @@
     <ProductVersion>10.0.0</ProductVersion>
     <SchemaVersion>2.0</SchemaVersion>
     <ProjectGuid>{973C423F-0CC0-4230-9E67-D944ED70ED19}</ProjectGuid>
-    <ProjectTypeGuids>{1C533B1C-72DD-4CB1-9F6B-BF11D93BCFBE};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ProjectTypeGuids>{948B3504-5B70-4649-8FE4-BDE1FB46EC69};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
     <OutputType>Exe</OutputType>
     <RootNamespace>RenderTarget2DSample</RootNamespace>
     <AssemblyName>RenderTarget2DSample</AssemblyName>