Image

Image is a class which is used to store a single image, for use in 2D games.

Image is derived from Texture, which is a resource managed class.  Texture is a simple OO wrapper around the concept of a texture in OpenGL.  An Image simply adds the ability to draw to a quad, as well as some rotation per-vertex tinting, and several other bonuses.

Since Image is a child of ResourceManaged, all memory management is taken care of.

Operators

  • Texture = Texture
  • operator bool
  • ostream& << Texture
Summary
Image is a class which is used to store a single image, for use in 2D games.
Default constructor, initalizes internal state of Image.
Copy constructor, copies another Image.
Initializing constructor, loads Image via call to open.
Opens an image file, currently supported image types are BMP, GIF, JPEG, PCX, PNG, and TGA.
Sets alpha-component for Image to be used when surface is drawn.
Flips image, horizontally and/or vertically.
Stretch image by a given factor.
Resize the image to a specific size.
draws image to the screen at a givem positon.
Draw image to screen at given position.
Draw image, rotated about it’s own center by a specified angle.
Draw image, rotated about it’s own center by a specified angle.
Get current surface-wide alpha value for image.

(Con/ De)structors

Image

Image()

Default constructor, initalizes internal state of Image.

Image

Image(const Image &rhs)

Copy constructor, copies another Image.

Parameters

rhsImage to construct copy of.

Image

Image(const std::string &name)

Initializing constructor, loads Image via call to open.

Parameters

nameName of the Image <Resource> to open.

See Also

open

General

open

void open(const std::string &name)

Opens an image file, currently supported image types are BMP, GIF, JPEG, PCX, PNG, and TGA.  (Images can be any dimensions)

Loading is done via a href=”Coronahttp://corona.sf.net">Corona</a.

Parameters

nameName of the Image <Resource> to open.

setAlpha

void setAlpha(ubyte alpha)

Sets alpha-component for Image to be used when surface is drawn.

Parameters

alphaDesired surface-wide alpha component for Image.

flip

void flip(bool horizontal,
bool vertical)

Flips image, horizontally and/or vertically.

Parameters

horizontalTrue if a flip over horizontal axis is desired.
verticalTrue if a flip over vertical axis is desired.

stretch

void stretch(scalar xFactor,
scalar yFactor)

Stretch image by a given factor.  For example: 1 = no change, .5 = 50% current size, 10 = 10 times current size.

Parameters

xFactorFactor for horizontal stretch.
yFactorFactor for vertical stretch.

resize

void resize(scalar width,
scalar height)

Resize the image to a specific size.

Parameters

widthNew desired with for image.
heightNew desired height for image.

Drawing

draw

void draw(scalar x,
scalar y) const

draws image to the screen at a givem positon.

Parameters

xX position to draw image at.
yY position to draw image at.

draw

void draw(scalar x,
scalar y,
ubyte vc[]) const

Draw image to screen at given position.

This version has an extra parameter, a color vertex option.  The 3rd parameter is an array of 16 ubytes defining, Starting in the top left corner & going counterclockwise, tint colors for the image.  It is possible to make very nice effects with little effort via this option.  Things like shading and lighting can be bluffed using this technique.

There are versions of drawRotated and <drawClipped> that have the vc parameter which works in the same manner.

Parameters

xX position to draw image at.
yY position to draw image at.
vcArray of 16 ubytes defining the colors of the 4 vertices in clockwise order.  (Order: R1,G1,B1,A1,...B4,A4)

drawRotated

void drawRotated(scalar x,
scalar y,
scalar angle) const

Draw image, rotated about it’s own center by a specified angle.

Parameters

xX position to draw image at.  (before rotation)
yY position to draw image at.  (before rotation)
angleAngle (in degrees) to rotate image.

drawRotated

void drawRotated(scalar x,
scalar y,
scalar angle,
ubyte vc[]) const

Draw image, rotated about it’s own center by a specified angle.  Includes color vertex option.

Parameters

xX position to draw image at.  (before rotation)
yY position to draw image at.  (before rotation)
angleAngle (in degrees) to rotate image.
vcArray of 16 ubytes defining the colors of the 4 vertices in clockwise order.  (Order: R1,G1,B1,A1,...B4,A4)

Accessors

getAlpha

ubyte getAlpha() const

Get current surface-wide alpha value for image.

Returns

Current surface-wide alpha.

See Also

setAlpha

Image()
Default constructor, initalizes internal state of Image.
void open(const std::string &name)
Opens an image file, currently supported image types are BMP, GIF, JPEG, PCX, PNG, and TGA.
void setAlpha(ubyte alpha)
Sets alpha-component for Image to be used when surface is drawn.
void flip(bool horizontal,
bool vertical)
Flips image, horizontally and/or vertically.
void stretch(scalar xFactor,
scalar yFactor)
Stretch image by a given factor.
void resize(scalar width,
scalar height)
Resize the image to a specific size.
void draw(scalar x,
scalar y) const
draws image to the screen at a givem positon.
void drawRotated(scalar x,
scalar y,
scalar angle) const
Draw image, rotated about it’s own center by a specified angle.
ubyte getAlpha() const
Get current surface-wide alpha value for image.
Simple OO wrapper around the concept of a texture in openGL.
Base template class, to be used as a base from which classes which have resources that can be controlled, such as textures and music, can be derived.
Unsigned byte, alias for unsigned char.