• Advertisement
Sign in to follow this  

Grouping images into a mega texture?

This topic is 2224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement