Jump to content
  • Advertisement
Sign in to follow this  
OmarShehata

Grouping images into a mega texture?

This topic is 2402 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!