Skip to content

GraphicsAPI reference

Interface IRenderer

Namespace: MicroEngine.Graphics
Assembly: MicroEngine.Graphics2D.dll
Guide: Graphics

Immediate-mode 2D drawing in virtual pixels. Coordinates go through the camera pushed with PushCamera; with no camera they are screen space.

C#
public interface IRenderer

Extension Methods

RendererExtensions.Draw(IRenderer, Sprite, Vector2, Color?, bool), RendererExtensions.Draw(IRenderer, Texture, Vector2, Color?), RendererExtensions.DrawNineSlice(IRenderer, NineSlice, RectF, Color?), RendererExtensions.DrawPivoted(IRenderer, Sprite, Vector2, float, Vector2?, Color?, bool), RendererExtensions.DrawRect(IRenderer, RectF, Color, float), RendererExtensions.FillEllipse(IRenderer, Vector2, float, float, Color), RendererExtensions.FillGradient(IRenderer, RectF, Color, Color, int), RendererExtensions.Panel(IRenderer, RectF, PanelStyle)

Remarks

Every renderer follows the same rules. Pixel (x, y) is the square from (x, y) to (x + 1, y + 1) and its centre is (x + 0.5, y + 0.5). A rectangle or an unrotated sprite covers exactly the pixels whose centre lies inside it, a centre on its left or top edge counting as inside and one on its right or bottom edge as outside (the top-left rule of Direct3D and Vulkan): a 1 × 1 rectangle at (2.5, 2.5) covers pixel (2, 2) only. A sprite pixel shows the texel under its centre (nearest) or the bilinear mix of the four texels around it (linear, clamped at the texture’s edge). Colours are given straight (not premultiplied); the canvas stores them premultiplied (colour times alpha), so linear sampling never darkens transparent edges, and 8-bit results are rounded to nearest. Circles, lines and triangles cover their shape’s area but their edge pixels may differ between renderers.

Properties

Height

Height of the virtual canvas in pixels.

C#
int Height { get; }

Property Value

int

Width

Width of the virtual canvas in pixels.

C#
int Width { get; }

Property Value

int

Methods

Clear(Color)

Replaces every pixel of the canvas with color, alpha included, whatever the clip (SetClip) and blend mode, and replaces what was drawn before it in the frame. The clip still applies to the draws after it. The game clears to its settings’ Background colour before the scenes draw.

C#
void Clear(Color color)

Parameters

color Color

Draw(Texture, RectF, Vector2, Color, in DrawOptions)

Draws the source part of texture with its top-left at position, multiplied by tint.

C#
void Draw(Texture texture, RectF source, Vector2 position, Color tint, in DrawOptions options = default)

Parameters

texture Texture

A texture of this renderer’s graphics device, not disposed.

source RectF

The rectangle of the texture to draw, in texture pixels.

position Vector2

Where the top-left of the unrotated, scaled source lands, in virtual pixels (world pixels under a camera).

tint Color

Colour multiplier; White draws the texture unchanged.

options DrawOptions

Flip, rotation, pivot and scale.

Exceptions

ObjectDisposedException

texture was disposed; nothing is drawn.

ArgumentException

Another graphics device created texture; nothing is drawn.

DrawLine(Vector2, Vector2, float, Color)

Draws a straight line thickness pixels wide. A zero-length line draws nothing.

C#
void DrawLine(Vector2 from, Vector2 to, float thickness, Color color)

Parameters

from Vector2

to Vector2

thickness float

color Color

DrawStretched(Texture, RectF, RectF, Color)

Draws the source part of texture scaled to fill destination.

C#
void DrawStretched(Texture texture, RectF source, RectF destination, Color tint)

Parameters

texture Texture

source RectF

destination RectF

tint Color

Exceptions

ObjectDisposedException

texture was disposed; nothing is drawn.

ArgumentException

Another graphics device created texture; nothing is drawn.

FillCircle(Vector2, float, Color)

Fills a circle; radius is in pixels.

C#
void FillCircle(Vector2 center, float radius, Color color)

Parameters

center Vector2

radius float

color Color

FillRect(RectF, Color)

Fills a rectangle: the pixels whose centre lies inside it (see the rules of IRenderer). A fully transparent colour draws nothing.

C#
void FillRect(RectF rect, Color color)

Parameters

rect RectF

color Color

FillTriangle(Vector2, Vector2, Vector2, Color)

Fills a triangle.

C#
void FillTriangle(Vector2 a, Vector2 b, Vector2 c, Color color)

Parameters

a Vector2

b Vector2

c Vector2

color Color

PopCamera()

Returns to the coordinates in use before the last PushCamera.

C#
void PopCamera()

Exceptions

InvalidOperationException

No camera was pushed.

PushCamera(Camera2D)

Draws in the world coordinates of camera until PopCamera: its RenderOffset replaces the current offset (cameras do not combine). Every push needs a pop in the same frame.

C#
void PushCamera(Camera2D camera)

Parameters

camera Camera2D

SetBlendMode(BlendMode)

Sets how later draws combine with the canvas. Every frame starts with Alpha. With source colour s (after the tint), its alpha a and canvas colour d: Alpha writes s·a + d·(1 − a), Additive s·a + d, Multiply s·a·d + d·(1 − a) (the colour multiplies the canvas in proportion to its opacity), each channel clamped to 0..1.

C#
void SetBlendMode(BlendMode mode)

Parameters

mode BlendMode

SetClip(RectF?)

Restricts drawing to a screen-space rectangle (the camera does not move it); pass null to remove. X, Y, Width and Height are truncated to whole pixels. Clear ignores the clip.

C#
void SetClip(RectF? screenRect)

Parameters

screenRect RectF?