Well this is not quite as easy as actually packing things before hand, (and not as fast) but is great for prototyping and adding stuff without having to repack every time. I made these classes when I made my Atlas engine which is crap but it was nice not having to deal with json/xml and still get atlases.
Here is the paste bin for the 3 classes.
http://pastebin.java-gaming.org/7718c134177 <---- Atlas class
http://pastebin.java-gaming.org/718c3214777 <---- BufferedImageUtils class
http://pastebin.java-gaming.org/18c3137477c <---- TextureRegion class.
Loads images onto a BufferedImage via java2d and a given name for the image. It will save the region coordinates of each image. Once all images are added, it will create a texture from the BufferedImage. You can then grab any region that was loaded. Here is example usage.
Atlas a1 = new Atlas(1024, 1024, "a1");
a1.addTexStrip(BufferedImageUtils.loadImageStrip("res/bloodSplat.png", 2, 2, 4, 128, 128), "bloodSplash");
a1.addTex(BufferedImageUtils.loadImage("res/player/idle.png", true), "playerTopIdle");
a1.addTex(BufferedImageUtils.loadImage("res/player/botIdle.png", true), "playerBotIdle");
a1.addTex(BufferedImageUtils.loadImage("res/player/fire1.png", true), "playerFire1");
a1.addTex(BufferedImageUtils.loadImage("res/player/fire2.png", true), "playerFire2");
a1.set();
//later in code
TextureRegion topIdle,botIdle,fire1,fire2;
topIdle = a1.getTexRegion("playerTopIdle");
botIdle = a1.getTexRegion("playerBotIdle");
fire1 = a1.getTexRegion("playerFire1");
fire2 = a1.getTexRegion("playerFire2");
//loading a strip of images into an array of TextureRegions
FxBloodSplat b = new FxBloodSplat(l.x + Rnd.random(1), l.y + Rnd.random(1), a1.getRegion("bloodSplash", 3), (int) a);
//rendering.
public static void drawImage(float x, float y, float w, float h, TextureRegion tex, Vector4f color)
{
glBindTexture(GL_TEXTURE_2D, tex.texID);
glBegin(GL_QUADS);
{
glColor4f(color.x, color.y, color.z, color.w);
glTexCoord2f(tex.region[0], tex.region[1]);
glVertex2f(x - w / 2, y - h / 2);
glTexCoord2f(tex.region[2], tex.region[3]);
glVertex2f(x + w / 2, y - h / 2);
glTexCoord2f(tex.region[4], tex.region[5]);
glVertex2f(x + w / 2, y + h / 2);
glTexCoord2f(tex.region[6], tex.region[7]);
glVertex2f(x - w / 2, y + h / 2);
}
glEnd();
}
This is quick and dirty and can very much be improved. It is fast enough for smaller games but for a larger project, use libGDX with their oh so nice texture packer. This should be an easy introduction for people looking to play with texture atlases before delving into libGDX or their own versions. I use it a bunch for my non-libgdx stuff as I am too damn lazy to use all the fancy texture packers.