CUGL
Cornell University Game Library
|
#include <CUSpriteBatch.h>
Public Member Functions | |
SpriteBatch () | |
~SpriteBatch () | |
void | dispose () |
bool | init () |
bool | init (std::shared_ptr< SpriteShader > shader) |
bool | init (unsigned int capacity) |
bool | init (unsigned int capacity, std::shared_ptr< SpriteShader > shader) |
bool | isReady () const |
bool | isDrawing () const |
unsigned int | getVerticesDrawn () const |
unsigned int | getCallsMade () const |
void | setShader (const std::shared_ptr< SpriteShader > &shader) |
const std::shared_ptr< SpriteShader > & | getShader () const |
void | setColor (Color4 color) |
Color4 | getColor () const |
void | setTexture (const std::shared_ptr< Texture > &texture) |
const std::shared_ptr< Texture > & | getTexture () const |
void | setPerspective (const Mat4 &perspective) |
const Mat4 & | getPerspective () const |
void | setBlendFunc (GLenum srcFactor, GLenum dstFactor) |
GLenum | getSourceBlendFactor () const |
GLenum | getDestinationBlendFactor () const |
void | setBlendEquation (GLenum equation) |
GLenum | getBlendEquation () const |
void | begin () |
void | begin (const Mat4 &perspective) |
void | end () |
void | flush () |
void | fill (const Rect &rect) |
void | fill (const Rect &rect, const Vec2 &origin, const Vec2 &scale, float angle, const Vec2 &offset) |
void | fill (const Rect &rect, const Vec2 &origin, const Mat4 &transform) |
void | fill (const Rect &rect, const Vec2 &origin, const Affine2 &transform) |
void | fill (const Poly2 &poly) |
void | fill (const Poly2 &poly, const Vec2 &offset) |
void | fill (const Poly2 &poly, const Vec2 &origin, const Vec2 &scale, float angle, const Vec2 &offset) |
void | fill (const Poly2 &poly, const Vec2 &origin, const Mat4 &transform) |
void | fill (const Poly2 &poly, const Vec2 &origin, const Affine2 &transform) |
void | fill (const std::vector< Vertex2 > &vertices, const std::vector< unsigned short > &indices, const Mat4 &transform, bool tint=true) |
void | fill (const std::vector< Vertex2 > &vertices, const std::vector< unsigned short > &indices, const Affine2 &transform, bool tint=true) |
void | fill (const Vertex2 *vertices, unsigned int vsize, unsigned int voffset, const unsigned short *indices, unsigned int isize, unsigned int ioffset, const Mat4 &transform, bool tint=true) |
void | fill (const Vertex2 *vertices, unsigned int vsize, unsigned int voffset, const unsigned short *indices, unsigned int isize, unsigned int ioffset, const Affine2 &transform, bool tint=true) |
void | outline (const Rect &rect) |
void | outline (const Rect &rect, const Vec2 &origin, const Vec2 &scale, float angle, const Vec2 &offset) |
void | outline (const Rect &rect, const Vec2 &origin, const Mat4 &transform) |
void | outline (const Rect &rect, const Vec2 &origin, const Affine2 &transform) |
void | outline (const Poly2 &poly) |
void | outline (const Poly2 &poly, const Vec2 &offset) |
void | outline (const Poly2 &poly, const Vec2 &origin, const Vec2 &scale, float angle, const Vec2 &offset) |
void | outline (const Poly2 &poly, const Vec2 &origin, const Mat4 &transform) |
void | outline (const Poly2 &poly, const Vec2 &origin, const Affine2 &transform) |
void | outline (const std::vector< Vertex2 > &vertices, const std::vector< unsigned short > &indices, const Mat4 &transform, bool tint=true) |
void | outline (const std::vector< Vertex2 > &vertices, const std::vector< unsigned short > &indices, const Affine2 &transform, bool tint=true) |
void | outline (const Vertex2 *vertices, unsigned int vsize, unsigned int voffset, const unsigned short *indices, unsigned int isize, unsigned int ioffset, const Mat4 &transform, bool tint=true) |
void | outline (const Vertex2 *vertices, unsigned int vsize, unsigned int voffset, const unsigned short *indices, unsigned int isize, unsigned int ioffset, const Affine2 &transform, bool tint=true) |
void | draw (const std::shared_ptr< Texture > &texture, const Vec2 &position) |
void | draw (const std::shared_ptr< Texture > &texture, Color4 color, const Vec2 &position) |
void | draw (const std::shared_ptr< Texture > &texture, const Rect &bounds) |
void | draw (const std::shared_ptr< Texture > &texture, Color4 color, const Rect &bounds) |
void | draw (const std::shared_ptr< Texture > &texture, const Vec2 &origin, const Vec2 &scale, float angle, const Vec2 &offset) |
void | draw (const std::shared_ptr< Texture > &texture, Color4 color, const Vec2 &origin, const Vec2 &scale, float angle, const Vec2 &offset) |
void | draw (const std::shared_ptr< Texture > &texture, const Rect &bounds, const Vec2 &origin, const Vec2 &scale, float angle, const Vec2 &offset) |
void | draw (const std::shared_ptr< Texture > &texture, Color4 color, const Rect &bounds, const Vec2 &origin, const Vec2 &scale, float angle, const Vec2 &offset) |
void | draw (const std::shared_ptr< Texture > &texture, const Vec2 &origin, const Mat4 &transform) |
void | draw (const std::shared_ptr< Texture > &texture, Color4 color, const Vec2 &origin, const Mat4 &transform) |
void | draw (const std::shared_ptr< Texture > &texture, const Rect &bounds, const Vec2 &origin, const Mat4 &transform) |
void | draw (const std::shared_ptr< Texture > &texture, Color4 color, const Rect &bounds, const Vec2 &origin, const Mat4 &transform) |
void | draw (const std::shared_ptr< Texture > &texture, const Vec2 &origin, const Affine2 &transform) |
void | draw (const std::shared_ptr< Texture > &texture, Color4 color, const Vec2 &origin, const Affine2 &transform) |
void | draw (const std::shared_ptr< Texture > &texture, const Rect &bounds, const Vec2 &origin, const Affine2 &transform) |
void | draw (const std::shared_ptr< Texture > &texture, Color4 color, const Rect &bounds, const Vec2 &origin, const Affine2 &transform) |
void | draw (const std::shared_ptr< Texture > &texture, const Poly2 &poly, const Vec2 &offset) |
void | draw (const std::shared_ptr< Texture > &texture, Color4 color, const Poly2 &poly, const Vec2 &offset) |
void | draw (const std::shared_ptr< Texture > &texture, const Poly2 &poly, const Vec2 &origin, const Vec2 &scale, float angle, const Vec2 &offset) |
void | draw (const std::shared_ptr< Texture > &texture, Color4 color, const Poly2 &poly, const Vec2 &origin, const Vec2 &scale, float angle, const Vec2 &offset) |
void | draw (const std::shared_ptr< Texture > &texture, const Poly2 &poly, const Vec2 &origin, const Mat4 &transform) |
void | draw (const std::shared_ptr< Texture > &texture, Color4 color, const Poly2 &poly, const Vec2 &origin, const Mat4 &transform) |
void | draw (const std::shared_ptr< Texture > &texture, const Poly2 &poly, const Vec2 &origin, const Affine2 &transform) |
void | draw (const std::shared_ptr< Texture > &texture, Color4 color, const Poly2 &poly, const Vec2 &origin, const Affine2 &transform) |
Static Public Member Functions | |
static std::shared_ptr< SpriteBatch > | alloc () |
static std::shared_ptr< SpriteBatch > | alloc (unsigned int capacity) |
static const std::shared_ptr< Texture > & | getBlankTexture () |
This class is a sprite batch for drawing 2d graphics.
A sprite batch gathers together sprites and draws them as a single mesh whenever possible. Changing the active texture requires that the sprite batch flush the mesh. Hence, using a single texture atlas can significantly improve drawing speed.
This is sprite batch is different from a classic sprite batch in that it can draw both solid shapes and outlines. Outlines use the same texturing rules that solids do.
In addition, this sprite batch is capable of drawing without an active texture. In that case, the shape will be drawn with a solid color.
cugl::SpriteBatch::SpriteBatch | ( | ) |
Creates a degenerate sprite batch with no buffers.
You must initialize the buffer before using it.
|
inline |
Deletes the sprite batch, disposing all resources
|
inlinestatic |
Returns a new sprite batch with the default vertex capacity.
The default vertex capacity is 8192 vertices and 8192*3 = 24576 indices. If the mesh exceeds these values, the sprite batch will flush before before continuing to draw. If you wish to increase (or decrease) the capacity, use the alternate initializer.
The sprite batch begins with the default blank texture, and color white. The perspective matrix is the identity.
|
inlinestatic |
Returns a new sprite batch with the given vertex capacity.
The index capacity will be 3 times the vertex capacity. The maximum number of possible indices is the maximum size_t, so the vertex size must be a third that.
If the mesh exceeds the capacity, the sprite batch will flush before before continuing to draw. You should tune your system to have the appropriate capacity. To small a capacity will cause the system to thrash. However, too large a capacity could stall on memory transfers.
The sprite batch begins with the default blank texture, and color white. The perspective matrix is the identity.
void cugl::SpriteBatch::begin | ( | ) |
Starts drawing with the current perspective matrix.
This call will disable depth buffer writing. It enables blending and texturing. You must call end() to complete drawing.
Calling this method will reset the vertex and OpenGL call counters to 0.
|
inline |
Starts drawing with the given perspective matrix.
This call will disable depth buffer writing. It enables blending and texturing. You must call end() to complete drawing.
Calling this method will reset the vertex and OpenGL call counters to 0.
perspective | The perspective matrix to draw with. |
void cugl::SpriteBatch::dispose | ( | ) |
Deletes the vertex buffers and resets all attributes.
You must reinitialize the sprite batch to use it.
Draws the texture (without tint) at the given position
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws a rectangle of the size of the texture, with bottom left corner at the given position.
texture | The new active texture |
position | The bottom left corner of the texture |
void cugl::SpriteBatch::draw | ( | const std::shared_ptr< Texture > & | texture, |
Color4 | color, | ||
const Vec2 & | position | ||
) |
Draws the tinted texture at the given position
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws a rectangle of the size of the texture, with bottom left corner at the given position.
texture | The new active texture |
color | The new active color |
position | The bottom left corner of the texture |
|
inline |
Draws the texture (without tint) inside the given bounds
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the specified rectangle filled with the texture.
texture | The new active texture |
bounds | The rectangle to texture |
|
inline |
Draws the tinted texture at the given position
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the specified rectangle filled with the texture.
texture | The new active texture |
color | The new active color |
bounds | The rectangle to texture |
void cugl::SpriteBatch::draw | ( | const std::shared_ptr< Texture > & | texture, |
const Vec2 & | origin, | ||
const Vec2 & | scale, | ||
float | angle, | ||
const Vec2 & | offset | ||
) |
Draws the texture (without tint) transformed by the given parameters
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws a texture-sized rectangle centered at the given origin, and transformed by the given parameters.
The rectangle will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified in texture pixel coordinates (e.g from the bottom) left corner).
texture | The new active texture |
origin | The rotation origin |
scale | The amount to scale the texture |
angle | The amount to rotate the texture |
offset | The texture origin offset |
void cugl::SpriteBatch::draw | ( | const std::shared_ptr< Texture > & | texture, |
Color4 | color, | ||
const Vec2 & | origin, | ||
const Vec2 & | scale, | ||
float | angle, | ||
const Vec2 & | offset | ||
) |
Draws the tinted texture transformed by the given parameters
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws a texture-sized rectangle centered at the given origin, and transformed by the given parameters.
The rectangle will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified in texture pixel coordinates (e.g from the bottom) left corner).
texture | The new active texture |
color | The new active color |
origin | The rotation origin |
scale | The amount to scale the texture |
angle | The amount to rotate the texture |
offset | The texture origin offset |
|
inline |
Draws the texture (without tint) transformed by the given parameters
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the rectangle centered at the given origin, and transformed by the given parameters.
The rectangle will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified in world coordinates (not relative to the rectangle). A rectangle should be centered on the origin to rotate properly.
texture | The new active texture |
bounds | The rectangle to texture |
origin | The rotation origin |
scale | The amount to scale the texture |
angle | The amount to rotate the texture |
offset | The texture origin offset |
|
inline |
Draws the tinted texture transformed by the given parameters
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the rectangle centered at the given origin, and transformed by the given parameters.
The rectangle will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified in world coordinates (not relative to the rectangle). A rectangle should be centered on the origin to rotate properly.
texture | The new active texture |
color | The new active color |
bounds | The rectangle to texture |
origin | The rotation origin |
scale | The amount to scale the texture |
angle | The amount to rotate the texture |
offset | The texture origin offset |
void cugl::SpriteBatch::draw | ( | const std::shared_ptr< Texture > & | texture, |
const Vec2 & | origin, | ||
const Mat4 & | transform | ||
) |
Draws the texture (without tint) transformed by the matrix
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws a texture-sized rectangle centered at the given origin, and transformed by the given matrix.
The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the rectangle bounds).
texture | The new active texture |
origin | The coordinate origin |
transform | The coordinate transform |
void cugl::SpriteBatch::draw | ( | const std::shared_ptr< Texture > & | texture, |
Color4 | color, | ||
const Vec2 & | origin, | ||
const Mat4 & | transform | ||
) |
Draws the tinted texture transformed by the matrix
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws a texture-sized rectangle centered at the given origin, and transformed by the given matrix.
The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the rectangle bounds).
texture | The new active texture |
color | The new active color |
origin | The coordinate origin |
transform | The coordinate transform |
|
inline |
Draws the texture (without tint) transformed by the matrix
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the rectangle centered at the given origin, and transformed by the given matrix.
The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the rectangle bounds).
texture | The new active texture |
bounds | The rectangle to texture |
origin | The coordinate origin |
transform | The coordinate transform |
|
inline |
Draws the tinted texture transformed by the matrix
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the rectangle centered at the given origin, and transformed by the given matrix.
The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the rectangle bounds).
texture | The new active texture |
color | The new active color |
bounds | The rectangle to texture |
origin | The coordinate origin |
transform | The coordinate transform |
void cugl::SpriteBatch::draw | ( | const std::shared_ptr< Texture > & | texture, |
const Vec2 & | origin, | ||
const Affine2 & | transform | ||
) |
Draws the texture (without tint) transformed by the affine matrix
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws a texture-sized rectangle centered at the given origin, and transformed by the given affine matrix.
The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the rectangle bounds).
texture | The new active texture |
origin | The coordinate origin |
transform | The coordinate transform |
void cugl::SpriteBatch::draw | ( | const std::shared_ptr< Texture > & | texture, |
Color4 | color, | ||
const Vec2 & | origin, | ||
const Affine2 & | transform | ||
) |
Draws the tinted texture transformed by the affine matrix
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws a texture-sized rectangle centered at the given origin, and transformed by the given affine matrix.
The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the rectangle bounds).
texture | The new active texture |
color | The new active color |
origin | The coordinate origin |
transform | The coordinate transform |
|
inline |
Draws the texture (without tint) transformed by the affine matrix
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the rectangle centered at the given origin, and transformed by the given affine matrix.
The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the rectangle bounds).
texture | The new active texture |
bounds | The rectangle to texture |
origin | The coordinate origin |
transform | The coordinate transform |
|
inline |
Draws the tinted texture transformed by the affine matrix
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the rectangle centered at the given origin, and transformed by the given affine matrix.
The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the rectangle bounds).
texture | The new active texture |
color | The new active color |
bounds | The rectangle to texture |
origin | The coordinate origin |
transform | The coordinate transform |
|
inline |
Draws the textured polygon (without tint) at the given position
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the polygon, offset by the given value.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
texture | The new active texture |
poly | The polygon to texture |
offset | The polygon offset |
|
inline |
Draws the tinted, textured polygon at the given position
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the polygon, offset by the given value.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
texture | The new active texture |
color | The new active color |
poly | The polygon to texture |
offset | The polygon offset |
|
inline |
Draws the textured polygon (without tint) transformed by the given parameters
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the polygon, translated by the given parameters.
The polygon will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified in world coordinates (not relative to the rectangle) a rectangle should be centered on the origin to rotate properly.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
texture | The new active texture |
poly | The polygon to texture |
origin | The rotation origin |
scale | The amount to scale the polygon |
angle | The amount to rotate the polygon |
offset | The polygon offset |
|
inline |
Draws the tinted, textured polygon transformed by the given parameters
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the polygon, translated by the given parameters.
The polygon will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified in world coordinates (not relative to the rectangle) a rectangle should be centered on the origin to rotate properly.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
texture | The new active texture |
color | The new active color |
poly | The polygon to texture |
origin | The rotation origin |
scale | The amount to scale the polygon |
angle | The amount to rotate the polygon |
offset | The polygon offset |
|
inline |
Draws the textured polygon (without tint) transformed by the given matrix
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the polygon, translated by the given matrix.
The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the polygon bounds).
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
texture | The new active texture |
poly | The polygon to texture |
origin | The coordinate origin |
transform | The coordinate transform |
|
inline |
Draws the tinted, textured polygon transformed by the given matrix
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the polygon, translated by the given matrix.
The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the polygon bounds).
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
texture | The new active texture |
color | The new active color |
poly | The polygon to texture |
origin | The coordinate origin |
transform | The coordinate transform |
|
inline |
Draws the textured polygon (without tint) transformed by the given affine matrix
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the polygon, translated by the given affine matrix.
The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the polygon bounds).
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
texture | The new active texture |
poly | The polygon to texture |
origin | The coordinate origin |
transform | The coordinate transform |
|
inline |
Draws the tinted, textured polygon transformed by the given affine matrix
This is a convenience method that calls the appropriate fill method. It sets both the texture and color (removing the previous active values). It then draws the polygon, translated by the given affine matrix.
The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the polygon bounds).
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
texture | The new active texture |
color | The new active color |
poly | The polygon to texture |
origin | The coordinate origin |
transform | The coordinate transform |
void cugl::SpriteBatch::end | ( | ) |
Completes the drawing pass for this sprite batch, flushing the buffer.
This method enables depth writes and disables blending and texturing. It Must always be called after a call to begin().
void cugl::SpriteBatch::fill | ( | const Rect & | rect | ) |
Draws the given rectangle filled with the current color and texture.
The texture will fill the entire rectangle with texture coordinate (0,1) at the bottom left corner identified by rect,origin. To draw only part of a texture, use a subtexture to fill the rectangle with the region [minS,maxS]x[min,maxT]. Alternatively, you can use a Poly2 for more fine-tuned control.
rect | The rectangle to draw |
void cugl::SpriteBatch::fill | ( | const Rect & | rect, |
const Vec2 & | origin, | ||
const Vec2 & | scale, | ||
float | angle, | ||
const Vec2 & | offset | ||
) |
Draws the given rectangle filled with the current color and texture.
The rectangle will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified in world coordinates (not relative to the rectangle). A rectangle should be centered on the origin to rotate properly.
The texture will fill the entire rectangle before being transformed. Texture coordinate (0,1) will at the bottom left corner identified by rect,origin. To draw only part of a texture, use a subtexture to fill the rectangle with the region [minS,maxS]x[min,maxT]. Alternatively, you can use a Poly2 for more fine-tuned control.
rect | The rectangle to draw |
origin | The rotation origin |
scale | The amount to scale the rectangle |
angle | The amount to rotate the rectangle |
offset | The rectangle offset |
Draws the given rectangle filled with the current color and texture.
The rectangle will transformed by the given matrix. The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the rectangle bounds).
The texture will fill the entire rectangle with texture coordinate (0,1) at the bottom left corner identified by rect,origin. To draw only part of a texture, use a subtexture to fill the rectangle with the region [minS,maxS]x[min,maxT]. Alternatively, you can use a { Poly2} for more fine-tuned control.
rect | The rectangle to draw |
origin | The coordinate origin |
transform | The coordinate transform |
Draws the given rectangle filled with the current color and texture.
The rectangle will transformed by the given matrix. The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the rectangle bounds).
The texture will fill the entire rectangle with texture coordinate (0,1) at the bottom left corner identified by rect,origin. To draw only part of a texture, use a subtexture to fill the rectangle with the region [minS,maxS]x[min,maxT]. Alternatively, you can use a { Poly2} for more fine-tuned control.
rect | The rectangle to draw |
origin | The coordinate origin |
transform | The coordinate transform |
void cugl::SpriteBatch::fill | ( | const Poly2 & | poly | ) |
Draws the given polygon filled with the current color and texture.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
poly | The polygon to draw |
Draws the given polygon filled with the current color and texture.
The polygon will be offset by the given position.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
poly | The polygon to draw |
offset | The polygon offset |
void cugl::SpriteBatch::fill | ( | const Poly2 & | poly, |
const Vec2 & | origin, | ||
const Vec2 & | scale, | ||
float | angle, | ||
const Vec2 & | offset | ||
) |
Draws the given polygon filled with the current color and texture.
The polygon will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified in world coordinates (not relative to the rectangle) a rectangle should be centered on the origin to rotate properly.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
poly | The polygon to draw |
origin | The rotation origin |
scale | The amount to scale the polygon |
angle | The amount to rotate the polygon |
offset | The polygon offset |
Draws the given polygon filled with the current color and texture.
The polygon will transformed by the given matrix. The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the polygon bounds).
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
poly | The polygon to draw |
origin | The coordinate origin |
transform | The coordinate transform |
Draws the given polygon filled with the current color and texture.
The polygon will transformed by the given matrix. The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the polygon bounds).
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated (by one of the triangulation factories SimpleTriangulator or ComplexTriangulator, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
poly | The polygon to draw |
origin | The coordinate origin |
transform | The coordinate transform |
|
inline |
Fills the triangulated vertices with the current texture.
This method provides more fine tuned control over texture coordinates that the other fill methods. The texture no longer needs to be drawn uniformly over the shape. The transform will be applied to the vertex positions directly in world space.
The triangulation will be determined by the given indices. If necessary, these can be generated via one of the triangulation factories SimpleTriangulator or ComplexTriangulator.
The vertices use their own color values. However, if tint is true, these values will be tinted (i.e. multiplied) by the current active color.
vertices | The list of vertices |
indices | The triangulation list |
transform | The coordinate transform |
tint | Whether to tint with the active color |
|
inline |
Fills the triangulated vertices with the current texture.
This method provides more fine tuned control over texture coordinates that the other fill methods. The texture no longer needs to be drawn uniformly over the shape. The transform will be applied to the vertex positions directly in world space.
The triangulation will be determined by the given indices. If necessary, these can be generated via one of the triangulation factories SimpleTriangulator or ComplexTriangulator.
The vertices use their own color values. However, if tint is true, these values will be tinted (i.e. multiplied) by the current active color.
vertices | The list of vertices |
indices | The triangulation list |
transform | The coordinate transform |
tint | Whether to tint with the active color |
void cugl::SpriteBatch::fill | ( | const Vertex2 * | vertices, |
unsigned int | vsize, | ||
unsigned int | voffset, | ||
const unsigned short * | indices, | ||
unsigned int | isize, | ||
unsigned int | ioffset, | ||
const Mat4 & | transform, | ||
bool | tint = true |
||
) |
Fills the triangulated vertices with the current texture.
This method provides more fine tuned control over texture coordinates that the other fill methods. The texture no longer needs to be drawn uniformly over the shape. The transform will be applied to the vertex positions directly in world space.
The triangulation will be determined by the given indices. If necessary, these can be generated via one of the triangulation factories SimpleTriangulator or ComplexTriangulator.
The vertices use their own color values. However, if tint is true, these values will be tinted (i.e. multiplied) by the current active color.
vertices | The array of vertices |
vsize | The size of the vertex array |
voffset | The first element of the vertex array |
indices | The triangulation array |
isize | The size of the index array |
ioffset | The first element of the index array |
transform | The coordinate transform |
tint | Whether to tint with the active color |
void cugl::SpriteBatch::fill | ( | const Vertex2 * | vertices, |
unsigned int | vsize, | ||
unsigned int | voffset, | ||
const unsigned short * | indices, | ||
unsigned int | isize, | ||
unsigned int | ioffset, | ||
const Affine2 & | transform, | ||
bool | tint = true |
||
) |
Fills the triangulated vertices with the current texture.
This method provides more fine tuned control over texture coordinates that the other fill methods. The texture no longer needs to be drawn uniformly over the shape. The transform will be applied to the vertex positions directly in world space.
The triangulation will be determined by the given indices. If necessary, these can be generated via one of the triangulation factories SimpleTriangulator or ComplexTriangulator.
The vertices use their own color values. However, if tint is true, these values will be tinted (i.e. multiplied) by the current active color.
vertices | The array of vertices |
vsize | The size of the vertex array |
voffset | The first element of the vertex array |
indices | The triangulation array |
isize | The size of the index array |
ioffset | The first element of the index array |
transform | The coordinate transform |
tint | Whether to tint with the active color |
void cugl::SpriteBatch::flush | ( | ) |
Flushes the current mesh without completing the drawing pass.
This method is called whenever you change any attribute other than color mid-pass. It prevents the attribute change from retoactively affecting previuosly drawn shapes.
|
static |
Returns the blank texture used to make solid shapes
This is the texture used when the active texture is nullptr. Using this texture means that all shapes and outlines will be drawn with a solid color instead.
|
inline |
Returns the blending equation for this sprite batch
By default this value is GL_FUNC_ADD. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendEquation.xhtml
|
inline |
Returns the number of OpenGL calls in the latest pass (so far).
This value will be reset to 0 whenever begin() is called.
|
inline |
Returns the active color of this sprite batch
All subsequent shapes and outlines drawn by this sprite batch will be tinted by this color. This color is white by default.
|
inline |
Returns the destination blending factor
By default this value is GL_ONE_MINUS_SRC_ALPHA. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
|
inline |
Returns the active perspective matrix of this sprite batch
The perspective matrix is the combined modelview-projection from the camera. By default, this is the identity matrix.
|
inline |
Returns the shader for this sprite batch
This value may NOT be changed during a drawing pass.
|
inline |
Returns the source blending factor
By default this value is GL_SRC_ALPHA. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
|
inline |
Returns the active texture of this sprite batch
All subsequent shapes and outlines drawn by this sprite batch will use this texture. If the value is nullptr, all shapes and outlines will be drawn with a solid color instead. This value is nullptr by default.
|
inline |
Returns the number of vertices drawn in the latest pass (so far).
This value will be reset to 0 whenever begin() is called.
bool cugl::SpriteBatch::init | ( | ) |
Initializes a sprite batch with the default vertex capacity.
The default vertex capacity is 8192 vertices and 8192*3 = 24576 indices. If the mesh exceeds these values, the sprite batch will flush before before continuing to draw. If you wish to increase (or decrease) the capacity, use the alternate initializer.
The sprite batch begins with the default blank texture, and color white. The perspective matrix is the identity.
|
inline |
Initializes a sprite batch with the default vertex capacity and given shader
The default vertex capacity is 8192 vertices and 8192*3 = 24576 indices. If the mesh exceeds these values, the sprite batch will flush before before continuing to draw. If you wish to increase (or decrease) the capacity, use the alternate initializer.
The sprite batch begins with the default blank texture, and color white. The perspective matrix is the identity.
bool cugl::SpriteBatch::init | ( | unsigned int | capacity | ) |
Initializes a sprite batch with the given vertex capacity.
The index capacity will be 3 times the vertex capacity. The maximum number of possible indices is the maximum size_t, so the vertex size must be a third that.
If the mesh exceeds the capacity, the sprite batch will flush before before continuing to draw. You should tune your system to have the appropriate capacity. To small a capacity will cause the system to thrash. However, too large a capacity could stall on memory transfers.
The sprite batch begins with the default blank texture, and color white. The perspective matrix is the identity.
bool cugl::SpriteBatch::init | ( | unsigned int | capacity, |
std::shared_ptr< SpriteShader > | shader | ||
) |
Initializes a sprite batch with the given vertex capacity and shader
The index capacity will be 3 times the vertex capacity. The maximum number of possible indices is the maximum size_t, so the vertex size must be a third that.
If the mesh exceeds the capacity, the sprite batch will flush before before continuing to draw. You should tune your system to have the appropriate capacity. To small a capacity will cause the system to thrash. However, too large a capacity could stall on memory transfers.
The sprite batch begins with the default blank texture, and color white. The perspective matrix is the identity.
|
inline |
|
inline |
Returns true if this sprite batch has been initialized and is ready for use.
void cugl::SpriteBatch::outline | ( | const Rect & | rect | ) |
Outlines the given rectangle with the current color and texture.
The drawing will be a wireframe of a rectangle. The wireframe will be textured with Texture coordinate (0,1) at the bottom left corner identified by rect,origin. The remaining edges will correspond to the edges of the texture. To draw only part of a texture, use a subtexture to outline the edges with [minS,maxS]x[min,maxT]. Alternatively, you can use a Poly2 for more fine-tuned control.
rect | The rectangle to outline |
void cugl::SpriteBatch::outline | ( | const Rect & | rect, |
const Vec2 & | origin, | ||
const Vec2 & | scale, | ||
float | angle, | ||
const Vec2 & | offset | ||
) |
Outlines the given rectangle with the current color and texture.
The rectangle will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified in world coordinates (not relative to the rectangle) a rectangle should be centered on the origin to rotate properly.
The drawing will be a wireframe of a rectangle. The wireframe will be textured with Texture coordinate (0,1) at the bottom left corner identified by rect,origin. The remaining edges will correspond to the edges of the texture. To draw only part of a texture, use a subtexture to outline the edges with [minS,maxS]x[min,maxT]. Alternatively, you can use a Poly2 for more fine-tuned control.
rect | The rectangle to outline |
origin | The rotation origin |
scale | The amount to scale the rectangle |
angle | The amount to rotate the rectangle |
offset | The rectangle offset |
Outlines the given rectangle with the current color and texture.
The rectangle will transformed by the given matrix. The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the rectangle bounds).
The drawing will be a wireframe of a rectangle. The wireframe will be textured with Texture coordinate (0,1) at the bottom left corner identified by rect,origin. The remaining edges will correspond to the edges of the texture. To draw only part of a texture, use a subtexture to outline the edges with [minS,maxS]x[min,maxT]. Alternatively, you can use a Poly2 for more fine-tuned control.
rect | The rectangle to outline |
origin | The coordinate origin |
transform | The coordinate transform |
void cugl::SpriteBatch::outline | ( | const Rect & | rect, |
const Vec2 & | origin, | ||
const Affine2 & | transform | ||
) |
Outlines the given rectangle with the current color and texture.
The rectangle will transformed by the given matrix. The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the rectangle bounds).
The drawing will be a wireframe of a rectangle. The wireframe will be textured with Texture coordinate (0,1) at the bottom left corner identified by rect,origin. The remaining edges will correspond to the edges of the texture. To draw only part of a texture, use a subtexture to outline the edges with [minS,maxS]x[min,maxT]. Alternatively, you can use a Poly2 for more fine-tuned control.
rect | The rectangle to outline |
origin | The coordinate origin |
transform | The coordinate transform |
void cugl::SpriteBatch::outline | ( | const Poly2 & | poly | ) |
Outlines the given polygon with the current color and texture.
The polygon path will be determined by the indices in poly. The indices should be a multiple of two, preferably generated by the factories PathOutliner or CubicSplineApproximator.
The drawing will be a wireframe of a polygon, but the lines are textured. The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply outlines the rectangle.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
poly | The polygon to outline |
Outlines the given polygon with the current color and texture.
The polygon will be offset by the given position.
The polygon path will be determined by the indices in poly. The indices should be a multiple of two, preferably generated by the factories PathOutliner or CubicSplineApproximator.
The drawing will be a wireframe of a polygon, but the lines are textured. The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply outlines the rectangle.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
poly | The polygon to outline |
offset | The polygon offset |
void cugl::SpriteBatch::outline | ( | const Poly2 & | poly, |
const Vec2 & | origin, | ||
const Vec2 & | scale, | ||
float | angle, | ||
const Vec2 & | offset | ||
) |
Outlines the given polygon with the current color and texture.
The polygon will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified in world coordinates (not relative to the rectangle) a rectangle should be centered on the origin to rotate properly.
The polygon path will be determined by the indices in poly. The indices should be a multiple of two, preferably generated by the factories PathOutliner or CubicSplineApproximator.
The drawing will be a wireframe of a polygon, but the lines are textured. The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply outlines the rectangle.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
poly | The polygon to outline |
origin | The rotation origin |
scale | The amount to scale the polygon |
angle | The amount to rotate the polygon |
offset | The polygon offset |
Outlines the given polygon with the current color and texture.
The polygon will transformed by the given matrix. The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the polygon bounds).
The polygon path will be determined by the indices in poly. The indices should be a multiple of two, preferably generated by the factories PathOutliner or CubicSplineApproximator.
The drawing will be a wireframe of a polygon, but the lines are textured. The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply outlines the rectangle.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
poly | The polygon to outline |
origin | The coordinate origin |
transform | The coordinate transform |
void cugl::SpriteBatch::outline | ( | const Poly2 & | poly, |
const Vec2 & | origin, | ||
const Affine2 & | transform | ||
) |
Outlines the given polygon with the current color and texture.
The polygon will transformed by the given matrix. The transform will be applied assuming the given origin, which is specified in world world coordinates (but which should ideally be inside the polygon bounds).
The polygon path will be determined by the indices in poly. The indices should be a multiple of two, preferably generated by the factories PathOutliner or CubicSplineApproximator.
The drawing will be a wireframe of a polygon, but the lines are textured. The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply outlines the rectangle.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
poly | The polygon to outline |
origin | The coordinate origin |
transform | The coordinate transform |
|
inline |
Outlines the vertex path with the current texture.
This method provides more fine tuned control over texture coordinates that the other outline methods. The texture no longer needs to be drawn uniformly over the wireframe. The transform will be applied to the vertex positions directly in world space.
The vertex path will be determined by the provided indices. The indices should be a multiple of two, preferably generated by the factories PathOutliner or CubicSplineApproximator.
The vertices use their own color values. However, if tint is true, these values will be tinted (i.e. multiplied) by the current active color.
vertices | The list of vertices |
indices | The triangulation list |
transform | The coordinate transform |
tint | Whether to tint with the active color |
|
inline |
Outlines the vertex path with the current texture.
This method provides more fine tuned control over texture coordinates that the other outline methods. The texture no longer needs to be drawn uniformly over the wireframe. The transform will be applied to the vertex positions directly in world space.
The vertex path will be determined by the provided indices. The indices should be a multiple of two, preferably generated by the factories PathOutliner or CubicSplineApproximator.
The vertices use their own color values. However, if tint is true, these values will be tinted (i.e. multiplied) by the current active color.
vertices | The list of vertices |
indices | The triangulation list |
transform | The coordinate transform |
tint | Whether to tint with the active color |
void cugl::SpriteBatch::outline | ( | const Vertex2 * | vertices, |
unsigned int | vsize, | ||
unsigned int | voffset, | ||
const unsigned short * | indices, | ||
unsigned int | isize, | ||
unsigned int | ioffset, | ||
const Mat4 & | transform, | ||
bool | tint = true |
||
) |
Outlines the vertex path with the current texture.
This method provides more fine tuned control over texture coordinates that the other outline methods. The texture no longer needs to be drawn uniformly over the wireframe. The transform will be applied to the vertex positions directly in world space.
The vertex path will be determined by the provided indices. The indices should be a multiple of two, preferably generated by the factories PathOutliner or CubicSplineApproximator.
The vertices use their own color values. However, if tint is true, these values will be tinted (i.e. multiplied) by the current active color.
vertices | The array of vertices |
vsize | The size of the vertex array |
voffset | The first element of the vertex array |
indices | The triangulation array |
isize | The size of the index array |
ioffset | The first element of the index array |
transform | The coordinate transform |
tint | Whether to tint with the active color |
void cugl::SpriteBatch::outline | ( | const Vertex2 * | vertices, |
unsigned int | vsize, | ||
unsigned int | voffset, | ||
const unsigned short * | indices, | ||
unsigned int | isize, | ||
unsigned int | ioffset, | ||
const Affine2 & | transform, | ||
bool | tint = true |
||
) |
Outlines the vertex path with the current texture.
This method provides more fine tuned control over texture coordinates that the other outline methods. The texture no longer needs to be drawn uniformly over the wireframe. The transform will be applied to the vertex positions directly in world space.
The vertex path will be determined by the provided indices. The indices should be a multiple of two, preferably generated by the factories PathOutliner or CubicSplineApproximator.
The vertices use their own color values. However, if tint is true, these values will be tinted (i.e. multiplied) by the current active color.
vertices | The array of vertices |
vsize | The size of the vertex array |
voffset | The first element of the vertex array |
indices | The triangulation array |
isize | The size of the index array |
ioffset | The first element of the index array |
transform | The coordinate transform |
tint | Whether to tint with the active color |
void cugl::SpriteBatch::setBlendEquation | ( | GLenum | equation | ) |
Sets the blending equation for this sprite batch
The enum must be a standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendEquation.xhtml
However, this setter does not do any error checking to verify that the input is valid. By default, the equation is GL_FUNC_ADD.
Changing this value will cause the sprite batch to flush.
equation | Specifies how source and destination colors are combined |
void cugl::SpriteBatch::setBlendFunc | ( | GLenum | srcFactor, |
GLenum | dstFactor | ||
) |
Sets the blending function for this sprite batch
The enums are the standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
However, this setter does not do any error checking to verify that the enums are valid. By default, srcFactor is GL_SRC_ALPHA while dstFactor is GL_ONE_MINUS_SRC_ALPHA. This corresponds to non-premultiplied alpha blending.
Changing this value will cause the sprite batch to flush.
srcFactor | Specifies how the source blending factors are computed |
dstFactor | Specifies how the destination blending factors are computed. |
|
inline |
Sets the active color of this sprite batch
All subsequent shapes and outlines drawn by this sprite batch will be tinted by this color. This color is white by default.
Changing this value will not cause the sprite batch to flush.
color | The active color for this sprite batch |
void cugl::SpriteBatch::setPerspective | ( | const Mat4 & | perspective | ) |
Sets the active perspective matrix of this sprite batch
The perspective matrix is the combined modelview-projection from the camera. By default, this is the identity matrix. Changing this value will cause the sprite batch to flush.
perspective | The active perspective matrix for this sprite batch |
void cugl::SpriteBatch::setShader | ( | const std::shared_ptr< SpriteShader > & | shader | ) |
Sets the shader for this sprite batch
This value may NOT be changed during a drawing pass.
shader | The active color for this sprite batch |
void cugl::SpriteBatch::setTexture | ( | const std::shared_ptr< Texture > & | texture | ) |
Sets the active texture of this sprite batch
All subsequent shapes and outlines drawn by this sprite batch will use this texture. If the value is nullptr, all shapes and outlines will be draw with a solid color instead. This value is nullptr by default.
Changing this value will cause the sprite batch to flush. However, a subtexture will not cause a pipeline flush. This is an important argument for using texture atlases.
texture | The active texture for this sprite batch |