Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using D2D = Microsoft.WindowsAPICodePack.DirectX.Direct2D1;
- using System;
- using Microsoft.WindowsAPICodePack.DirectX.Graphics;
- namespace Example
- {
- internal sealed class MyScene : Direct2D.Scene
- {
- private D2D.SolidColorBrush redBrush;
- D2D.D2DBitmap m_atlasBitmap;
- int m_tileSize = 32;
- protected override void OnCreateResources()
- {
- this.redBrush = this.RenderTarget.CreateSolidColorBrush(new D2D.ColorF(1, 0, 0));
- m_atlasBitmap = this.RenderTarget.CreateBitmap(new D2D.SizeU((uint)m_tileSize, (uint)m_tileSize),
- new D2D.BitmapProperties(new D2D.PixelFormat(Format.B8G8R8A8UNorm, D2D.AlphaMode.Ignore), 96, 96));
- }
- protected override void OnFreeResources()
- {
- if (this.redBrush != null)
- {
- this.redBrush.Dispose();
- this.redBrush = null;
- }
- if (m_atlasBitmap != null)
- {
- m_atlasBitmap.Dispose();
- m_atlasBitmap = null;
- }
- }
- protected override void OnRender()
- {
- this.RenderTarget.BeginDraw();
- // clear to green
- this.RenderTarget.Clear(new D2D.ColorF(0, 1, 0, 1));
- int columns = (int)Math.Ceiling(this.RenderTarget.Size.Width / m_tileSize);
- int rows = (int)Math.Ceiling(this.RenderTarget.Size.Height / m_tileSize);
- for (int y = 0; y < rows; y++)
- {
- for (int x = 0; x < columns; x++)
- {
- var rect = new D2D.RectF(x * m_tileSize, y * m_tileSize, x * m_tileSize + m_tileSize, y * m_tileSize + m_tileSize);
- // draw red tile
- this.RenderTarget.FillRectangle(rect, redBrush);
- // draw black bitmap tile
- this.RenderTarget.DrawBitmap(m_atlasBitmap, 1.0f, D2D.BitmapInterpolationMode.Linear, rect,
- new D2D.RectF(0, 0, m_tileSize, m_tileSize));
- }
- }
- this.RenderTarget.EndDraw();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement