示例#1
0
        private Pixmap.Layer RenderToTexture(int width, int height, Action <Canvas> renderMethod)
        {
            Pixmap.Layer pixelData;

            using (Texture texture = new Texture(width, height, Texture.SizeMode.NonPowerOfTwo))
                using (RenderTarget renderTarget = new RenderTarget(AAQuality.Off, texture))
                    using (DrawDevice device = new DrawDevice())
                    {
                        device.Perspective    = PerspectiveMode.Flat;
                        device.VisibilityMask = VisibilityFlag.AllGroups | VisibilityFlag.ScreenOverlay;
                        device.RenderMode     = RenderMatrix.OrthoScreen;
                        device.Target         = renderTarget;
                        device.ViewportRect   = new Rect(renderTarget.Width, renderTarget.Height);

                        device.BeginRendering(ClearFlag.All, ColorRgba.TransparentBlack, 1.0f);
                        {
                            Canvas canvas = new Canvas(device);
                            renderMethod(canvas);
                        }
                        device.EndRendering();

                        RenderTarget.Bind(RenderTarget.None);

                        pixelData = texture.RetrievePixelData();
                    }

            return(pixelData);
        }
示例#2
0
		private Pixmap.Layer RenderToTexture(int width, int height, Action<Canvas> renderMethod)
		{
			Pixmap.Layer pixelData;

			using (Texture texture = new Texture(width, height, Texture.SizeMode.NonPowerOfTwo))
			using (RenderTarget renderTarget = new RenderTarget(AAQuality.Off, texture))
			using (DrawDevice device = new DrawDevice())
			{
				device.Perspective = PerspectiveMode.Flat;
				device.VisibilityMask = VisibilityFlag.AllGroups | VisibilityFlag.ScreenOverlay;
				device.RenderMode = RenderMatrix.OrthoScreen;
				device.Target = renderTarget;
				device.ViewportRect = new Rect(renderTarget.Width, renderTarget.Height);

				device.BeginRendering(ClearFlag.All, ColorRgba.TransparentBlack, 1.0f);
				{
					Canvas canvas = new Canvas(device);
					renderMethod(canvas);
				}
				device.EndRendering();
				
				RenderTarget.Bind(RenderTarget.None);

				pixelData = texture.RetrievePixelData();
			}

			return pixelData;
		}