Jump to content

  • Log In with Google      Sign In   
  • Create Account


Grouping images into a mega texture?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 OmarShehata   Members   -  Reputation: 205

Like
0Likes
Like

Posted 20 March 2012 - 11:58 PM

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?

Sponsor:

#2 FXACE   Members   -  Reputation: 182

Like
1Likes
Like

Posted 21 March 2012 - 06:46 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS