Click here to Skip to main content
13,590,782 members
Click here to Skip to main content

Stats

104.4K views
6.3K downloads
55 bookmarked
Posted 15 Feb 2012
Licenced BSD

Texture Atlas Maker

, 1 Apr 2012
A utility to create texture atlases for 2D OpenGL games
AtlasExample
.DS_Store
__MACOSX
AtlasExample
._.DS_Store
AtlasExample
.DS_Store
AtlasExample
._.DS_Store
AtlasExample-Prefix.pch
._AtlasExample-Prefix.pch
en.lproj
InfoPlist.strings
en.lproj
._InfoPlist.strings
images0.tga
Shaders
Shaders
AtlasExample.xcodeproj
project.pbxproj
project.xcworkspace
contents.xcworkspacedata
xcuserdata
lefty.xcuserdatad
UserInterfaceState.xcuserstate
xcuserdata
lefty.xcuserdatad
xcdebugger
Breakpoints.xcbkptlist
xcschemes
AtlasExample.xcscheme
AtlasExampleTests
AtlasExampleTests-Prefix.pch
AtlasExampleTests
._AtlasExampleTests-Prefix.pch
en.lproj
InfoPlist.strings
en.lproj
._InfoPlist.strings
.DS_Store
._.DS_Store
.DS_Store
._.DS_Store
AtlasExample-Prefix.pch
._AtlasExample-Prefix.pch
InfoPlist.strings
._InfoPlist.strings
imagesNelly0.tga
project.pbxproj
contents.xcworkspacedata
UserInterfaceState.xcuserstate
Breakpoints.xcbkptlist
AtlasExample.xcscheme
AtlasExampleTests-Prefix.pch
._AtlasExampleTests-Prefix.pch
InfoPlist.strings
._InfoPlist.strings
AtlasMaker
.classpath
.project
bin
icon.png
images
icon.png
output.png
settings.png
output.png
settings.png
src
AtlasMaker.jar
AtlasMaker.jar
AtlasMaker.jar
AtlasMaker.jar
AtlasMaker.jar
.classpath
.project
.settings
icon.png
icon.png
settings.png
settings.png
.classpath
.project
icon.png
icon.png
output.png
settings.png
output.png
settings.png
.classpath
.project
icon.png
icon.png
settings.png
settings.png
.classpath
.project
icon.png
icon.png
settings.png
settings.png
.classpath
.project
icon.png
icon.png
settings.png
settings.png
#include "PreCompile.h"
#include "ResManager.h"
#include "Util.h"
#include "AtlasMaster.h"
#include "CommonBuffer.h"
#include "XParser.h"

ResManager g_resManager;

ResManager::ResManager() : m_initialised(false)
{
}

ResManager::~ResManager()
{
}

void ResManager::Release()
{
	delete m_pXParser;
	delete m_pAtlasMaster;
}

void ResManager::Init(const string& dirResources, const string& dirUser, 
	int screenWidth, int screenHeight)
{
	m_dirUser = dirUser + FILE_SEPERATOR;
	m_dirResources = dirResources + FILE_SEPERATOR;
#ifdef _DEBUG
	cout << m_dirResources << endl;
	cout << m_dirUser << endl;
#endif
	m_screenWidth = screenWidth;
	m_screenHeight = screenHeight;
	m_pXParser = new XParser();

	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
	glEnable(GL_CULL_FACE);
	glDisable(GL_DITHER);	// these are enabled by default
	glDisable(GL_ALPHA_TEST);
	
	glViewport(0, 0, m_screenWidth, m_screenHeight);
	m_initialised = true;
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glDisable(GL_LIGHTING);
	glFrontFace(GL_CW);
    glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	// set orthographic, so that we are drawing billboard style using screen dimensions 
	glOrthof(0, (float)m_screenWidth, (float)m_screenHeight, 0, -50.0f, 50.0f);

	glActiveTexture(GL_TEXTURE1);
	glDisable(GL_TEXTURE_2D);
	glActiveTexture(GL_TEXTURE0);
	glEnable(GL_TEXTURE_2D);
	glClientActiveTexture(GL_TEXTURE1);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glClientActiveTexture(GL_TEXTURE0);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisable(GL_DEPTH_TEST);	
	// handle tranparancy
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	m_pAtlasMaster = new AtlasMaster();
	m_pAtlasMaster->Load(m_dirResources + "atlas.xml");
	g_commonBuffer.Release();
}

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

Share

About the Author

ed welch
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.

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.180618.1 | Last Updated 1 Apr 2012
Article Copyright 2012 by ed welch
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid