Click here to Skip to main content
15,891,864 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.7K   7K   55  
A utility to create texture atlases for 2D OpenGL games
#ifndef _TARGAREADER_H_INCLUDED_
#define _TARGAREADER_H_INCLUDED_

class TargaReader
{
#pragma pack(push)  /* push current alignment to stack */
#pragma pack(1)     /* set alignment to 1 byte boundary */
	class TargaHeader 
	{
		public:
		char  m_idLength;
		char  m_colourMapType;
		char  m_imageType;
		short m_colourMapOrigin;
		short m_colourMapLength;
		char  m_colourMapDepth;
		short m_xOrigin;
		short m_yOrigin;
		short m_width;
		short m_height;
		char  m_bitsPerPixel;
		char  m_imageDescriptor;
	};
#pragma pack(pop) 
public:
	TargaReader();
	~TargaReader();
	void Load(const string& fileName);
	int GetWidth() const
	{
		return m_targaHeader.m_width;
	}
	int GetHeight() const
	{
		return m_targaHeader.m_height;
	}
	unsigned char* GetRawData()
	{
		return (unsigned char*)m_pData;
	}
	int GetBitDepth() const
	{
		return m_targaHeader.m_bitsPerPixel;
	}
private:
	void ReadRLE(FILE *pFile);
	void ReadRLE16(const char* pDataIn, int bufferInSize, int totalPixels);
	void ReadRLE32(const char* pDataIn, int bufferInSize, int totalPixels);
	TargaHeader m_targaHeader;
	char* m_pData;
	int m_dataSize;
};





#endif // _TARGAREADER_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