CUGL
Cornell University Game Library
Public Member Functions | Static Public Member Functions | List of all members
cugl::SpriteBatch Class Reference

#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 Mat4getPerspective () 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< SpriteBatchalloc ()
 
static std::shared_ptr< SpriteBatchalloc (unsigned int capacity)
 
static const std::shared_ptr< Texture > & getBlankTexture ()
 

Detailed Description

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.

Constructor & Destructor Documentation

cugl::SpriteBatch::SpriteBatch ( )

Creates a degenerate sprite batch with no buffers.

You must initialize the buffer before using it.

cugl::SpriteBatch::~SpriteBatch ( )
inline

Deletes the sprite batch, disposing all resources

Member Function Documentation

static std::shared_ptr<SpriteBatch> cugl::SpriteBatch::alloc ( )
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.

Returns
a new sprite batch with the default vertex capacity.
static std::shared_ptr<SpriteBatch> cugl::SpriteBatch::alloc ( unsigned int  capacity)
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.

Returns
a new sprite batch with the given vertex capacity.
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.

void cugl::SpriteBatch::begin ( const Mat4 perspective)
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.

Parameters
perspectiveThe 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.

void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
const Vec2 position 
)

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.

Parameters
textureThe new active texture
positionThe 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.

Parameters
textureThe new active texture
colorThe new active color
positionThe bottom left corner of the texture
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
const Rect bounds 
)
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.

Parameters
textureThe new active texture
boundsThe rectangle to texture
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
Color4  color,
const Rect bounds 
)
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.

Parameters
textureThe new active texture
colorThe new active color
boundsThe 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).

Parameters
textureThe new active texture
originThe rotation origin
scaleThe amount to scale the texture
angleThe amount to rotate the texture
offsetThe 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).

Parameters
textureThe new active texture
colorThe new active color
originThe rotation origin
scaleThe amount to scale the texture
angleThe amount to rotate the texture
offsetThe texture origin offset
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
const Rect bounds,
const Vec2 origin,
const Vec2 scale,
float  angle,
const Vec2 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.

Parameters
textureThe new active texture
boundsThe rectangle to texture
originThe rotation origin
scaleThe amount to scale the texture
angleThe amount to rotate the texture
offsetThe texture origin offset
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
Color4  color,
const Rect bounds,
const Vec2 origin,
const Vec2 scale,
float  angle,
const Vec2 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.

Parameters
textureThe new active texture
colorThe new active color
boundsThe rectangle to texture
originThe rotation origin
scaleThe amount to scale the texture
angleThe amount to rotate the texture
offsetThe 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).

Parameters
textureThe new active texture
originThe coordinate origin
transformThe 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).

Parameters
textureThe new active texture
colorThe new active color
originThe coordinate origin
transformThe coordinate transform
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
const Rect bounds,
const Vec2 origin,
const Mat4 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).

Parameters
textureThe new active texture
boundsThe rectangle to texture
originThe coordinate origin
transformThe coordinate transform
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
Color4  color,
const Rect bounds,
const Vec2 origin,
const Mat4 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).

Parameters
textureThe new active texture
colorThe new active color
boundsThe rectangle to texture
originThe coordinate origin
transformThe 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).

Parameters
textureThe new active texture
originThe coordinate origin
transformThe 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).

Parameters
textureThe new active texture
colorThe new active color
originThe coordinate origin
transformThe coordinate transform
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
const Rect bounds,
const Vec2 origin,
const Affine2 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).

Parameters
textureThe new active texture
boundsThe rectangle to texture
originThe coordinate origin
transformThe coordinate transform
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
Color4  color,
const Rect bounds,
const Vec2 origin,
const Affine2 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).

Parameters
textureThe new active texture
colorThe new active color
boundsThe rectangle to texture
originThe coordinate origin
transformThe coordinate transform
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
const Poly2 poly,
const Vec2 offset 
)
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.

Parameters
textureThe new active texture
polyThe polygon to texture
offsetThe polygon offset
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
Color4  color,
const Poly2 poly,
const Vec2 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.

Parameters
textureThe new active texture
colorThe new active color
polyThe polygon to texture
offsetThe polygon offset
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
const Poly2 poly,
const Vec2 origin,
const Vec2 scale,
float  angle,
const Vec2 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.

Parameters
textureThe new active texture
polyThe polygon to texture
originThe rotation origin
scaleThe amount to scale the polygon
angleThe amount to rotate the polygon
offsetThe polygon offset
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
Color4  color,
const Poly2 poly,
const Vec2 origin,
const Vec2 scale,
float  angle,
const Vec2 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.

Parameters
textureThe new active texture
colorThe new active color
polyThe polygon to texture
originThe rotation origin
scaleThe amount to scale the polygon
angleThe amount to rotate the polygon
offsetThe polygon offset
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
const Poly2 poly,
const Vec2 origin,
const Mat4 transform 
)
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.

Parameters
textureThe new active texture
polyThe polygon to texture
originThe coordinate origin
transformThe coordinate transform
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
Color4  color,
const Poly2 poly,
const Vec2 origin,
const Mat4 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.

Parameters
textureThe new active texture
colorThe new active color
polyThe polygon to texture
originThe coordinate origin
transformThe coordinate transform
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
const Poly2 poly,
const Vec2 origin,
const Affine2 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.

Parameters
textureThe new active texture
polyThe polygon to texture
originThe coordinate origin
transformThe coordinate transform
void cugl::SpriteBatch::draw ( const std::shared_ptr< Texture > &  texture,
Color4  color,
const Poly2 poly,
const Vec2 origin,
const Affine2 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.

Parameters
textureThe new active texture
colorThe new active color
polyThe polygon to texture
originThe coordinate origin
transformThe 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.

Parameters
rectThe 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.

Parameters
rectThe rectangle to draw
originThe rotation origin
scaleThe amount to scale the rectangle
angleThe amount to rotate the rectangle
offsetThe rectangle offset
void cugl::SpriteBatch::fill ( const Rect rect,
const Vec2 origin,
const Mat4 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.

Parameters
rectThe rectangle to draw
originThe coordinate origin
transformThe coordinate transform
void cugl::SpriteBatch::fill ( const Rect rect,
const Vec2 origin,
const Affine2 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.

Parameters
rectThe rectangle to draw
originThe coordinate origin
transformThe 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.

Parameters
polyThe polygon to draw
void cugl::SpriteBatch::fill ( const Poly2 poly,
const Vec2 offset 
)

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.

Parameters
polyThe polygon to draw
offsetThe 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.

Parameters
polyThe polygon to draw
originThe rotation origin
scaleThe amount to scale the polygon
angleThe amount to rotate the polygon
offsetThe polygon offset
void cugl::SpriteBatch::fill ( const Poly2 poly,
const Vec2 origin,
const Mat4 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.

Parameters
polyThe polygon to draw
originThe coordinate origin
transformThe coordinate transform
void cugl::SpriteBatch::fill ( const Poly2 poly,
const Vec2 origin,
const Affine2 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.

Parameters
polyThe polygon to draw
originThe coordinate origin
transformThe coordinate transform
void cugl::SpriteBatch::fill ( const std::vector< Vertex2 > &  vertices,
const std::vector< unsigned short > &  indices,
const Mat4 transform,
bool  tint = true 
)
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.

Parameters
verticesThe list of vertices
indicesThe triangulation list
transformThe coordinate transform
tintWhether to tint with the active color
void cugl::SpriteBatch::fill ( const std::vector< Vertex2 > &  vertices,
const std::vector< unsigned short > &  indices,
const Affine2 transform,
bool  tint = true 
)
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.

Parameters
verticesThe list of vertices
indicesThe triangulation list
transformThe coordinate transform
tintWhether 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.

Parameters
verticesThe array of vertices
vsizeThe size of the vertex array
voffsetThe first element of the vertex array
indicesThe triangulation array
isizeThe size of the index array
ioffsetThe first element of the index array
transformThe coordinate transform
tintWhether 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.

Parameters
verticesThe array of vertices
vsizeThe size of the vertex array
voffsetThe first element of the vertex array
indicesThe triangulation array
isizeThe size of the index array
ioffsetThe first element of the index array
transformThe coordinate transform
tintWhether 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 const std::shared_ptr<Texture>& cugl::SpriteBatch::getBlankTexture ( )
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.

Returns
the blank texture used to make solid shapes
GLenum cugl::SpriteBatch::getBlendEquation ( ) const
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
Returns
the blending equation for this sprite batch
unsigned int cugl::SpriteBatch::getCallsMade ( ) const
inline

Returns the number of OpenGL calls in the latest pass (so far).

This value will be reset to 0 whenever begin() is called.

Returns
the number of OpenGL calls in the latest pass (so far).
Color4 cugl::SpriteBatch::getColor ( ) const
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.

Returns
the active color of this sprite batch
GLenum cugl::SpriteBatch::getDestinationBlendFactor ( ) const
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
Returns
the destination blending factor
const Mat4& cugl::SpriteBatch::getPerspective ( ) const
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.

Returns
the active perspective matrix of this sprite batch
const std::shared_ptr<SpriteShader>& cugl::SpriteBatch::getShader ( ) const
inline

Returns the shader for this sprite batch

This value may NOT be changed during a drawing pass.

Returns
the shader for this sprite batch
GLenum cugl::SpriteBatch::getSourceBlendFactor ( ) const
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
Returns
the source blending factor
const std::shared_ptr<Texture>& cugl::SpriteBatch::getTexture ( ) const
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.

Returns
the active texture of this sprite batch
unsigned int cugl::SpriteBatch::getVerticesDrawn ( ) const
inline

Returns the number of vertices drawn in the latest pass (so far).

This value will be reset to 0 whenever begin() is called.

Returns
the number of vertices drawn in the latest pass (so far).
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.

Returns
true if initialization was successful.
bool cugl::SpriteBatch::init ( std::shared_ptr< SpriteShader shader)
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.

Returns
true if initialization was successful.
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.

Returns
true if initialization was successful.
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.

Returns
true if initialization was successful.
bool cugl::SpriteBatch::isDrawing ( ) const
inline

Returns whether this sprite batch is actively drawing.

A sprite batch is in use if begin() has been called without the requisite end() to flush the pipeline.

Returns
whether this sprite batch is actively drawing.
bool cugl::SpriteBatch::isReady ( ) const
inline

Returns true if this sprite batch has been initialized and is ready for use.

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.

Parameters
rectThe 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.

Parameters
rectThe rectangle to outline
originThe rotation origin
scaleThe amount to scale the rectangle
angleThe amount to rotate the rectangle
offsetThe rectangle offset
void cugl::SpriteBatch::outline ( const Rect rect,
const Vec2 origin,
const Mat4 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.

Parameters
rectThe rectangle to outline
originThe coordinate origin
transformThe 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.

Parameters
rectThe rectangle to outline
originThe coordinate origin
transformThe 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.

Parameters
polyThe polygon to outline
void cugl::SpriteBatch::outline ( const Poly2 poly,
const Vec2 offset 
)

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.

Parameters
polyThe polygon to outline
offsetThe 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.

Parameters
polyThe polygon to outline
originThe rotation origin
scaleThe amount to scale the polygon
angleThe amount to rotate the polygon
offsetThe polygon offset
void cugl::SpriteBatch::outline ( const Poly2 poly,
const Vec2 origin,
const Mat4 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.

Parameters
polyThe polygon to outline
originThe coordinate origin
transformThe 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.

Parameters
polyThe polygon to outline
originThe coordinate origin
transformThe coordinate transform
void cugl::SpriteBatch::outline ( const std::vector< Vertex2 > &  vertices,
const std::vector< unsigned short > &  indices,
const Mat4 transform,
bool  tint = true 
)
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.

Parameters
verticesThe list of vertices
indicesThe triangulation list
transformThe coordinate transform
tintWhether to tint with the active color
void cugl::SpriteBatch::outline ( const std::vector< Vertex2 > &  vertices,
const std::vector< unsigned short > &  indices,
const Affine2 transform,
bool  tint = true 
)
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.

Parameters
verticesThe list of vertices
indicesThe triangulation list
transformThe coordinate transform
tintWhether 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.

Parameters
verticesThe array of vertices
vsizeThe size of the vertex array
voffsetThe first element of the vertex array
indicesThe triangulation array
isizeThe size of the index array
ioffsetThe first element of the index array
transformThe coordinate transform
tintWhether 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.

Parameters
verticesThe array of vertices
vsizeThe size of the vertex array
voffsetThe first element of the vertex array
indicesThe triangulation array
isizeThe size of the index array
ioffsetThe first element of the index array
transformThe coordinate transform
tintWhether 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.

Parameters
equationSpecifies 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.

Parameters
srcFactorSpecifies how the source blending factors are computed
dstFactorSpecifies how the destination blending factors are computed.
void cugl::SpriteBatch::setColor ( Color4  color)
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.

Parameters
colorThe 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.

Parameters
perspectiveThe 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.

Parameters
shaderThe 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.

Parameters
textureThe active texture for this sprite batch

The documentation for this class was generated from the following file: