Some basic drawing functionalities (2D/3D). More...
Classes | |
class | ArrowParams |
Arrow parameters passed to DrawArrow. More... | |
struct | Vertex |
The vertex type used by DrawHelpers (V4F_C4F) More... | |
Public Member Functions | |
DrawHelpers (GraphicsContextAlpha gl, uint max_vertices) | |
void | Dispose () |
Dispose implementation. | |
void | ImmBegin (DrawMode mode, uint max_vertices_intended) |
Start a new immediate primitive. | |
void | ImmVertex (Vertex v) |
Add a vertex to current primitive. | |
void | ImmVertex (Vector4 pos) |
Add a vertex to current primitive, using the most recent color set by SetColor(). | |
void | ImmVertex (Vector2 pos) |
Add a vertex to current primitive, using the most recent color set by SetColor(). | |
void | ImmEnd () |
Finish current primitive (this function triggers the actual draw call). | |
void | ShaderPush () |
ShaderPush() reads current MVP matrix and sets the current shader. | |
void | ShaderPop () |
"Pop" the shader. | |
void | SetColor (Vector4 value) |
Set the color to be used by the next calls to ImmVertex. | |
void | DrawBounds2Fill (Bounds2 bounds) |
Draw a filled axis aligned rectangle. | |
void | DrawBounds2 (Bounds2 bounds) |
Draw a wireframe axis aligned rectangle. | |
void | DrawConvexPoly2 (ConvexPoly2 convex_poly) |
Draw convex polygon. | |
void | DrawDisk (Vector2 center, float radius, uint n) |
Draw a filled disk. | |
void | DrawCircle (Vector2 center, float radius, uint n) |
Draw a filled circle. | |
void | DrawCoordinateSystem2D (Matrix3 mat, ArrowParams ap=null) |
Draw the coordinate system represented by a transformation matrix using arrows. | |
void | DrawCoordinateSystem2D () |
Draw a unit len arrow on x and y axis. | |
void | DrawArrow (Vector2 start_point, Vector2 end_point, ArrowParams ap) |
Draw a 2d arrow. | |
void | DrawLineSegment (Vector2 A, Vector2 B) |
Draw a single line segment. | |
void | DrawInfiniteLine (Vector2 A, Vector2 v) |
Draw a single line segment. | |
void | DrawRulers (Bounds2 bounds, float step_x, float step_y) |
Draw all the vertical and horizontal lines in a given rectangle, regularly spaced. | |
void | DrawAxis (Bounds2 clipping_bounds, float thickness) |
Draw axis lines (x=0 and y=0 lines) with a thickness. | |
void | DrawDefaultGrid (Bounds2 clipping_bounds, Vector2 step, Vector4 rulers_color, Vector4 axis_color) |
This function draws all the vertical and horizontal lines (rulers) regularly placed at multiples of 'step' distances that are inside the rectangle 'clipping_bounds'. | |
void | DrawDefaultGrid (Bounds2 clipping_bounds, float step) |
DrawDefaultGrid with a default color/blend. | |
Properties | |
bool | Disposed [get] |
Return true if this object been disposed. |
Some basic drawing functionalities (2D/3D).
This class is mostly an ImmediateMode object coupled with a debug shader. You shouldn't use DrawHelpers for anything else than visual debugging, as by nature it is not performance friendly at all.
DrawHelpers | ( | GraphicsContextAlpha | gl, |
uint | max_vertices | ||
) |
gl | The core graphics context. |
max_vertices | The maximum number of vertices you will be able to write in one frame with this DrawHelpers object. |
void DrawArrow | ( | Vector2 | start_point, |
Vector2 | end_point, | ||
ArrowParams | ap | ||
) |
Draw a 2d arrow.
This function can be wrapped by ImmBegin()/ImmEnd(), if you need to draw several arrows but want to limit the number of draw calls. Each arrow consumes at most 9 vertices.
start_point | Arrow's start point. |
end_point | Arrow's tip. |
ap | Arrow geometry parameters. |
void DrawCircle | ( | Vector2 | center, |
float | radius, | ||
uint | n | ||
) |
Draw a filled circle.
center | The center. |
radius | The radius. |
n | Tesselation. |
void DrawCoordinateSystem2D | ( | ) |
Draw a unit len arrow on x and y axis.
Color is set to vector coordinates, so the x arrow is red (1,0,0), and the y arrow is green (0,1,0).
void DrawCoordinateSystem2D | ( | Matrix3 | mat, |
ArrowParams | ap = null |
||
) |
Draw the coordinate system represented by a transformation matrix using arrows.
The x vector is represented by a red arrow, and the y vector is represented by a green arrow.
void DrawDefaultGrid | ( | Bounds2 | clipping_bounds, |
Vector2 | step, | ||
Vector4 | rulers_color, | ||
Vector4 | axis_color | ||
) |
This function draws all the vertical and horizontal lines (rulers) regularly placed at multiples of 'step' distances that are inside the rectangle 'clipping_bounds'.
It also draws the the 2 thick axis lines. All lines drawn are clipped again 'clipping_bounds'. Blend mode is untouched when drawing the rulers, then blend is disabled when drawing axis lines.
clipping_bounds | Clipping rectangle. |
step | Horizontal and vertical spacing between rulers. |
rulers_color | Color of rulers lines. |
axis_color | Color of axis lines. |
void DrawDisk | ( | Vector2 | center, |
float | radius, | ||
uint | n | ||
) |
Draw a filled disk.
center | The center. |
radius | The radius. |
n | Tesselation. |
Draw a single line segment.
This is expensive, if you draw many lines, don't use this function.
Draw a single line segment.
This is expensive, if you draw many lines, don't use this function.
void DrawRulers | ( | Bounds2 | bounds, |
float | step_x, | ||
float | step_y | ||
) |
Draw all the vertical and horizontal lines in a given rectangle, regularly spaced.
Since the smaller step_x or step_y are, the more lines primitives are generated, it is easy to overflow the immediate draw mode vertex buffer. For that reason care must be taken when setting the step values respective to the the bounds clip area.
step_x | X spacing (starts at 0). |
step_y | Y spacing (starts at 0). |
bounds | Clipping rectangle. |
void ImmBegin | ( | DrawMode | mode, |
uint | max_vertices_intended | ||
) |
Start a new immediate primitive.
mode | The draw primive type. |
max_vertices_intended | You must specify the maximum number of vertices you intend to write with ImmVertex(): the number of ImmVertex() calls following this function must be inferior or equal to 'max_vertices_intended'. |
void ImmVertex | ( | Vector2 | pos | ) |
Add a vertex to current primitive, using the most recent color set by SetColor().
(z,w) is set to (0,1).
void ShaderPop | ( | ) |
"Pop" the shader.
Number of ShaderPush() calls must match the number of ShaderPush().
void ShaderPush | ( | ) |
ShaderPush() reads current MVP matrix and sets the current shader.
For DrawHelpers we allow nesting (shader parameters get updated internally accordingly).