Texture atlasing for GUITextures

Hey all,

In our iPhone game, we’ve combined many of our buttons and gui icons onto one texture sheet. This works fine if we’re using a plane to display the image, we can map it onto a place and move its uvs around so that it only shows the certain button we’re looking for. No problem.

The problem is with our guiTextures. It seems it uses the whole texture. Is there a way to clamp out a certain part of the texture or crop in some way so we can use our guiTextures and our texture sheet to save memory?

Not possible with GUITextures I’m afraid.

–Eric

Ready for this crazy hack? I put 4 button images on one texture sheet and got it to work with guitextures by doing the following:

Put one button in each corner of your texture atlas. Make sure you have a transparent background to the texture atlas and each button has some transparent space around it. Load the texture atlas onto the guitexture and use the border numbers to “clamp” the certain part of the texture that you want, and set the height and width to 500,000, effectively stretching the rest of the texture into obscurity, never to be seen again… muahaha.

Hello there, I just found a simple way to dynamically load pieces of one or several image files into a guiTexture (or any Texture2D) :

Just look at the GetPixels / SetPixels functions of Texture2D :slight_smile:

That way, you can Resources.Load any file into a Texture2D variable, and manipulate it the way you want in any Start() function.

This can be extended to any 3D Texture Mapping (via a Texture2D manipulation of course), and save many drawcalls.

To an extent, you can even create dynamic Texture Animation this way, by loading sets of GetPixels into static vars, in just one DC.

Until I’m wrong with the logic, I just tested it with GUITexture, but planning to use it many times in my game to create cool animation effects.

Great idea n0mad, thanks!

Looking for a solution to a similar problem I stumbled upon the GUI.BeginGroup and GUI.EndGroup functions which do indeed allow you to crop an image:

Hope this helps

Hey Nomad,

I know this post is ancient, but what kind of luck have you had with GetPixels/SetPixels as a dynamic way to write textures during runtime?? I ask because I was trying to find a way to use a texture atlas to use with the GUI for reducing draw calls. It seems like a heavy process and I’m targeting iOS. I came up with a quick mock up with a GUITexture and it works, but I was wondering if the benefits of minimizing draw calls out weighs the negative aspect of having to store huge arrays of colours and iterating through them to write to a texture every time you need to change something ( it’s sure hard to balance the GPU/CPU with mobile development )…

Anyhow, I was wondering what kind of luck you had with it?

Cool idea anyhow