PageRenderTime 717ms CodeModel.GetById 131ms app.highlight 357ms RepoModel.GetById 48ms app.codeStats 3ms

/Rendering/BasicTests/MaterialTests.cs

#
C# | 1329 lines | 900 code | 121 blank | 308 comment | 27 complexity | aa3bb33a8bf55d6b95d3f798d158aa30 MD5 | raw file
   1using System.Diagnostics;
   2using Delta.ContentSystem;
   3using Delta.ContentSystem.Rendering;
   4using Delta.Engine;
   5using Delta.Engine.Game;
   6using Delta.Graphics.Basics;
   7using Delta.InputSystem;
   8using Delta.InputSystem.Devices;
   9using Delta.Rendering.Basics.Drawing;
  10using Delta.Rendering.Basics.Fonts;
  11using Delta.Rendering.Basics.Materials;
  12using Delta.Rendering.Cameras;
  13using Delta.Rendering.Enums;
  14using Delta.Utilities;
  15using Delta.Utilities.Datatypes;
  16using Delta.Utilities.Graphics;
  17using Delta.Utilities.Helpers;
  18using NUnit.Framework;
  19
  20namespace Delta.Rendering.BasicTests
  21{
  22	/// <summary>
  23	/// Material tests 
  24	/// </summary>
  25	[Category("Visual")]
  26	internal class MaterialTests
  27	{
  28		#region DrawDefaultMaterial
  29		/// <summary>
  30		/// Draw default material, has 10-15k fps, pretty good. All dynamic.
  31		/// </summary>
  32		[Test]
  33		public static void DrawDefaultMaterial()
  34		{
  35			Application.Start(delegate
  36			{
  37				Material2D.Default.Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f));
  38			});
  39		}
  40		#endregion
  41
  42		#region DrawDefaultMaterialAutoRotated
  43		/// <summary>
  44		/// Draw default material auto rotated.
  45		/// </summary>
  46		[Test]
  47		public static void DrawDefaultMaterialAutoRotated()
  48		{
  49			float rotation = 0.0f;
  50
  51			Application.Start(delegate
  52			{
  53				rotation += Time.Delta * 10.0f;
  54
  55				Material2D.Default.Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f),
  56					rotation);
  57			});
  58		}
  59		#endregion
  60
  61		#region DrawDefaultMaterialColoredFullscreen
  62		/// <summary>
  63		/// Draw default material with color on fullscreen. Testing bug #4481
  64		/// </summary>
  65		[Test]
  66		public static void DrawDefaultMaterialColoredFullscreen()
  67		{
  68			Material2DColored background = new Material2DColored(
  69				//Color.Red);
  70				"DeltaIcon");
  71			Application.Start(delegate
  72			{
  73				background.Draw(Rectangle.One);
  74			});
  75		}
  76		#endregion
  77
  78		#region DrawDefaultMaterialWithLines
  79		/// <summary>
  80		/// Draw default material and some lines, can get up to 10k fps.
  81		/// </summary>
  82		[Test]
  83		public static void DrawDefaultMaterialWithLines()
  84		{
  85			// The default fallback material texture (4x4) should use no filtering
  86			Assert.False(Material2D.Default.diffuseMap.UseLinearFiltering);
  87			Application.BackgroundColor = Color.Unused;
  88
  89			Application.Start(delegate
  90			{
  91				Material2D.Default.Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f));
  92
  93				Line.Draw(new Point(0, 0.5f), new Point(1, 0.5f), Color.Red);
  94				Line.Draw(new Point(0.5f, 0), new Point(0.5f, 1), Color.Green);
  95				Line.Draw(new Point(0, 0), new Point(1, 1), Color.Yellow);
  96			});
  97		}
  98		#endregion
  99
 100		#region DrawManyMaterialsPerformance
 101		/// <summary>
 102		/// Draw many materials performance test
 103		/// </summary>
 104		[Test]
 105		public static void DrawManyMaterialsPerformance()
 106		{
 107			// With new optimizations on PC we have ~1500 fps for 2500 draws with
 108			// 5000 polys (or 10000 quad vertices), so we have 7.5m poly/s (in
 109			// debug mode, in release mode it is almost 10m poly/s).
 110			// Note: When using 25000 draws per frame (50000 polys), it still
 111			// comes out to about 7.5m poly/s with ~150 fps.
 112
 113			// New optimizations done 2011-03-20, mostly caching MaterialManager layers in Material now!
 114			// Performance for the DrawManyMaterialsPerformance unit test is about 4000fps (release, in debug still 2500fps) for 10000 vertices,
 115			// which is 40 million dynamic vertices with 60 million indices for 20 million dynamic polys
 116			// per second (not really dynamic anymore because of caching, but you can change them anytime)!
 117			// Other unit tests are also doing well, almost all simple tests easily reach 10000fps in debug mode!
 118			//OK: performance for this is horrible, 5000 polys and only 1000fps, it is all CPU limited for all the .Save methods used here (and new Point for each property there), which can be optimized! See MaterialTests.DrawManyMaterialsPerformance()!
 119			//OK: continue optimizing, first get this as fast as possible (even in debug mode, some checks are just too slow)
 120			//OK: then try to remember the values from last time and skip updating/adding and even the hash code check in geometry if nothing has changed at all (which is the case in 99.9% of the time for dynamic data).
 121			//OK: we should get a few thousand fps :)
 122			//OK: indices are always the same, why not calculate when creating indices?
 123			//OK: do most checks at initialization time of the render geometry (does not change after that)
 124			//OK: put in method, always the same, isn't it? same as creation!
 125			//OK: easy caching of GeometryData or RenderGeometryByAtlas does not work this easily, we need to cache the whole result of the render geometry tree, next time all steps have to be retraced and we need to increase the counters to make rendering work!
 126			//OK: all GeometryData initialization code is always the same and can be in a method too!
 127
 128			/*performance result in iPad debug mode:
 12912.673 totalCpuTimeMs=5121 (95.36313%)
 13012.674 totalGpuTimeMs=249 (4.636871%)
 13112.675 Last frame OnRenderFrame time: 34ms (CPU: 34ms, GPU: 0ms)
 13212.675 Last frame Time.Delta: 0.03338146
 13312.678 Total Application Time: 12.17727s
 134We got 5 sections that took in total: 6.317755s
 135 Section Time took: 0.007066727s (0.111855%), Calls: 294, first time called: 1.151879s
 136 Section Application delegate run code took: 5.47965s (86.73415%), Calls: 294, first time called: 1.154123s
 137 Section ContentManager took: 0.004089594s (0.06473176%), Calls: 294, first time called: 1.581513s
 138 Section OpenGLES20Graphic took: 0.008611083s (0.1362997%), Calls: 293, first time called: 1.623532s
 139 Section MaterialManager took: 0.818337s (12.95297%), Calls: 293, first time called: 2.007285s
 140			 */
 141
 142			// 5 layers * 50 * 10 = 2500 draws per frame (which is 5000 polygons or
 143			// 10000 vertices with 15000 indices being rendered, these are also the
 144			// limits for MaterialManager right now)!
 145			int numberOfLayerTypes = EnumHelper.GetCount<RenderLayer>();
 146			const int HorizontalDrawsPerLayer = 50;
 147			const int VerticalDrawsPerLayer = 10;
 148			const float DrawSize = 0.6f / HorizontalDrawsPerLayer;
 149
 150			Material2D material = new Material2D(Content.EmptyName)
 151			{
 152				DrawLayer = RenderLayer.Text,
 153			};
 154
 155			Application.Start(delegate
 156			{
 157				for (int layer = 0; layer < numberOfLayerTypes; layer++)
 158				{
 159					for (int y = 0; y < VerticalDrawsPerLayer; y++)
 160					{
 161						for (int x = 0; x < HorizontalDrawsPerLayer; x++)
 162						{
 163							material.Draw(new Rectangle(x / (float)HorizontalDrawsPerLayer,
 164								0.1f + 0.15f * (layer + (y / (float)VerticalDrawsPerLayer)),
 165								DrawSize, DrawSize));
 166						}
 167					} // for
 168				} // for
 169			});
 170		}
 171		#endregion
 172
 173		#region DrawTwoSameMaterials
 174		/// <summary>
 175		/// Helper unit test to check if Niko's Bug report about rendering the same
 176		/// image in a different order does not affect rendering. This test proves
 177		/// that it all works fine (he had different content caching bugs btw,
 178		/// non-loaded images were compared to loaded ones, this is already fixed
 179		/// in v0.8.3.2).
 180		/// </summary>
 181		[Test]
 182		public static void DrawTwoSameMaterials()
 183		{
 184			Material2D material1 = new Material2D("DeltaEngineLogo");
 185			Material2D material2 = new Material2D("DeltaEngineLogo");
 186			bool material2First = false;
 187			Application.Start(delegate
 188			{
 189				// All the same, just render material2 first if space was pressed,
 190				// otherwise render material1 first, then material2.
 191				if (material2First)
 192				{
 193					material2.Draw(new Rectangle(0.5f, 0.5f, 0.25f, 0.25f));
 194					material1.Draw(ScreenSpace.DrawArea);
 195				}
 196				else
 197				{
 198					material1.Draw(ScreenSpace.DrawArea);
 199					material2.Draw(new Rectangle(0.5f, 0.5f, 0.25f, 0.25f));
 200				}
 201
 202				if (Input.Keyboard.SpaceReleased)
 203				{
 204					material2First = !material2First;
 205				}
 206			});
 207		}
 208		#endregion
 209
 210		#region DrawAnimatedAndNormalImagesAlternating
 211		/// <summary>
 212		/// Draw Animated and Normal Images Alternating
 213		/// </summary>
 214		[Test]
 215		public static void DrawAnimatedAndNormalImagesAlternating()
 216		{
 217			Material2D material = new Material2D("ImageAnimation");
 218			Material2D staticImage = new Material2D("DeltaEngineLogo");
 219
 220			bool showAnimated = true;
 221			Application.Start(delegate
 222			{
 223				staticImage.Draw(new Rectangle(0f, 0f, 0.2f, 0.2f));
 224
 225				if (showAnimated)
 226				{
 227					material.Draw(new Rectangle(0.2f, 0.35f, 0.6f, 0.3f));
 228				}
 229				else
 230				{
 231					staticImage.Draw(new Rectangle(0.2f, 0.35f, 0.6f, 0.3f));
 232				}
 233
 234				if (Time.CheckEvery(2))
 235				{
 236					showAnimated = !showAnimated;
 237				}
 238			});
 239		}
 240		#endregion
 241
 242		#region DrawAnimatedImageWithGameTimePause
 243		/// <summary>
 244		/// Draw Animated image with game time pause.
 245		/// </summary>
 246		[Test]
 247		public static void DrawAnimatedImageWithGameTimePause()
 248		{
 249			Material2D material = new Material2D("ImageAnimation");
 250
 251			Application.Start(delegate
 252			{
 253				material.Draw(Rectangle.FromCenter(0.5f, 0.5f, 0.2f, 0.2f));
 254
 255				if (Input.Keyboard.SpaceReleased)
 256				{
 257					if (GameTime.IsRunning)
 258					{
 259						GameTime.Pause();
 260					}
 261					else
 262					{
 263						GameTime.Start();
 264					}
 265				}
 266			});
 267		}
 268		#endregion
 269
 270		#region DrawMaterialFlipped
 271		/// <summary>
 272		/// This test explains how to draw materials vertically or horizontally
 273		/// flipped. Internally the UVs are flipped, nothing else changes. You can
 274		/// combine this with other operations like rotation or coloring as well.
 275		/// </summary>
 276		[Test]
 277		public static void DrawMaterialFlipped()
 278		{
 279			Material2DColored logo = new Material2DColored("DeltaEngineLogo");
 280
 281			Application.Start(delegate
 282			{
 283				logo.Draw(Rectangle.FromCenter(
 284					Point.Half + new Size(-0.5f, -0.5f) * logo.Size, logo.Size), 0,
 285					FlipMode.None);
 286				logo.Draw(Rectangle.FromCenter(
 287					Point.Half + new Size(0.5f, -0.5f) * logo.Size, logo.Size), 0,
 288					FlipMode.Horizontal);
 289				logo.Draw(Rectangle.FromCenter(
 290					Point.Half + new Size(-0.5f, 0.5f) * logo.Size, logo.Size), 0,
 291					FlipMode.Vertical);
 292				logo.Draw(Rectangle.FromCenter(
 293					Point.Half + new Size(0.5f, 0.5f) * logo.Size, logo.Size), 0,
 294					FlipMode.VerticalAndHorizontal);
 295			});
 296		}
 297		#endregion
 298
 299		#region DrawMaterialRotatedAroundPoint
 300		/// <summary>
 301		/// Draw default material rotated around a custom point. As requested in
 302		/// http://forum.deltaengine.net/yaf_postsm1094_Rotate-a-Material2D.aspx
 303		/// </summary>
 304		[Test]
 305		public static void DrawMaterialRotatedAroundPoint()
 306		{
 307			float rotation = 0.0f;
 308
 309			Application.Start(delegate
 310			{
 311				rotation += Time.Delta * 100.0f;
 312
 313				Material2D.Default.Draw(new Rectangle(0.3f, 0.3f, 0.4f, 0.4f),
 314					rotation, new Point(0.3f, 0.3f));
 315			});
 316		}
 317		#endregion
 318
 319		#region BlendModes
 320		/// <summary>
 321		/// Blend modes. We test the different blend modes with textures.
 322		/// </summary>
 323		[Test]
 324		public static void BlendModes()
 325		{
 326			// Test Additive BlendMode
 327			Material2D additive = new Material2D("DeltaAdditive");
 328
 329			// Test LightEffect BlendMode
 330			Material2D lightEffect = new Material2D("BlendModesLightEffect");
 331
 332			// Test AlphaTest BlendMode
 333			Material2D transparent = new Material2D(
 334				"DeltaIcon");
 335
 336			// Test Substractive BlendMode
 337			Material2D substractive = new Material2D("DeltaSubtractive");
 338
 339			// And draw them all
 340			Application.Start(delegate
 341			{
 342				Material2D.Default.Draw(Rectangle.FromCenter(Point.Half, 0.25f));
 343				additive.Draw(new Rectangle(new Point(0.5f - additive.Size.Width,
 344					0.5f - additive.Size.Height), additive.Size));
 345				lightEffect.Draw(new Rectangle(new Point(0.5f,
 346					0.5f - lightEffect.Size.Height), lightEffect.Size));
 347				transparent.Draw(new Rectangle(new Point(0.5f - transparent.Size.Width,
 348					0.5f), transparent.Size));
 349				substractive.Draw(new Rectangle(new Point(0.5f,
 350					0.5f), substractive.Size));
 351			});
 352		}
 353		#endregion
 354
 355		#region DrawTransparentMaterial
 356		/// <summary>
 357		/// Draw transparent material
 358		/// </summary>
 359		[Test]
 360		public static void DrawTransparentMaterial()
 361		{
 362			Material2D material = new Material2D("DeltaIcon");
 363
 364			Application.Start(delegate
 365			{
 366				material.Draw(Rectangle.FromCenter(Point.Half, material.Size));
 367			});
 368		}
 369		#endregion
 370
 371		#region DrawOpaqueMaterial
 372		/// <summary>
 373		/// Draw opaque material
 374		/// </summary>
 375		[Test]
 376		public static void DrawOpaqueMaterial()
 377		{
 378			Material2D opaqueMat = new Material2D("ImageAnimation");
 379			Application.BackgroundColor = Color.Red;
 380
 381			Application.Start(delegate
 382			{
 383				opaqueMat.Draw(ScreenSpace.DrawArea);
 384				Font.DrawTopLeftInformation("Fps: " + Time.Fps);
 385			});
 386		}
 387		#endregion
 388
 389		#region DrawTwoMaterialsFromSameAtlas
 390		/// <summary>
 391		/// Draw two materials from same atlas. Helped fixing bug #3197, now we
 392		/// got 9000fps with 2 materials and only 1 draw call :)
 393		/// </summary>
 394		[Test]
 395		public static void DrawTwoMaterialsFromSameAtlas()
 396		{
 397			Material2D testMat1 = new Material2D("DeltaEngineLogo");
 398			Material2D testMat2 = new Material2D("DefaultButtonBackground");
 399
 400			Application.Start(delegate
 401			{
 402				testMat1.Draw(new Rectangle(0.2f, 0.2f, 0.3f, 0.2f));
 403				testMat2.Draw(new Rectangle(0.3f, 0.3f, 0.3f, 0.2f));
 404				// Note: Fonts eat up lots of performance, disable for more fps
 405				Font.DrawTopLeftInformation("Fps: " + Time.Fps);
 406			});
 407		}
 408		#endregion
 409
 410		#region DrawAdditiveMaterial
 411		/// <summary>
 412		/// DrawAdditiveMaterial for the bug #3173
 413		/// </summary>
 414		[Test]
 415		public static void DrawAdditiveMaterial()
 416		{
 417			Material2D background = new Material2D("DeltaEngineLogo");
 418			background.DrawLayer = RenderLayer.Background;
 419			Material2D material = new Material2D("DeltaAdditive");
 420			Material2D material2 = new Material2D("SmokeSmallAdditive");
 421
 422			Application.Start(delegate
 423			{
 424				background.Draw(Rectangle.FromCenter(Point.Half, background.Size));
 425				material.Draw(Rectangle.FromCenter(Point.Half, material.Size));
 426				material2.Draw(Rectangle.One);
 427			});
 428		}
 429		#endregion
 430
 431		#region DrawSubtractiveMaterial
 432		/// <summary>
 433		/// DrawSubtractiveMaterial
 434		/// </summary>
 435		[Test]
 436		public static void DrawSubtractiveMaterial()
 437		{
 438			Material2D background = new Material2D("DeltaEngineLogo")
 439			{
 440				DrawLayer = RenderLayer.Background,
 441			};
 442			Material2D material = new Material2D("DeltaSubtractive");
 443			Application.Start(delegate
 444			{
 445				background.Draw(Rectangle.FromCenter(Point.Half, background.Size));
 446				material.Draw(Rectangle.FromCenter(Point.Half, material.Size));
 447			});
 448		}
 449		#endregion
 450
 451		#region DrawAdditiveMaterialComplex
 452		/// <summary>
 453		/// Draw additive materials onto each other.
 454		/// Move two of the materials back and forth to see the additive effect
 455		/// at work.
 456		/// </summary>
 457		[Test]
 458		public static void DrawAdditiveMaterialComplex()
 459		{
 460			RenderLayer drawLayer = RenderLayer.Normal;
 461
 462			Material2DColored additive = new Material2DColored("DeltaAdditive")
 463			{
 464				DrawLayer = drawLayer,
 465			};
 466			Material2DColored halfTransparent = new Material2DColored(
 467				"DeltaAdditive")
 468			{
 469				DrawLayer = drawLayer,
 470				BlendColor = Color.WhiteHalfTransparent,
 471			};
 472			Material2DColored transparentGrey = new Material2DColored(
 473				"DeltaAdditive")
 474			{
 475				DrawLayer = drawLayer,
 476				BlendColor = Color.Grey,
 477			};
 478
 479			float start = 0.2f;
 480			float end = 0.6f;
 481			float offset = start;
 482			float speed = 0.05f;
 483			bool direction = true;
 484
 485			Application.Start(delegate
 486			{
 487				offset +=
 488					Time.Delta *
 489					(direction
 490					 	? speed
 491					 	: -speed);
 492				if (offset > end ||
 493				    offset < start)
 494				{
 495					direction = !direction;
 496				}
 497
 498				additive.Draw(new Rectangle(0.4f, 0.4f, 0.2f, 0.2f), 0.0f);
 499				// WhiteHalfAlpha and Grey should both be the same (50% of original)
 500				halfTransparent.Draw(new Rectangle(offset, 0.41f, 0.2f, 0.2f));
 501				transparentGrey.Draw(new Rectangle(0.41f, offset, 0.2f, 0.2f), 0.0f);
 502			});
 503		}
 504		#endregion
 505
 506		#region DrawLightEffectMaterial
 507		/// <summary>
 508		/// Draw LightEffect Material
 509		/// </summary>
 510		[Test]
 511		public static void DrawLightEffectMaterial()
 512		{
 513			Material2D lightEffect = new Material2D("BlendModesLightEffect");
 514
 515			Application.Start(delegate
 516			{
 517				lightEffect.Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f));
 518			});
 519		}
 520		#endregion
 521
 522		#region DrawAnimatedMaterial
 523		/// <summary>
 524		/// Test animated material from Content.xml, must exist there and be setup
 525		/// correctly (either with AnimatedSpeed or with AnimationIndexAndMs).
 526		/// </summary>
 527		[Test]
 528		public static void DrawAnimatedMaterial()
 529		{
 530			Material2D animatedMaterial = new Material2D("BigExplosion");
 531
 532			Application.Start(delegate
 533			{
 534				// By default all animations play right away
 535				if (Input.Keyboard.SpaceReleased)
 536				{
 537					if (animatedMaterial.IsPlaying)
 538					{
 539						animatedMaterial.StopAnimation();
 540					}
 541					else
 542					{
 543						animatedMaterial.StartAnimation(true);
 544					}
 545				}
 546
 547				animatedMaterial.Draw(new Rectangle(0.4f, 0.4f, 0.2f, 0.2f));
 548			});
 549		}
 550		#endregion
 551
 552		#region DrawAnimatedMaterialAndOverwritingAnimationSpeed
 553		/// <summary>
 554		/// Test animated material from Content and overwriting the AnimationSpeed.
 555		/// </summary>
 556		[Test]
 557		public static void DrawAnimatedMaterialAndOverwritingAnimationSpeed()
 558		{
 559			Material2D animatedMaterial = new Material2D("BigExplosion");
 560
 561			animatedMaterial.AnimationSpeed = 5;
 562
 563			Application.Start(delegate
 564			{
 565				// With space we switch 2 speed values to see the difference.
 566				if (Input.Keyboard.SpaceReleased)
 567				{
 568					animatedMaterial.AnimationSpeed =
 569						animatedMaterial.AnimationSpeed == 5
 570							? 10
 571							: 5;
 572				}
 573				animatedMaterial.Draw(new Rectangle(0.4f, 0.4f, 0.2f, 0.2f));
 574			});
 575		}
 576		#endregion
 577
 578		#region DrawAnimatedMaterialCustomIndicesAndTimes
 579		/// <summary>
 580		/// Test animated material from Content.xml and using custom
 581		/// AnimationIndexAndMs values.
 582		/// </summary>
 583		[Test]
 584		public static void DrawAnimatedMaterialCustomIndicesAndTimes()
 585		{
 586			Material2D animatedMaterial = new Material2D("ImageAnimation");
 587
 588			// This is image meta-data and set automatically be the content!
 589			// We will overwrite it with our own indices and times in ms.
 590			animatedMaterial.AnimationFrameIndicesAndMs = new[]
 591			{
 592				// ImageAnimation has 10 frames (first number = frame, second = ms)
 593				// Count to 2 in 2 seconds
 594				0, 1000,
 595				1, 1000,
 596				// Count to 3 in 2 seconds
 597				0, 666,
 598				1, 666,
 599				2, 666,
 600				// Count to 4 in 2 seconds
 601				0, 500,
 602				1, 500,
 603				2, 500,
 604				3, 500,
 605				// Count to 5 in 2 seconds
 606				0, 400,
 607				1, 400,
 608				2, 400,
 609				3, 400,
 610				4, 400,
 611				// Count to 6 in 2 seconds
 612				0, 333,
 613				1, 333,
 614				2, 333,
 615				3, 333,
 616				4, 333,
 617				5, 333,
 618				// Count to 7 in 2 seconds
 619				0, 285,
 620				1, 285,
 621				2, 285,
 622				3, 285,
 623				4, 285,
 624				5, 285,
 625				6, 285,
 626				// Count to 8 in 2 seconds
 627				0, 250,
 628				1, 250,
 629				2, 250,
 630				3, 250,
 631				4, 250,
 632				5, 250,
 633				6, 250,
 634				7, 250,
 635				// Count to 9 in 2 seconds
 636				0, 222,
 637				1, 222,
 638				2, 222,
 639				3, 222,
 640				4, 222,
 641				5, 222,
 642				6, 222,
 643				7, 222,
 644				8, 222,
 645				// Count to 10
 646				0, 200,
 647				1, 200,
 648				2, 200,
 649				3, 200,
 650				4, 200,
 651				5, 200,
 652				6, 200,
 653				7, 200,
 654				8, 200,
 655				9, 200,
 656			};
 657
 658			Application.Start(delegate
 659			{
 660				if (Input.Keyboard.SpaceReleased)
 661				{
 662					if (animatedMaterial.IsPlaying)
 663					{
 664						animatedMaterial.StopAnimation();
 665					}
 666					else
 667					{
 668						animatedMaterial.StartAnimation(true);
 669					}
 670				} // if
 671
 672				animatedMaterial.Draw(new Rectangle(0.4f, 0.4f, 0.2f, 0.2f));
 673			});
 674		}
 675		#endregion
 676
 677		#region DrawLayeredMaterials
 678		/// <summary>
 679		/// Helper to figure out some old bug with texture atlas switching
 680		/// </summary>
 681		[Test]
 682		public static void DrawLayeredMaterials()
 683		{
 684			/*iPad debug result:
 68512.427 OnUnload Fps: 31.87856
 68612.709 totalCpuTimeMs=1758 (90.10764%)
 68712.710 totalGpuTimeMs=193 (9.892363%)
 68812.710 Last frame OnRenderFrame time: 29ms (CPU: 29ms, GPU: 0ms)
 68912.710 Last frame Time.Delta: 0.03332901
 69012.713 Total Application Time: 12.07296s
 691We got 6 sections that took in total: 3.000518s
 692 Section Time took: 0.01031613s (0.3438118%), Calls: 549, first time called: 1.075648s
 693 Section Application delegate run code took: 1.729822s (57.65079%), Calls: 549, first time called: 1.077253s
 694 Section ContentManager took: 0.00714159s (0.2380119%), Calls: 549, first time called: 2.362464s
 695 Section OpenGLES20Graphic took: 0.01350093s (0.4499533%), Calls: 548, first time called: 2.397646s
 696 Section MaterialManager took: 1.128s (37.59352%), Calls: 548, first time called: 2.401425s
 697 Section Draw took: 0.111737s (3.723924%), Calls: 548, first time called: 2.67375s
 698			 */
 699
 700			// Works fine with this or all default materials!
 701			Material2DColored[] testMaterials = new[]
 702			{
 703				new Material2DColored("SmokeSmallAdditive")
 704				{
 705					DrawLayer = RenderLayer.UI,
 706					BlendColor = Color.Yellow,
 707				},
 708				new Material2DColored("DeltaEngineLogo")
 709				{
 710					DrawLayer = RenderLayer.Front,
 711					BlendColor = Color.Red,
 712				},
 713				new Material2DColored("LensflareDTransparency")
 714				{
 715					DrawLayer = RenderLayer.Normal,
 716					BlendColor = Color.Blue,
 717				},
 718				new Material2DColored("SteamAdditive")
 719				{
 720					DrawLayer = RenderLayer.Background,
 721				},
 722				new Material2DColored("WaterSplatterAdditive")
 723				{
 724					DrawLayer = RenderLayer.Front,
 725					BlendColor = Color.Green,
 726				},
 727			};
 728
 729			Application.Start(delegate
 730			{
 731				Font.DrawTopLeftInformation("Fps: " + Time.Fps);
 732
 733				testMaterials[0].Draw(new Rectangle(0.15f, 0.15f, 0.15f, 0.15f));
 734				testMaterials[1].Draw(new Rectangle(0.2f, 0.2f, 0.34f, 0.34f));
 735				testMaterials[2].Draw(new Rectangle(0.2f, 0.2f, 0.45f, 0.45f));
 736				testMaterials[3].Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f));
 737				testMaterials[4].Draw(new Rectangle(0.2f, 0.2f, 0.15f, 0.15f));
 738			});
 739		}
 740		#endregion
 741
 742		#region DrawManyMaterialsInSameLayer
 743		/// <summary>
 744		/// Draw many materials in same layer
 745		/// </summary>
 746		[Test]
 747		public static void DrawManyMaterialsInSameLayer()
 748		{
 749			const int DrawCalls = 10;
 750			const float DrawOffset = 0.025f;
 751
 752			const string textureName = "DeltaAdditive";
 753			Material2D material = new Material2D(textureName);
 754
 755			Application.Start(delegate
 756			{
 757				float leftStart = ScreenSpace.DrawArea.X + 0.025f;
 758				float topStart = ScreenSpace.DrawArea.Y + 0.025f;
 759
 760				// First test overlapped drawing when using the same material
 761				Rectangle drawArea = new Rectangle(leftStart, topStart, 0.225f, 0.15f);
 762				for (int index = 0; index < DrawCalls; index++)
 763				{
 764					material.Draw(drawArea);
 765
 766					drawArea.X += DrawOffset;
 767					drawArea.Y = ((index + 1) == (DrawCalls / 2))
 768					             	? topStart
 769					             	: drawArea.Y + DrawOffset;
 770				}
 771
 772				// Second test overlapped drawing when using always a new material
 773				drawArea.X = leftStart + 0.5f;
 774				drawArea.Y = topStart;
 775				for (int index = 0; index < DrawCalls; index++)
 776				{
 777					new Material2DColored(textureName).Draw(drawArea);
 778
 779					drawArea.X += DrawOffset;
 780					drawArea.Y = ((index + 1) == (DrawCalls / 2))
 781					             	? topStart
 782					             	: drawArea.Y + DrawOffset;
 783				}
 784			});
 785		}
 786		#endregion
 787
 788		#region DrawMaterialClipped
 789		/// <summary>
 790		/// Draw material clipped
 791		/// </summary>
 792		[Test]
 793		public static void DrawMaterialClipped()
 794		{
 795			Material2DColored testMaterial =
 796				new Material2DColored("DeltaEngineLogo");
 797
 798			Rectangle materialArea = Rectangle.FromCenter(0.5f, 0.3f, 0.2f, 0.2f);
 799			Rectangle strechedArea = Rectangle.FromCenter(0.3f, 0.6f, 0.1f, 0.2f);
 800			Rectangle clippedArea = Rectangle.FromCenter(0.7f, 0.6f, 0.1f, 0.2f);
 801
 802			float horizontalClipBorder = 0.5f;
 803			float verticalClipBorder = 0.5f;
 804			Application.Start(delegate
 805			{
 806				BaseMouse mouse = Input.Mouse;
 807				if (Input.Gestures.IsHorizontalDrag ||
 808				    Input.Gestures.IsVerticalDrag)
 809				{
 810					horizontalClipBorder =
 811						MathHelper.Clamp(horizontalClipBorder - mouse.Movement.X);
 812					verticalClipBorder =
 813						MathHelper.Clamp(verticalClipBorder - mouse.Movement.Y);
 814				}
 815
 816				testMaterial.Draw(materialArea);
 817				testMaterial.Draw(strechedArea);
 818				testMaterial.Draw(clippedArea,
 819					new Rectangle(horizontalClipBorder, verticalClipBorder,
 820						1f - horizontalClipBorder, 1f - verticalClipBorder));
 821			});
 822		}
 823		#endregion
 824
 825		#region DrawTwoTexturesSameSizeColorAndUV
 826		/// <summary>
 827		/// This is testing two (atlas) materials which has the same size, uv
 828		/// coordinates and the same blending color.
 829		/// </summary>
 830		[Test]
 831		public static void DrawTwoTexturesSameSizeColorAndUV()
 832		{
 833			Material2DColored material1 = new Material2DColored("ImageAnimation01",
 834				Color.White);
 835			Material2DColored material2 = new Material2DColored("ImageAnimation02",
 836				Color.White);
 837
 838			Rectangle drawArea = new Rectangle(0.2f, 0.3f, 0.2f, 0.2f);
 839
 840			Application.Start(delegate
 841			{
 842				// Use the space key to toggle the materials
 843				// -> we should see the image with "2" if the space is pressed
 844				if (Input.Keyboard.SpaceIsPressed)
 845				{
 846					material2.Draw(drawArea);
 847				}
 848					// or the image with the "1" if we do nothing
 849				else
 850				{
 851					material1.Draw(drawArea);
 852				}
 853			});
 854		}
 855		#endregion
 856
 857		#region DrawScreenRectangle
 858		/// <summary>
 859		/// Draw the default material in the screen area rectangle.
 860		/// </summary>
 861		[Test]
 862		public static void DrawScreenRectangle()
 863		{
 864			Application.Start(delegate
 865			{
 866				// There should be a border of 1 pixel around this image!
 867				Material2D.Default.Draw(ScreenSpace.ToQuadraticSpace(
 868					new Rectangle(1, 1, Application.Window.ViewportPixelWidth - 2,
 869						Application.Window.ViewportPixelHeight - 2)));
 870			});
 871		}
 872		#endregion
 873
 874		#region DrawDDS888Image
 875		/// <summary>
 876		/// Draw image special unit test for testing DDS textures with the 888
 877		/// format like for the Shader lut helper textures.
 878		/// </summary>
 879		[Test]
 880		public static void DrawDDS888Image()
 881		{
 882			Material2D testMat = new Material2D("Specular10Fresnel4Lut");
 883
 884			Application.Start(delegate
 885			{
 886				testMat.Draw(new Rectangle(0.2f, 0.3f, 0.5f, 0.5f));
 887			});
 888		}
 889		#endregion
 890
 891		#region DrawPureColoredMaterial
 892		/// <summary>
 893		/// This test shows 3 pure colored materials and a colored one with a
 894		/// texture.
 895		/// </summary>
 896		[Test]
 897		public static void DrawPureColoredMaterial()
 898		{
 899			Material2DColored material1 = new Material2DColored(Color.Red);
 900			Material2DColored material2 = new Material2DColored(Color.Green);
 901			Material2DColored material3 = new Material2DColored(Color.Blue);
 902			Material2DColored materialTexture = new Material2DColored("",
 903				Color.Yellow);
 904
 905			Application.Start(delegate
 906			{
 907				material1.Draw(new Rectangle(0.2f, 0.2f, 0.2f, 0.2f));
 908				material2.Draw(new Rectangle(0.4f, 0.2f, 0.2f, 0.2f));
 909				material3.Draw(new Rectangle(0.6f, 0.2f, 0.2f, 0.2f));
 910				materialTexture.Draw(new Rectangle(0.2f, 0.4f, 0.2f, 0.2f));
 911			});
 912		}
 913		#endregion
 914
 915		#region DrawSimpleBrownMaterial
 916		/// <summary>
 917		/// Draws a simple brown material fullscreen. Testing bug report #7482.
 918		/// </summary>
 919		[Test]
 920		public static void DrawSimpleBrownMaterial()
 921		{
 922			Material2DColored background = new Material2DColored(Color.Brown);
 923
 924			Application.Start(delegate
 925			{
 926				background.Draw(Rectangle.One);
 927			});
 928		}
 929		#endregion
 930
 931		#region ResizeWindowAndDrawBoxAndTexture
 932		/// <summary>
 933		/// Helper unit test to fix bug #4472: Different resolution doesn't work
 934		/// with materials, can even happenin some cases that the resolution in the
 935		/// settings file is "reset". Materials are drawn at the wrong positition,
 936		/// DrawManager based drawings works correctly. Tested with a resolution of
 937		/// 640 * 960 pixels, but happens at any resolution.
 938		/// </summary>
 939		[Test]
 940		public static void ResizeWindowAndDrawBoxAndTexture()
 941		{
 942			Material2DColored mat = new Material2DColored("DeltaEngineLogo");
 943			
 944			// Note: This is the only way to resize now :)
 945			Application.Window.Resize(640, 960);
 946
 947			// Restore the old size again when closing!
 948			Application.ApplicationClosing += delegate
 949			{
 950				Application.Window.Resize(1024, 768);
 951			};
 952
 953			Rectangle drawArea = Rectangle.FromCenter(Point.Half, mat.Size);
 954
 955			// This will resize the already created window to fix the first part of
 956			// the problem. Then we also have to fix the graphics device, which might
 957			// also be created already, which actually caused all the render bugs!
 958			Application.Start(delegate
 959			{
 960				Font.DrawTopLeftInformation(
 961				  "Resolution=" + Settings.Resolution + "\n" +
 962				  "Window=" + Application.Window.ViewportPixelWidth + ", " +
 963				  Application.Window.ViewportPixelHeight);
 964				Line.Draw(Point.Zero, drawArea.Position, Color.Red);
 965				mat.Draw(drawArea);
 966			});
 967		}
 968		#endregion
 969
 970		#region DrawMultipleColoredMaterials
 971		/// <summary>
 972		/// Helper unit test to fix bug #7481: Most of the materials will be
 973		/// rendered wrong if many different are used - maybe corrupt check for
 974		/// caching?
 975		/// </summary>
 976		[Test]
 977		public static void DrawMultipleColoredMaterials()
 978		{
 979			Material2DColored mat1 = new Material2DColored("DeltaEngineLogo");
 980			Material2DColored mat2 = new Material2DColored("DeltaIcon");
 981			Material2DColored mat3 = new Material2DColored("ImageAnimation01");
 982			Material2DColored mat4 = new Material2DColored("ImageAnimation02");
 983			Material2DColored mat5 = new Material2DColored("ImageAnimation03");
 984			Material2DColored mat6 = new Material2DColored("ImageAnimation02");
 985			Material2DColored mat7 = new Material2DColored("ImageAnimation03");
 986			Material2DColored mat8 = new Material2DColored("ImageAnimation01");
 987			Material2DColored mat9 = new Material2DColored("ImageAnimation03");
 988
 989			Application.Start(delegate
 990			{
 991				Font.DrawTopLeftInformation(
 992					"Resolution=" + Settings.Resolution);
 993				Line.Draw(Point.Zero, Point.One, Color.Red);
 994				mat1.Draw(new Rectangle(0.3f, 0.3f, 0.1f, 0.1f));
 995				mat2.Draw(new Rectangle(0.4f, 0.3f, 0.1f, 0.1f));
 996				mat3.Draw(new Rectangle(0.5f, 0.3f, 0.1f, 0.1f));
 997				mat4.Draw(new Rectangle(0.3f, 0.4f, 0.1f, 0.1f));
 998				mat5.Draw(new Rectangle(0.4f, 0.4f, 0.1f, 0.1f));
 999				mat6.Draw(new Rectangle(0.5f, 0.4f, 0.1f, 0.1f));
1000				mat7.Draw(new Rectangle(0.3f, 0.5f, 0.1f, 0.1f));
1001				mat8.Draw(new Rectangle(0.4f, 0.5f, 0.1f, 0.1f));
1002				mat9.Draw(new Rectangle(0.5f, 0.5f, 0.1f, 0.1f));
1003			});
1004
1005			/*this part of the test only works with ZooMumbaMobile test content!
1006			Material2DColored mat1 = new Material2DColored("AnimalTileBlue");
1007			Material2DColored mat2 = new Material2DColored("AnimalTileCyan");
1008			Material2DColored mat3 = new Material2DColored("AnimalTileGreen");
1009			Material2DColored mat4 = new Material2DColored("AnimalTileRed");
1010			Material2DColored mat5 = new Material2DColored("AnimalTileYellow");
1011			Material2DColored mat6 = new Material2DColored("IconChimpanze");
1012			Material2DColored mat7 = new Material2DColored("IconDove");
1013			Material2DColored mat8 = new Material2DColored("IconElephant");
1014			Material2DColored mat9 = new Material2DColored("IconFlamingo");
1015			Material2DColored mat10 = mat1;// new Material2DColored("AnimalTileBlue");
1016			Material2DColored mat11 = mat2;// new Material2DColored("AnimalTileCyan");
1017			Material2DColored mat12 = mat2;// new Material2DColored("AnimalTileCyan");
1018			Material2DColored mat13 = mat2;// new Material2DColored("AnimalTileBlue");
1019			Material2DColored mat14 = mat1;// new Material2DColored("AnimalTileBlue");
1020			Material2DColored mat15 = mat2;// new Material2DColored("AnimalTileYellow");
1021
1022			Application.Start(delegate
1023			{
1024				//Font.DrawTopLeftInformation(
1025				//	"Resolution=" + Settings.Resolution);
1026				//Line.Draw(Point.Zero, Point.One, Color.Red);
1027				mat1.Draw(new Rectangle(0.3f, 0.3f, 0.1f, 0.1f));
1028				if (Time.Milliseconds > 500)
1029				mat2.Draw(new Rectangle(0.4f, 0.3f, 0.1f, 0.1f));
1030				if (Time.Milliseconds > 1000)
1031				mat3.Draw(new Rectangle(0.5f, 0.3f, 0.1f, 0.1f));
1032				if (Time.Milliseconds > 1500)
1033				mat4.Draw(new Rectangle(0.3f, 0.4f, 0.1f, 0.1f));
1034				if (Time.Milliseconds > 2000)
1035				mat5.Draw(new Rectangle(0.4f, 0.4f, 0.1f, 0.1f));
1036				if (Time.Milliseconds > 2500)
1037				mat6.Draw(new Rectangle(0.5f, 0.4f, 0.1f, 0.1f));
1038				if (Time.Milliseconds > 3000)
1039				mat7.Draw(new Rectangle(0.3f, 0.5f, 0.1f, 0.1f));
1040				if (Time.Milliseconds > 3500)
1041				mat8.Draw(new Rectangle(0.4f, 0.5f, 0.1f, 0.1f));
1042				if (Time.Milliseconds > 4000)
1043					mat9.Draw(new Rectangle(0.5f, 0.5f, 0.1f, 0.1f));
1044				if (Time.Milliseconds > 4000)
1045					mat10.Draw(new Rectangle(0.6f, 0.5f, 0.1f, 0.1f));
1046				if (Time.Milliseconds > 4000)
1047					mat11.Draw(new Rectangle(0.3f, 0.6f, 0.1f, 0.1f));
1048				if (Time.Milliseconds > 4000)
1049					mat12.Draw(new Rectangle(0.4f, 0.6f, 0.1f, 0.1f));
1050				if (Time.Milliseconds > 4000)
1051					mat13.Draw(new Rectangle(0.5f, 0.6f, 0.1f, 0.1f));
1052				if (Time.Milliseconds > 4000)
1053					mat14.Draw(new Rectangle(0.6f, 0.6f, 0.1f, 0.1f));
1054				if (Time.Milliseconds > 4000)
1055					mat15.Draw(new Rectangle(0.3f, 0.7f, 0.1f, 0.1f));
1056			});
1057			 */
1058		}
1059		#endregion
1060
1061		#region DrawMaterial3D
1062		/// <summary>
1063		/// Draw a material in 3d by using the geometry class.
1064		/// </summary>
1065		[Test]
1066		public static void DrawMaterial3D()
1067		{
1068			LookAtCamera cam = new LookAtCamera(new Vector(1f, -5f, 3f));
1069			Material material = new Material("DeltaEngineLogo",
1070				Shader.Create("TexturedShader3D"));
1071
1072			GeometryData data = GeometryData.CreatePlane(
1073				VertexFormat.Position3DTextured, 20f, 5f);
1074			Geometry geometry = Geometry.Create(data);
1075
1076			Application.Start(delegate
1077			{
1078				Grid.Draw();
1079
1080				material.Draw(geometry);
1081			});
1082		}
1083		#endregion
1084
1085		#region DrawBillboard3D
1086		/// <summary>
1087		/// Draw billboard 3D
1088		/// </summary>
1089		[Test]
1090		public static void DrawBillboard3D()
1091		{
1092			LookAtCamera cam = new LookAtCamera(new Vector(1, -5, 3));
1093			// Note: Texture may not look like a particle, but it is good for 
1094			// checking billboard orientation.
1095			MaterialColored billboard = new MaterialColored("DeltaEngineLogo");
1096
1097			Size size = new Size(2f, 2f);
1098			float r = 0f;
1099			Application.Start(delegate
1100			{
1101				// Draw a Grid
1102				Grid.Draw();
1103
1104				// Draw Billboards unrotated in different modes and rotated
1105				// in different modes
1106				for (int index = 0; index < 2; index++)
1107				{
1108					r += Time.CheckEvery(0.03f)
1109					     	? 0.5f
1110					     	: 0f;
1111					r = (r > 360f)
1112					    	? (r - 360f)
1113					    	: r;
1114
1115					float z = index == 0
1116					          	? -1f
1117					          	: 1f;
1118					float rotation = index == 0
1119					                 	? 0f
1120					                 	: r;
1121
1122					billboard.billboardMode = BillboardMode.CameraFacingPrecise;
1123					BillboardManager.Instance.Draw(billboard, new Vector(-4f, 0f, z),
1124						size, rotation);
1125					billboard.billboardMode = BillboardMode.UpAxis;
1126					BillboardManager.Instance.Draw(billboard, new Vector(-2f, 0f, z),
1127						size, rotation);
1128					billboard.billboardMode = BillboardMode.FrontAxis;
1129					BillboardManager.Instance.Draw(billboard, new Vector(0f, 0f, z),
1130						size, rotation);
1131					billboard.billboardMode = BillboardMode.Ground;
1132					BillboardManager.Instance.Draw(billboard, new Vector(4f, 0f, z),
1133						size, rotation);
1134				}
1135			});
1136		}
1137		#endregion
1138
1139		#region CreateTextureDynamically
1140		/// <summary>
1141		/// Unit test that shows how to create a texture dynamically from rgb data.
1142		/// </summary>
1143		[Test]
1144		public static void CreateTextureDynamically()
1145		{
1146			// Define a 8x8 texture with some colors.
1147			Color[] textureColors = new[]
1148			{
1149				Color.Red, Color.Green, Color.Yellow, Color.Blue,
1150				Color.Black, Color.White, Color.Brown, Color.Orange,
1151				Color.Green, Color.Yellow, Color.Blue, Color.Black,
1152				Color.White, Color.Brown, Color.Orange, Color.Red,
1153				Color.Yellow, Color.Blue, Color.Black, Color.White,
1154				Color.Brown, Color.Orange, Color.Red, Color.Green,
1155				Color.Blue, Color.Black, Color.White, Color.Brown,
1156				Color.Orange, Color.Red, Color.Green, Color.Yellow,
1157				Color.Black, Color.White, Color.Brown, Color.Orange,
1158				Color.Red, Color.Green, Color.Yellow, Color.Blue,
1159				Color.White, Color.Brown, Color.Orange, Color.Red,
1160				Color.Green, Color.Yellow, Color.Blue, Color.Black,
1161				Color.Brown, Color.Orange, Color.Red, Color.Green,
1162				Color.Yellow, Color.Blue, Color.Black, Color.White,
1163				Color.Orange, Color.Red, Color.Green, Color.Yellow,
1164				Color.Blue, Color.Black, Color.White, Color.Brown,
1165			};
1166			// Convert the colors to rgb data and create texture out of it plus
1167			// pass it into a material for rendering.
1168			Material2D dynamicMaterial = new Material2D(Texture.Create(
1169				Texture.ConvertColorToRgb(textureColors), new Size(8, 8),
1170				BlendMode.Opaque, false));
1171
1172			Application.Start(delegate
1173			{
1174				dynamicMaterial.Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f));
1175			});
1176		}
1177		#endregion
1178
1179		#region CreateTextureDynamicallyWithAlpha
1180		/// <summary>
1181		/// Unit test that shows how to create a texture dynamically from RGBA
1182		/// data.
1183		/// </summary>
1184		[Test]
1185		public static void CreateTextureDynamicallyWithAlpha()
1186		{
1187			// We will use partially transparent Black and Green.
1188			Color transparentBlack = new Color(Color.Black, 0.5f);
1189			Color transparentGreen = new Color(Color.Green, 0.2f);
1190
1191			// Define a 8x8 texture with some colors.
1192			Color[] textureColors = new[]
1193			{
1194				Color.Unused, transparentGreen, Color.Yellow, Color.Blue,
1195				transparentBlack, Color.White, Color.Brown, Color.Orange,
1196				transparentGreen, Color.Yellow, Color.Blue, transparentBlack,
1197				Color.White, Color.Brown, Color.Orange, Color.Red,
1198				Color.Yellow, Color.Blue, transparentBlack, Color.White,
1199				Color.Brown, Color.Orange, Color.Red, transparentGreen,
1200				Color.Blue, transparentBlack, Color.White, Color.Brown,
1201				Color.Orange, Color.Red, transparentGreen, Color.Yellow,
1202				transparentBlack, Color.White, Color.Brown, Color.Orange,
1203				Color.Red, transparentGreen, Color.Yellow, Color.Blue,
1204				Color.White, Color.Brown, Color.Orange, Color.Red,
1205				transparentGreen, Color.Yellow, Color.Blue, transparentBlack,
1206				Color.Brown, Color.Orange, Color.Red, transparentGreen,
1207				Color.Yellow, Color.Blue, transparentBlack, Color.White,
1208				Color.Orange, Color.Red, transparentGreen, Color.Yellow,
1209				Color.Blue, transparentBlack, Color.White, Color.Brown,
1210			};
1211			// Convert the colors to RGBA data and create texture out of it plus
1212			// pass it into a material for rendering.
1213			Material2D dynamicMaterial = new Material2D(Texture.Create(
1214				Texture.ConvertColorToRgba(textureColors), new Size(8, 8),
1215				BlendMode.Translucency, false, true));
1216
1217			Application.Start(delegate
1218			{
1219				dynamicMaterial.Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f));
1220
1221				Font.DrawTopLeftInformation(
1222					"Click to change background color to see alpha a bit better");
1223
1224				// Clicking changes the background color
1225				if (Input.Mouse.LeftButtonReleased)
1226				{
1227					Application.BackgroundColor = Color.Random;
1228				}
1229			});
1230		}
1231		#endregion
1232
1233		#region DrawLineOnTexture
1234		/// <summary>
1235		/// Draw line onto render to texture
1236		/// </summary>
1237		[Test]
1238		public static void DrawLineOnTexture()
1239		{
1240			RenderToTexture renderToTexture = RenderToTexture.Create(
1241				new Size(256, 256), false, false);
1242			Material2D mat = new Material2D(renderToTexture);
1243
1244			Application.Start(delegate
1245			{
1246				// Render line into texture.
1247				renderToTexture.Render(delegate
1248				{
1249					// Line from top left up to bottom right in quadratic space
1250					Line.Draw(new Point(0, 0), new Point(1, 1), Color.Red);
1251					Line.Draw(new Point(0, 0.3f), new Point(1, 0.3f), Color.Red);
1252
1253					// Also draw a default material.
1254					//Material2D.Default.Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f));
1255					DrawManager.Instance.Run();
1256					//MaterialManager.Instance.Run();
1257				});
1258
1259				// Also draw line and material in normal mode.
1260				//Line.Draw(new Point(0, 0), new Point(1, 1), Color.Green);
1261				//Material2D.Default.Draw(new Rectangle(0.7f, 0.3f, 0.1f, 0.1f));
1262
1263				// Show rendered texture with our material.
1264				mat.Draw(new Rectangle(0.2f, 0.3f, 0.5f, 0.5f));
1265			});
1266		}
1267		#endregion
1268
1269		#region MaskTexture
1270		/// <summary>
1271		/// Draws a mask into a stencilbuffer hiding parts of a texture
1272		/// </summary>
1273		[Test]
1274		public static void MaskTexture()
1275		{
1276			Application.BackgroundColor = Color.Red;
1277			RenderToTexture renderToTextureWithStencil = RenderToTexture.Create(
1278				new Size(256, 256), false, false, true);
1279			Material2D stencilMask = new Material2D(renderToTextureWithStencil);
1280
1281			Application.Start(delegate
1282			{
1283				// Render line into texture.
1284				renderToTextureWithStencil.Render(delegate
1285				{
1286					// Draw a circle mask in the center
1287					Circle.DrawFilled(new Point(0.5f, 0.5f), 0.3f, Color.Black);
1288					DrawManager.Instance.Run();
1289				});
1290
1291				// Show masked texture with our stencilMask material.
1292				stencilMask.Draw(new Rectangle(0.2f, 0.3f, 0.5f, 0.5f));
1293			});
1294		}
1295		#endregion
1296
1297		#region TakeScreenshot
1298		/// <summary>
1299		/// Test the screenshot capturer.
1300		/// </summary>
1301		[Test]
1302		public static void TakeScreenshot()
1303		{
1304			Application.Start(delegate
1305			{
1306				// Draw dummy image
1307				Material2D.Default.Draw(new Rectangle(0, 0, 0.5f, 0.5f));
1308
1309				// And some text
1310				Font.Default.Draw(
1311					"Click Left to take a screenshot!\n" +
1312					"The app will then close and open the image automatically.",
1313					Rectangle.FromCenter(Point.Half, Size.Half));
1314
1315				// Capture when clicking.
1316				if (Input.Mouse.LeftButtonReleased)
1317				{
1318					string screenshotPath = DrawManager.MakeScreenshot();
1319
1320					// Also quit the application and show the screenshot we just made.
1321					Application.Quit();
1322					Process.Start(screenshotPath);
1323				}
1324			});
1325		}
1326		#endregion
1327
1328	}
1329}