The Little Vector Library is a .NET library for software rendered vector graphics. The API implements a subset of the System.Drawing and adds a few extra ones. It does not depend on any operating system libraries such as GDI+, or the equivalent on IOS or Android.
It is useful for writing applications that need to run on multiple devices and being sure that the graphics will work and be the same on each device.
So if you are writing your software in C#, Visual Basic .NET or another .NET language you can use this library to draw vector graphics.
LittleVectorLibrary.dll
The Little Vector Library can take as it's input a byte array which represents all the pixels of your canvas in ARGB format. You can call functions on the pixels to draw shapes. Then you get back a byte array to do with as you wish. For example, you might draw those pixels to the screen or send them to a texture.
Examples
This is a C# example which draws a green ellipse with a black outline.
using LVL;
class Main{
void foo(){
Bitmap bitmap = new Bitmap(400, 300);
Graphics graphics = Graphics.FromImage(bitmap);
Pen pen = new Pen(Color.Black, 5);
Brush brush = new SolidBrush(Color.Green);
Brush brush = new SolidBrush(Color.Green);
graphics.FillEllipse(brush, 50, 50, 200, 100);
graphics.DrawEllipse(pen, 50, 50, 200, 100);
byte[] bytes = bitmap.GetBytes();
//do something with the bytes here
}
};
Unity 3D
In Unity3D for example you might want to send the bytes to a texture. In Unity 4.5 and above you can use the function: LoadRawTextureData(byte[] bytes) to send the bytes to a texture which may be on a solid shape or on an image component for example.
There are some helper functions included to make using the library with Unity easier, such as the DrawableTexture class:
void foo(){
DrawableTexture dtexture = new DrawableTexture(256, 256);
//now set the material to have your texture
myGameObject.renderer.material.mainTexture = dtexture.texture;
//draw your shapes
//now set the material to have your texture
myGameObject.renderer.material.mainTexture = dtexture.texture;
//draw your shapes
Graphics graphics = dtexture.graphics;
Pen pen = new Pen(Color.Black, 5);
Brush brush = new SolidBrush(Color.Green);
Brush brush = new SolidBrush(Color.Green);
graphics.FillEllipse(brush, 50, 50, 200, 100);
graphics.DrawEllipse(pen, 50, 50, 200, 100);
//apply the graphics to the texture
//apply the graphics to the texture
dtexture.Apply();
}
Or use it with new new Unity 4.6 GUI Image component:
public UnityEngine.UI.Image image;
void foo(){
DrawableTexture dtexture = new DrawableTexture(800, 600);
//now set the sprite of the image component
image.sprite = Sprite.Create( dtexture.texture,
new Rect(0, 0, dtexture.getWidth(), dtexture.getHeight()) , Vector2.zero);
//draw your shapes
//now set the sprite of the image component
image.sprite = Sprite.Create( dtexture.texture,
new Rect(0, 0, dtexture.getWidth(), dtexture.getHeight()) , Vector2.zero);
//draw your shapes
Graphics graphics = dtexture.graphics;
Pen pen = new Pen(Color.Black, 5);
Brush brush = new SolidBrush(Color.Green);
Brush brush = new SolidBrush(Color.Green);
graphics.FillEllipse(brush, 50, 50, 200, 100);
graphics.DrawEllipse(pen, 50, 50, 200, 100);
//apply the graphics to the texture
//apply the graphics to the texture
dtexture.Apply();
}
More examples for different game engines to come!