I’ve run into a situation where I need a texture with only an alpha. Let me describe it:
I’m recreating the HUD for my game, and in it I have some curved bars to represent values. To make the bars appear to go up and down without distorting their color or curve, I apply a texture with an alpha channel to them, in modulate mode. Because of the modulate mode, the alpha in the textures creates a cut out in the bars. Using that to my advantage, I can offset the texture with the alpha according to the value the bar is connected to, thus determining how much of the bar is removed by the cut out.
For this to work, I need a texture with just an alpha. I can do it by using a small, all white PNG image for RGB and another gray-scale PNG for the alpha and loading them with
Which is alright, but because of how loadTexture works, if I load White.png more than once with different alphas, I only get the first alpha I loaded. To get new alphas, I need more white.pngs with different names.
Instead of having a couple of pointless, worthless, tiny images loaded into memory, I’d rather just load the alphas and have them work as alphas. Is there a way to make that happen?
Another reliable way that doesn’t require mucking with the texture settings after loading it is to create an egg file, for instance with egg-texture-cards, and load the texture via that egg file:
egg-texture-cards -f alpha -o Alpha.egg Alpha.png
model = loader.loadModel("Alpha.egg")
tex = model.findTexture("Alpha")
For now I’m going to use a work around I just thought off. Since my alpha is just black and white, I’m not using any gray, I can just use the same image for both the RGB and Alpha components. Duh, right?