I would like to apply an opacity map, which I have stored as a black and white image, to a solid-colored card. Currently I achieve this with the hack:
opacityMap = loader.loadTexture('black.png', 'map.png')
where ‘black.png’ is a huge, all-black image, but it seems that there has got to be a better way–ideally one that involves setting the color of the card with card.setColor and then applying the opacity map over it. Is there?
I’m almost certain you could do it with a custom TextureStage blend mode. If you want to save space by using a b&w texture, this is probably the route to try. However, in most graphics engines, including Panda to my recollection, textures are multiplied onto the base object color by default. If you start with a white&transparent texture (getting texture transparency isn’t half as hard as the manual makes it out to be, in my experience), you should just be able to apply the texture in one pass, and have any underlying object color shown in the white regions of the texture map. Gimp & PS both have channel-copy mechanisms that should even let you automatically transfer your b&w mask to an alpha channel with a little setup.
Hmm, there must be a way to load just the alpha channel.
Does it work if you simply load map.png, then set the format to FAlpha, and call reload() on the texture?
Ah, perfect. pro-rsoft’s suggestion does, indeed, work perfectly. I think I’ll add a mention of that in the “Transparency and Blending” section of the manual next to the loader.loadTexture trick.
Eh, nevermind about the manual. I’m not sure it belongs there.