I’m having a problem with texturing objects in OpenGL using texture atlases, I’m creating a 2d game and I know how to texture a POT bitmap to an object but, I can’t seem to find a tutorial in converting my code to use a texture atlas for performance reasons, here is my code for my current working object creation and texturing implementation.
public void createTexture(Bitmap bmp, GL10 gls, int texturename)
{
this.gl = (GL11) gls;
this.TextureName = texturename;
bombBmp = bmp;
VertexBuffer = null;
TextureBuffer = null;
IndexBuffer = null;
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(12 * 4);
byteBuffer.order(ByteOrder.nativeOrder());
VertexBuffer = byteBuffer.asFloatBuffer();
VertexBuffer.put(new float[] { 0, 0, 0.0f, 0, -h, 0.0f, w, 0, 0.0f, w, -h, 0.0f });
VertexBuffer.position(0);
byteBuffer = ByteBuffer.allocateDirect(8 * 4);
byteBuffer.order(ByteOrder.nativeOrder());
TextureBuffer = byteBuffer.asFloatBuffer();
TextureBuffer.put(new float[] { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f });
TextureBuffer.position(0);
byteBuffer = ByteBuffer.allocateDirect(6 * 2);
byteBuffer.order(ByteOrder.nativeOrder());
IndexBuffer = byteBuffer.asShortBuffer();
IndexBuffer.put(new short[] { 0, 1, 2, 1, 3, 2 });
IndexBuffer.position(0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, this.TextureName);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bombBmp, 0);
bombBmp.recycle();
bombBmp = null;
}
I generate my Texturename from genTexture and pass the POT bitmap to this function
gl.glGenTextures(1, textures, 0);
bomb.createTexture(bombBmp, gl, textures[0]);
here’s my supposed texture bitmap

Responding to your comment, you don’t bind subImages. glTexSubImage is only used for replacing pixels in a stored texture. If your bitmap already exists as an atlas as you’ve shown, then you just load the whole texture via glTexImage2d and bind it.
If you want to access a particular part of that image (say the yellow circle bomb 3rd from the left on the first line), then you just modify the texture coordinates that you use to access it. If that circle was in its own image you would just use (0,0) to (1,1) coordinates, but because it is part of another image you have to select just a specific part of it. In your picture there it would have texcoords of:
If you draw a quad with these texcoords it should look exactly as if the yellow circle bomb had its own image, but you don’t have to keep rebinding textures all the time (hence the performance increase).