Table of Contents

Class RenderContext

Namespace
Myra.Graphics2D
Assembly
Myra.dll

Provides rendering context for drawing 2D graphics including shapes, text, and textured regions.

public class RenderContext : IDisposable
Inheritance
RenderContext
Implements
Inherited Members

Constructors

RenderContext()

Initializes a new instance of the RenderContext class.

public RenderContext()

Properties

Opacity

Gets or sets the opacity (alpha) value for rendering, ranging from 0.0 (fully transparent) to 1.0 (fully opaque).

public float Opacity { get; set; }

Property Value

float

Scissor

Gets or sets the scissor rectangle for clipping rendered output.

public Rectangle Scissor { get; set; }

Property Value

Rectangle

Methods

AddOpacity(float)

Applies opacity

public void AddOpacity(float opacity)

Parameters

opacity float

Begin()

Begins rendering.

public void Begin()

Dispose()

Disposes resources used by the RenderContext.

public void Dispose()

Draw(Texture2D, Rectangle, Color)

Draws a texture

public void Draw(Texture2D texture, Rectangle destinationRectangle, Color color)

Parameters

texture Texture2D
destinationRectangle Rectangle
color Color

Draw(Texture2D, Rectangle, Rectangle?, Color)

Draws a texture

public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color)

Parameters

texture Texture2D
destinationRectangle Rectangle
sourceRectangle Rectangle?
color Color

Draw(Texture2D, Rectangle, Rectangle?, Color, float)

Draws a texture

public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation)

Parameters

texture Texture2D
destinationRectangle Rectangle
sourceRectangle Rectangle?
color Color
rotation float

Draw(Texture2D, Rectangle, Rectangle?, Color, float, float)

Draws a texture

public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, float depth = 0)

Parameters

texture Texture2D
destinationRectangle Rectangle
sourceRectangle Rectangle?
color Color
rotation float
depth float

Draw(Texture2D, Vector2, Color)

Draws a texture

public void Draw(Texture2D texture, Vector2 position, Color color)

Parameters

texture Texture2D
position Vector2
color Color

Draw(Texture2D, Vector2, Color, Vector2, float)

Draws a texture

public void Draw(Texture2D texture, Vector2 pos, Color color, Vector2 scale, float rotation = 0)

Parameters

texture Texture2D
pos Vector2
color Color
scale Vector2
rotation float

Draw(Texture2D, Vector2, Rectangle?, Color)

Draws a texture

public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color)

Parameters

texture Texture2D
position Vector2
sourceRectangle Rectangle?
color Color

Draw(Texture2D, Vector2, Rectangle?, Color, float)

Draws a texture

public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation)

Parameters

texture Texture2D
position Vector2
sourceRectangle Rectangle?
color Color
rotation float

Draw(Texture2D, Vector2, Rectangle?, Color, float, Vector2, float)

Draws a texture

public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 scale, float depth = 0)

Parameters

texture Texture2D
position Vector2
sourceRectangle Rectangle?
color Color
rotation float
scale Vector2
depth float

DrawArc(Vector2, float, int, Color, float, float, float)

Draw an Arc

public void DrawArc(Vector2 center, float radius, int sides, Color color, float startAngle, float endAngle, float thickness = 1)

Parameters

center Vector2

The center of the Arc

radius float

The radius of the Arc

sides int

The number of sides to generate

color Color

The color of the Arc

startAngle float

The start angle of the line in radians

endAngle float

The end angle of the line in radians

thickness float

The thickness of the lines used

DrawArc(float, float, float, int, Color, float, float, float)

Draw a Arc

public void DrawArc(float x, float y, float radius, int sides, Color color, float startAngle, float endAngle, float thickness = 1)

Parameters

x float

The center X of the Arc

y float

The center Y of the Arc

radius float

The radius of the Arc

sides int

The number of sides to generate

color Color

The color of the Arc

startAngle float

The start angle of the line in radians

endAngle float

The end angle of the line in radians

thickness float

The thickness of the line

DrawCircle(Vector2, float, int, Color, float)

Draw a circle

public void DrawCircle(Vector2 center, float radius, int sides, Color color, float thickness = 1)

Parameters

center Vector2

The center of the circle

radius float

The radius of the circle

sides int

The number of sides to generate

color Color

The color of the circle

thickness float

The thickness of the lines used

DrawCircle(float, float, float, int, Color, float)

Draw a circle

public void DrawCircle(float x, float y, float radius, int sides, Color color, float thickness = 1)

Parameters

x float

The center X of the circle

y float

The center Y of the circle

radius float

The radius of the circle

sides int

The number of sides to generate

color Color

The color of the circle

thickness float

The thickness of the line

DrawLine(Vector2, Vector2, Color, float)

Draws a line from point1 to point2 with an offset

public void DrawLine(Vector2 point1, Vector2 point2, Color color, float thickness = 1)

Parameters

point1 Vector2

The first point

point2 Vector2

The second point

color Color

The color to use

thickness float

The thickness of the line

DrawLine(Vector2, float, float, Color, float)

Draws a line from point1 to point2 with an offset

public void DrawLine(Vector2 point, float length, float angle, Color color, float thickness = 1)

Parameters

point Vector2

The starting point

length float

The length of the line

angle float

The angle of this line from the starting point

color Color

The color to use

thickness float

The thickness of the line

DrawLine(float, float, float, float, Color, float)

Draws a line from point1 to point2 with an offset

public void DrawLine(float x1, float y1, float x2, float y2, Color color, float thickness = 1)

Parameters

x1 float

The X coord of the first point

y1 float

The Y coord of the first point

x2 float

The X coord of the second point

y2 float

The Y coord of the second point

color Color

The color to use

thickness float

The thickness of the line

DrawPoint(Vector2, Color, float)

Draws a point at the specified position. The center of the point will be at the position.

public void DrawPoint(Vector2 position, Color color, float size = 1)

Parameters

position Vector2
color Color
size float

DrawPoint(float, float, Color, float)

Draws a point at the specified x, y position. The center of the point will be at the position.

public void DrawPoint(float x, float y, Color color, float size = 1)

Parameters

x float
y float
color Color
size float

DrawPolygon(Vector2, Vector2[], Color, float)

Draws a closed polygon from an array of points

public void DrawPolygon(Vector2 offset, Vector2[] points, Color color, float thickness = 1)

Parameters

offset Vector2

Where to offset the points

points Vector2[]

The points to connect with lines

color Color

The color to use

thickness float

The thickness of the lines

DrawRectangle(Rectangle, Color, float)

Draws a rectangle with the thickness provided

public void DrawRectangle(Rectangle rectangle, Color color, float thickness = 1)

Parameters

rectangle Rectangle

The rectangle to draw

color Color

The color to draw the rectangle in

thickness float

The thickness of the lines

DrawRectangle(Vector2, Vector2, Color, float)

Draws a rectangle with the thickness provided

public void DrawRectangle(Vector2 location, Vector2 size, Color color, float thickness = 1)

Parameters

location Vector2

Where to draw

size Vector2

The size of the rectangle

color Color

The color to draw the rectangle in

thickness float

The thickness of the line

DrawRichText(RichTextLayout, Vector2, Color, Vector2?, float, float, TextHorizontalAlignment)

Draws a rich text

public void DrawRichText(RichTextLayout richText, Vector2 position, Color color, Vector2? sourceScale = null, float rotation = 0, float layerDepth = 0, TextHorizontalAlignment horizontalAlignment = TextHorizontalAlignment.Left)

Parameters

richText RichTextLayout

The text which will be drawn.

position Vector2

The drawing location on screen.

color Color

A color mask.

sourceScale Vector2?

A scaling of this text.

rotation float

A rotation of this text in radians.

layerDepth float

A depth of the layer of this string.

horizontalAlignment TextHorizontalAlignment

The horizontal alignment of the text.

DrawString(SpriteFontBase, string, Vector2, Color, Vector2, float)

Draws a text

public void DrawString(SpriteFontBase font, string text, Vector2 position, Color color, Vector2 scale, float layerDepth = 0)

Parameters

font SpriteFontBase

The font to use for drawing.

text string

The text which will be drawn.

position Vector2

The drawing location on screen.

color Color

A color mask.

scale Vector2

A scaling of this text.

layerDepth float

A depth of the layer of this string.

DrawString(SpriteFontBase, string, Vector2, Color, Vector2, float, float)

Draws a text

public void DrawString(SpriteFontBase font, string text, Vector2 position, Color color, Vector2 scale, float rotation, float layerDepth = 0)

Parameters

font SpriteFontBase

The font to use for drawing.

text string

The text which will be drawn.

position Vector2

The drawing location on screen.

color Color

A color mask.

scale Vector2

A scaling of this text.

rotation float

A rotation of this text in radians.

layerDepth float

A depth of the layer of this string.

DrawString(SpriteFontBase, string, Vector2, Color, float)

Draws a text

public void DrawString(SpriteFontBase font, string text, Vector2 position, Color color, float layerDepth = 0)

Parameters

font SpriteFontBase

The font to use for drawing.

text string

The text which will be drawn.

position Vector2

The drawing location on screen.

color Color

A color mask.

layerDepth float

A depth of the layer of this string.

End()

Ends rendering.

public void End()

FillRectangle(Rectangle, Color)

Draws a filled rectangle

public void FillRectangle(Rectangle rectangle, Color color)

Parameters

rectangle Rectangle

The rectangle to draw

color Color

The color to draw the rectangle in

FillRectangle(Vector2, Vector2, Color)

Draws a filled rectangle

public void FillRectangle(Vector2 location, Vector2 size, Color color)

Parameters

location Vector2

Where to draw

size Vector2

The size of the rectangle

color Color

The color to draw the rectangle in

FillRectangle(float, float, float, float, Color)

Draws a filled rectangle

public void FillRectangle(float x, float y, float width, float height, Color color)

Parameters

x float

The X coord of the left side

y float

The Y coord of the upper side

width float

Width

height float

Height

color Color

The color to draw the rectangle in

~RenderContext()

Finalizer that releases unmanaged resources.

protected ~RenderContext()

Flush()

Flushes pending render operations.

public void Flush()

SetAnisotropicFilteringMode(bool)

Sets whether anisotropic filtering mode is enabled.

public void SetAnisotropicFilteringMode(bool isAnisotropicFiltering)

Parameters

isAnisotropicFiltering bool

True to enable anisotropic filtering; false to disable.