public async Task Render_SimpleGeometry_Ellipse() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (SolidBrushResource solidBrush = new SolidBrushResource(Color4.LightGray)) using (SolidBrushResource solidBrushBorder = new SolidBrushResource(Color4.Gray)) using (EllipseGeometryResource ellipseGeometry = new EllipseGeometryResource(new Vector2(512, 512), 400f, 300f)) using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { // Perform rendering memRenderTarget.ClearColor = Color4.CornflowerBlue; await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync((graphics) => { // 2D rendering is made here graphics.DrawGeometry(ellipseGeometry, solidBrushBorder, 3f); graphics.FillGeometry(ellipseGeometry, solidBrush); }); await memRenderTarget.AwaitRenderAsync(); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference float diff = BitmapComparison.CalculatePercentageDifference( screenshot, Properties.Resources.ReferenceImage_SimpleGeometry2D_Ellipse); Assert.True(diff < 0.2, "Difference to reference image is to big!"); } }
public async Task Render_SimpleBitmap_WithTransparency() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (SolidBrushResource solidBrush = new SolidBrushResource(Color4.LightGray)) using (StandardBitmapResource bitmap = new StandardBitmapResource(new AssemblyResourceLink(this.GetType(), "Ressources.Bitmaps.Logo.png"))) using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { // Perform rendering memRenderTarget.ClearColor = Color4.CornflowerBlue; await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync((graphics) => { // 2D rendering is made here graphics.FillRectangle(graphics.ScreenBounds, solidBrush); graphics.DrawBitmap(bitmap, new Vector2(100f, 100f)); }); //await AsyncResourceLoader.Current.WaitForAllFinishedAsync(); await memRenderTarget.AwaitRenderAsync(); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference float diff = BitmapComparison.CalculatePercentageDifference( screenshot, Properties.Resources.ReferenceImage_SimpleBitmap_Transparency); Assert.True(diff < 0.02, "Difference to reference image is to big!"); } }
public async Task Render_SimpleRoundedRect_Filled_Solid() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (SolidBrushResource solidBrush = new SolidBrushResource(Color4.Gray)) using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { // Perform rendering memRenderTarget.ClearColor = Color4.CornflowerBlue; await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync((graphics) => { // 2D rendering is made here graphics.FillRoundedRectangle( new RectangleF(10, 10, 512, 512), 30, 30, solidBrush); }); await memRenderTarget.AwaitRenderAsync(); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference float diff = BitmapComparison.CalculatePercentageDifference( screenshot, Properties.Resources.ReferenceImage_SimpleRoundedRectFilled); Assert.True(diff < 0.2, "Difference to reference image is to big!"); } }
public async Task Render_SimpleText_SimpleSingleColor() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (SolidBrushResource solidBrush = new SolidBrushResource(Color4.RedColor)) using (TextFormatResource textFormat = new TextFormatResource("Arial", 70)) using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { // Perform rendering memRenderTarget.ClearColor = Color4.CornflowerBlue; await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync((graphics) => { // 2D rendering is made here graphics.DrawText( string.Format("Just a dummy text ;){0}Just a dummy text ;)", Environment.NewLine), textFormat, new RectangleF(10, 10, 512, 512), solidBrush); }); await memRenderTarget.AwaitRenderAsync(); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference float diff = BitmapComparison.CalculatePercentageDifference( screenshot, Properties.Resources.ReferenceImage_SimpleText_SingleColor); Assert.True(diff < 0.2, "Difference to reference image is to big!"); } }
public async Task Render_SimpleRoundedRect_Filled_Over3D() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (SolidBrushResource solidBrush = new SolidBrushResource(Color4.Gray.ChangeAlphaTo(0.5f))) using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(0f, 5f, -5f); camera.Target = new Vector3(0f, 1f, 0f); camera.UpdateCamera(); // Define scene await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) => { // Define object NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>( () => new GeometryResource(new PalletStackType( NamedOrGenericKey.Empty, 10))); var newObject = manipulator.AddGeneric(geoResource); newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f); newObject.Scaling = new Vector3(2f, 2f, 2f); newObject.Color = Color4.Goldenrod; newObject.EnableShaderGeneratedBorder(); }); // Define 2D overlay await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync((graphics) => { // 2D rendering is made here graphics.FillRoundedRectangle( new RectangleF(10, 10, 512, 512), 30, 30, solidBrush); }); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference float diff = BitmapComparison.CalculatePercentageDifference( screenshot, Properties.Resources.ReferenceImage_RoundedRectOver3D); Assert.True(diff < 0.2, "Difference to reference image is to big!"); } // Finishing checks Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!"); }
public async Task MemoryRenderTarget_2DFallbackRendering() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (GraphicsCore.AutomatedTest_NewTestEnviornment()) { GraphicsCore.Initialize( enableDebug: false, force2DFallback: true); Assert.True(GraphicsCore.IsInitialized); Polygon2D polygon = new Polygon2D(new Vector2[] { new Vector2(10, 10), new Vector2(900, 100), new Vector2(800, 924), new Vector2(50, 1014), new Vector2(10, 10) }); using (SolidBrushResource solidBrush = new SolidBrushResource(Color4.LightGray)) using (SolidBrushResource solidBrushBorder = new SolidBrushResource(Color4.Gray)) using (PolygonGeometryResource polygonGeometry = new PolygonGeometryResource(polygon)) using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { // Perform rendering memRenderTarget.ClearColor = Color4.CornflowerBlue; await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync((graphics) => { // 2D rendering is made here graphics.DrawGeometry(polygonGeometry, solidBrushBorder, 3f); graphics.FillGeometry(polygonGeometry, solidBrush); }); await memRenderTarget.AwaitRenderAsync(); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference float diff = BitmapComparison.CalculatePercentageDifference( screenshot, Properties.Resources.ReferenceImage_SimpleGeometry2D); Assert.True(diff < 0.2, "Difference to reference image is to big!"); } } }
public async Task Render_SimpleBitmap_Animated() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (StandardBitmapResource bitmap = new StandardBitmapResource( new AssemblyResourceLink(this.GetType(), "Ressources.Bitmaps.Boom.png"), frameCountX: 8, frameCountY: 8)) using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { // Perform rendering memRenderTarget.ClearColor = Color4.CornflowerBlue; await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync((graphics) => { // 2D rendering is made here for (int loop = 0; loop < 8; loop++) { graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 10f), frameIndex: 7); graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 100f), frameIndex: 15); graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 200f), frameIndex: 23); graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 300f), frameIndex: 31); graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 400f), frameIndex: 39); graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 500f), frameIndex: 47); graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 600f), frameIndex: 55); graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 700f), frameIndex: 63); } }); //await AsyncResourceLoader.Current.WaitForAllFinishedAsync(); await memRenderTarget.AwaitRenderAsync(); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference float diff = BitmapComparison.CalculatePercentageDifference( screenshot, Properties.Resources.ReferenceImage_SimpleBitmap_Animated); Assert.True(diff < 0.02, "Difference to reference image is to big!"); } }
public async Task Render_SimpleRoundedRect_Filled_RadialGradient() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (RadialGradientBrushResource radialGradientBrush = new RadialGradientBrushResource( new Vector2(200f, 400f), new Vector2(0f, 0f), 200f, 400f, new GradientStop[] { new GradientStop(Color4.Gray, 0f), new GradientStop(Color4.White, 0.6f), new GradientStop(Color4.BlueColor, 1f) }, extendMode: ExtendMode.Clamp)) using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { // Perform rendering memRenderTarget.ClearColor = Color4.CornflowerBlue; await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync((graphics) => { // 2D rendering is made here graphics.FillRoundedRectangle( new RectangleF(10, 10, 900, 900), 30, 30, radialGradientBrush); }); await memRenderTarget.AwaitRenderAsync(); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); // screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference float diff = BitmapComparison.CalculatePercentageDifference( screenshot, Properties.Resources.ReferenceImage_SimpleRoundedRectFilled_RadialGradient); Assert.True(diff < 0.2, "Difference to reference image is to big!"); } }
public async Task Render_DebugLayer() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (DebugDrawingLayer debugLayer = new DebugDrawingLayer()) using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { // Perform rendering memRenderTarget.ClearColor = Color4.CornflowerBlue; await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync(debugLayer); await memRenderTarget.AwaitRenderAsync(); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference float diff = BitmapComparison.CalculatePercentageDifference( screenshot, Properties.Resources.ReferenceImage_DebugDawingLayer); Assert.True(diff < 0.2, "Difference to reference image is to big!"); } }