中文介绍Project DescriptionXNA Graphics API Library is an open source library aiming at providing 2D drawing functions with high performance and easy APIs.
Features:
1. Simple APIs.
2. Good performance.
3. Multi-thread supported.
Usage:
1. DrawingBatch
drawingBatch = new DrawingBatch(GraphicsDevice);
drawingBatch.Begin();
drawingBatch.DrawLine(10, 20, 100, 20, Color.Red);
drawingBatch.DrawRectangle(120, 10, 100, 20, Color.Blue);
drawingBatch.DrawTriangle(240, 10, 240, 60, 200, 60, Color.Black);
drawingBatch.DrawEllipse(310, 10, 50, 50, Color.Green);
drawingBatch.DrawPolyline(new Vector2[] { new Vector2(410, 10), new Vector2(440, 10), new Vector2(420, 20), new Vector2(440, 40), new Vector2(410, 60) }, Color.Aqua);
drawingBatch.DrawFilledRectangle(120, 110, 50, 0, Color.Blue);
drawingBatch.DrawFilledTriangle(240, 110, 240, 160, 200, 160, Color.Brown);
drawingBatch.DrawFilledEllipse(310, 110, 80, 40, Color.Green);
drawingBatch.End();
2. DrawingContext (based on DrawingBatch and wrapped all the functions of SpriteBatch)
drawingContext = new DrawingContext(GraphicsDevice);
spriteFont = Content.Load<SpriteFont>("SegoeUI");
texture = Content.Load<Texture2D>("Tulips");
drawingContext.Begin();
drawingContext.DrawLine(10, 20, 100, 20, Color.Red);
drawingContext.DrawRectangle(120, 10, 100, 20, Color.Blue);
drawingContext.DrawTriangle(240, 10, 240, 60, 200, 60, Color.Black);
drawingContext.DrawEllipse(310, 10, 50, 50, Color.Green);
drawingContext.DrawTexture(texture, new Vector2(10, 300), Color.White);
drawingContext.DrawPolyline(new Vector2[] { new Vector2(410, 10), new Vector2(440, 10), new Vector2(420, 20), new Vector2(440, 40), new Vector2(410, 60) }, Color.Aqua);
drawingContext.DrawFilledRectangle(120, 110, 50, 50, Color.Blue);
drawingContext.DrawFilledTriangle(240, 110, 240, 160, 200, 160, Color.Brown);
drawingContext.DrawFilledEllipse(310, 110, 80, 40, Color.Green);
drawingContext.DrawText(spriteFont, "Hello World!", new Vector2(120, 300), Color.Black);
drawingContext.End();
3. DrawingTexture
spriteFont = Content.Load<SpriteFont>("SegoeUI");
texture = Content.Load<Texture2D>("Tulips");
PresentationParameters pp = GraphicsDevice.PresentationParameters;
int bufferWidth = pp.BackBufferWidth;
int bufferHeight = pp.BackBufferHeight;
drawingTexture = new DrawingTexture(GraphicsDevice, bufferWidth, bufferHeight);
drawingTexture.Clear(Color.White);
DrawingContext drawingContext = drawingTexture.DrawingContext;
drawingContext.Begin();
drawingContext.DrawLine(10, 20, 100, 20, Color.Red);
drawingContext.DrawRectangle(120, 10, 100, 20, Color.Blue);
drawingContext.DrawTriangle(240, 10, 240, 60, 200, 60, Color.Black);
drawingContext.DrawEllipse(310, 10, 50, 50, Color.Green);
drawingContext.DrawTexture(texture, new Vector2(10, 300), Color.White);
drawingContext.DrawPolyline(new Vector2[] { new Vector2(410, 10), new Vector2(440, 10), new Vector2(420, 20), new Vector2(440, 40), new Vector2(410, 60) }, Color.Aqua);
drawingContext.DrawFilledRectangle(120, 110, 50, 50, Color.Blue);
drawingContext.DrawFilledTriangle(240, 110, 240, 160, 200, 160, Color.Brown);
drawingContext.DrawFilledEllipse(310, 110, 80, 40, Color.Green);
drawingContext.DrawText(spriteFont, "Hello World!", new Vector2(120, 300), Color.Black);
drawingContext.End();
spriteBatch.Begin();
spriteBatch.Draw(drawingTexture, Vector2.Zero, Color.White);
spriteBatch.End();
4. DrawingComponent
drawingComponent = new DrawingComponent(this);
this.Components.Add(this.drawingComponent);
drawingComponent.DrawingContext.DrawLine(0, 0, 100, 100, Color.Black);
Example screenshot:
Team Blogs