Grouping images into a mega texture?

Started by
0 comments, last by FXACE 12 years, 1 month ago
I'm making a 2D game and I'd like to group all the images that I'm going to use for a certain level into one huge texture (or a couple of textures) instead of binding many different textures each frame.

My question is, first, code-wise, how would I go about assembling this texture?

Second, how would I then disassemble it? Or rather, know the relevant parts to draw? Should I just keep track of the coordinates as I'm adding them in?
Advertisement
You can use either GL_TEXTURE_2D_ARRAY in GLSL eigther to combine some textures into one:
+-------+
|....A....|
|..........|
+-------+
combine with:
+-------+
|....B....|
|..........|
+-------+
result: "C" =
+-------++-------+
|....A.....||....B....|
|...........||...........|
+-------++-------+
- where "A" and "B" are different textures but with the same dimensions.
Note: you need here to adjust texture coordinates. For example:

float new_s_coord = old_s_coord / float(num_combined_textures) + (float(use_texture_index) / float(num_combined_textures));
float new_t_coord = old_t_coord; // no changes, because we do texture combination by horizontal axis


If you are using GL_REPEAT texture coordinate wrapping (for example: walls, ground, etc..), it is better to use first method (GL_TEXTURE_2D_ARRAY), because with this method you will get some strange graphic results.

Best wishes, FXACE.

This topic is closed to new replies.

Advertisement