Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
Public Member Functions | List of all members
gf::BufferedGeometry Class Reference

A drawable for buffers. More...

#include <gf/BufferedGeometry.h>

Inheritance diagram for gf::BufferedGeometry:
Inheritance graph
[legend]

Public Member Functions

 BufferedGeometry ()
 Default constructor. More...
 
 BufferedGeometry (const VertexBuffer &buffer)
 Constructor with a buffer. More...
 
 BufferedGeometry (const VertexBuffer &buffer, const VertexBuffer &outlineBuffer)
 Constructor with a buffer and an outline buffer. More...
 
void setBuffer (const VertexBuffer &buffer)
 Set the vertex buffer. More...
 
void setOutlineBuffer (const VertexBuffer &outlineBuffer)
 Set the outline buffer, if any. More...
 
void setTexture (const BareTexture &texture)
 Change the source texture of the geometry. More...
 
const BareTexturegetTexture () const
 Get the source texture of the geometry. More...
 
void unsetTexture ()
 Unset the source texture of the geometry. More...
 
void setLocalBounds (const RectF &bounds)
 Set the local bounds of the geometry. More...
 
RectF getLocalBounds () const
 Get the local bounding rectangle of the entity. More...
 
void setAnchor (Anchor anchor)
 Set the anchor origin of the entity. More...
 
virtual void draw (RenderTarget &target, RenderStates states) override
 Draw the object to a render target. More...
 
- Public Member Functions inherited from gf::Transformable
 Transformable ()
 Default constructor. More...
 
void setOrigin (Vector2f origin)
 Set the local origin of the object. More...
 
Vector2f getOrigin () const
 Get the local origin of the object. More...
 
void setPosition (Vector2f position)
 Set the position of the object. More...
 
Vector2f getPosition () const
 Get the position of the object. More...
 
void move (Vector2f offset)
 Move the object by a given offset. More...
 
void setRotation (float angle)
 Set the orientation of the object. More...
 
float getRotation () const
 Get the orientation of the object. More...
 
void rotate (float angle)
 Rotate the object. More...
 
void setScale (Vector2f factors)
 Set the scale factors of the object. More...
 
void setScale (float factor)
 Set the scale factor of the object. More...
 
Vector2f getScale () const
 Get the current scale of the object. More...
 
void scale (Vector2f factors)
 Scale the object. More...
 
void scale (float factor)
 Scale the object. More...
 
Matrix3f getTransform () const
 Get the combined transform of the object. More...
 
Matrix3f getInverseTransform () const
 Get the inverse of the combined transform of the object. More...
 
- Public Member Functions inherited from gf::Drawable
virtual ~Drawable ()
 Virtual desctructor. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gf::Transformable
void setOriginFromAnchorAndBounds (Anchor anchor, const RectF &bounds)
 Set the origin from an anchor and bounds. More...
 

Detailed Description

A drawable for buffers.

A buffered geometry is a lightweight object to draw vertex buffers. It can handle two vertex buffers, one for the main object and one for the outline when it exists. The outline is drawn first and the main object second.

In addition to the geometry, a buffered geometry can store a texture if needed because a vertex buffer has no notion of texture.

Finally, a buffered geometry can remember the local bounds of the original object, so that it can be used for setting an anchor.

See also
gf::VertexBuffer

Constructor & Destructor Documentation

gf::BufferedGeometry::BufferedGeometry ( )

Default constructor.

gf::BufferedGeometry::BufferedGeometry ( const VertexBuffer buffer)

Constructor with a buffer.

Parameters
bufferA vertex buffer
gf::BufferedGeometry::BufferedGeometry ( const VertexBuffer buffer,
const VertexBuffer outlineBuffer 
)

Constructor with a buffer and an outline buffer.

Parameters
bufferA vertex buffer
outlineBufferAn outline buffer
See also
setBuffer(), setOutlineBuffer()

Member Function Documentation

virtual void gf::BufferedGeometry::draw ( RenderTarget target,
RenderStates  states 
)
overridevirtual

Draw the object to a render target.

This is a pure virtual function that has to be implemented by the derived class to define how the drawable should be drawn.

Parameters
targetRender target to draw to
statesCurrent render states

Implements gf::Drawable.

RectF gf::BufferedGeometry::getLocalBounds ( ) const
inline

Get the local bounding rectangle of the entity.

The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity's coordinate system.

Returns
Local bounding rectangle of the entity
const BareTexture* gf::BufferedGeometry::getTexture ( ) const
inline

Get the source texture of the geometry.

If the geometry has no source texture, a nullptr pointer is returned. The returned pointer is const, which means that you can't modify the texture when you retrieve it with this function.

Returns
Pointer to the geometry's texture
See also
setTexture()
void gf::BufferedGeometry::setAnchor ( Anchor  anchor)

Set the anchor origin of the entity.

Compute the origin of the entity based on the local bounds and the specified anchor. Internally, this function calls Transformable::setOrigin().

Parameters
anchorThe anchor of the entity
See also
getLocalBounds(), Transformable::setOrigin()
void gf::BufferedGeometry::setBuffer ( const VertexBuffer buffer)
inline

Set the vertex buffer.

Parameters
bufferA vertex buffer
See also
setOutlineBuffer()
void gf::BufferedGeometry::setLocalBounds ( const RectF bounds)
inline

Set the local bounds of the geometry.

There is no way to compute the bounds of the object with the vertex buffer. So you have to set it directly with this function when you create the geometry.

Parameters
boundsThe local bounds of the object
void gf::BufferedGeometry::setOutlineBuffer ( const VertexBuffer outlineBuffer)
inline

Set the outline buffer, if any.

Parameters
outlineBufferAn outline buffer
See also
setBuffer()
void gf::BufferedGeometry::setTexture ( const BareTexture texture)
inline

Change the source texture of the geometry.

The texture must exist as long as the geometry uses it. Indeed, the geometry doesn't store its own copy of the texture, but rather keeps a pointer to the one that you passed to this function. If the source texture is destroyed and the geometry tries to use it, the behavior is undefined.

Parameters
textureThe texture
See also
getTexture()
void gf::BufferedGeometry::unsetTexture ( )
inline

Unset the source texture of the geometry.

After a call to this function, the geometry has no source texture.

See also
setTexture()