Click here to Skip to main content
15,886,110 members
Articles / Mobile Apps / Android

Texture Atlas Maker

Rate me:
Please Sign up or sign in to vote.
4.94/5 (16 votes)
1 Apr 2012BSD6 min read 142.3K   7K   55  
A utility to create texture atlases for 2D OpenGL games
#ifndef _ATLASIMAGE_H_INCLUDED_
#define _ATLASIMAGE_H_INCLUDED_


class ImageGL;
class XParser;
class Rect;

const int verticesPerQuad = 4;
const int indicesPerQuad = 6;
const int compVertPos = 2;
const int compVertTex = 2;

class AtlasImage
{
public:
	AtlasImage(ImageGL* pTexture) : m_pImageGL(pTexture) {}
	AtlasImage(const AtlasImage& atlasImage);
	AtlasImage() : m_pImageGL(NULL) {}
	void Load(const XParser* pXParser);
	void Render(int x, int y) const;
	void Release();
	int GetHeight() const
	{
		return m_height;
	}
	int GetWidth() const
	{
		return m_width;
	}
	int GetXOffset() const
	{
		return m_xOffset;
	}
	void SetXOffset(int xOffset)
	{
		m_xOffset = xOffset;
	}
	int GetYOffset() const
	{
		return m_yOffset;
	}
	void SetYOffset(int yOffset)
	{
		m_yOffset = yOffset;
	}
	const string& GetName() const
	{
		return *m_pName;
	}
	void SetName(const string& name)
	{
		m_pName = &name;
	}
	ImageGL* GetTexture() const
	{
		return m_pImageGL;
	}
	void SetImageGL(ImageGL* pImageGL)
	{
		m_pImageGL = pImageGL;
	}
	int GetTransHeight() const
	{
		return m_transHeight;
	}
	int GetTransWidth() const
	{
		return m_transWidth;
	}
	friend class TexturedQuad; 
protected:
	bool CreateVertices(float* vertices, int x, int y, 
		float scale, float rotation, int ancor) const;
	const string* m_pName;	// only for debug purposes
	int m_x;
	int m_y;
	int m_width;
	int m_height;
	int m_transWidth;
	int m_transHeight;
	int m_xOffset;
	int m_yOffset;
	bool m_transparent;
	float m_texCoords[verticesPerQuad*compVertTex];
	ImageGL* m_pImageGL;
};

void CreateQuad(float* pTexCoords, 
	int x, int y, int width, int height,
	int texWidth, int texHeight);




#endif // _ATLASIMAGE_H_INCLUDED_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Software Developer Astronautz
Spain Spain
After working in the software industry for many years, I've started my own games company that specialises in strategy games for mobile platforms.

Comments and Discussions