Angel 3.2
A 2D Game Prototyping Engine
Functions
Textures.h File Reference
#include "../Util/StringUtil.h"
#include "../Infrastructure/Color.h"

Go to the source code of this file.

Functions

void InitializeTextureLoading ()
 
void FinalizeTextureLoading ()
 
void FlushTextureCache ()
 
const int GetTextureReference (const String &name, bool optional=false)
 
const int GetTextureReference (const String &filename, GLint clampmode, GLint filtermode, bool optional=false)
 
const Vec2i GetTextureSize (const String &filename)
 
bool PurgeTexture (const String &filename)
 
bool GetRawImageData (const String &filename, std::vector< Color > &pixels)
 
bool PixelsToPositions (const String &filename, Vector2List &positions, float gridSize, const Color &pixelColor, float tolerance=0.1f)
 

Detailed Description

A low-level C-style interface for managing textures. Most of the functionality is wrapped in the Actor classes, which is where you should probably be focusing. The function you might otherwise care about in here is FlushTextureCache.

Definition in file Textures.h.

Function Documentation

void InitializeTextureLoading ( )

Do whatever setup needs to be done at program start.

Definition at line 50 of file Textures.cpp.

void FinalizeTextureLoading ( )

Do whatever cleanup needs to be done at program end.

Definition at line 65 of file Textures.cpp.

void FlushTextureCache ( )

Goes through all loaded textures and marks them as dirty, so the next time they're referenced the file will be loaded up fresh from the disk. The effect of this is that you can update your texture files and see them in-game without having to restart.

Definition at line 82 of file Textures.cpp.

const int GetTextureReference ( const String &  name,
bool  optional = false 
)

Get the GL texture reference from a file path. If this is the first time a file has been referenced, it will be loaded from disk and formatted appropriately for OpenGL. Thus you use this function to both load your textures initially and to reference them afterwards.

Parameters
nameThe path to the file to load. Must be readable by DevIL. (http://openil.sourceforge.net/)
optionalIf true, the engine won't complain if it can't load it.
Returns
The GLuint that OpenGL uses to reference the texture. If the number is negative, that means the texture couldn't be loaded or found.

Definition at line 93 of file Textures.cpp.

const int GetTextureReference ( const String &  filename,
GLint  clampmode,
GLint  filtermode,
bool  optional = false 
)

The same as the above function, but with some more available parameters if you want control over how to display this texture. See OpenGL docs for further explanation of how these parameters work.

Parameters
nameThe path to the file to load. Must be readable by DevIL. (http://openil.sourceforge.net/)
clampmodeEither GL_CLAMP or GL_REPEAT.
filtermodeOne of: GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, or GL_LINEAR_MIPMAP_LINEAR
optionalIf true, the engine won't complain if it can't load it.
Returns
The GLuint that OpenGL uses to reference the texture. If the number is negative, that means the texture couldn't be loaded or found.

Definition at line 327 of file Textures.cpp.

const Vec2i GetTextureSize ( const String &  filename)

Gets the dimensions for a loaded texture.

Parameters
filenameThe path to the texture's file.
Returns
The width and height of the texture; if no texture is currently loaded from the given filename, will return (0, 0)

Definition at line 416 of file Textures.cpp.

bool PurgeTexture ( const String &  filename)

Remove a texture from memory. On the desktop this usually isn't an issue unless your game is long-running and uses lots of images, but those issues crop up earlier on mobile platforms.

Parameters
filenameThe filename of the texture to be removed
Returns
Whether the texture was previously loaded into memory or not

Definition at line 98 of file Textures.cpp.

bool GetRawImageData ( const String &  filename,
std::vector< Color > &  pixels 
)

Use this function to get the raw pixel data of an image as a vector of Color structures.

Parameters
filenameThe path to the file to load
pixelsThe vector of Colors to populate
Returns
Whether the image was found and processed.

Definition at line 429 of file Textures.cpp.

bool PixelsToPositions ( const String &  filename,
Vector2List &  positions,
float  gridSize,
const Color pixelColor,
float  tolerance = 0.1f 
)

Use this function to process an image into positional data, in other words, use an image as map or level data. For every pixel within the tolerance range of the specified color, a Vector2 is added to positions. Resulting positions will be in range imageSizeX * gridSize, imageSizeY * gridSize, and be centered on 0,0.

Parameters
filenameThe path to the file to load.
positionsThe vector of Vector2s to populate
gridSizeThe size of the grid, i.e. how much space one pixel occupies.
pixelColorThe color to search the image for (channels in 0.0-1.0 range). NOTE: Alpha component is unused.
toleranceThe amount RGB channels can deviate from pixelColor.
Returns
Whether the image was found and processed.

Definition at line 509 of file Textures.cpp.