I have written a font class, which uses a jpg texture containing all of the characters
i.e
it is 256x256 pixels, with each character being (16x16 pixels ) layed out as a grid
on the texture.
Basically, I draw a billboarded quad to the screen, for each character in strings I want to display, and I pull out 16x16 ‘sub-textures’ from the overall texture, for each quad.
I would like to use black to be transparent
when drawing these textures, and am struggling with the blending functions to use to achieve this…
What is the simplest way to draw my quads,
whilst getting the scene to show through the transparent parts of the font?
when you load your image you should use the alpha channel of the texture. Just assign it the luminance of your font. Then you can use alphatest and blending:
you load the jpg into a buffer of this type normally:
unsigned char imagedata[width][height][3]; or so…
just add the alpha channel onto it. by hand.
where the image is black, make alpha to 0, where it is not, set it to 1… or other way around, you can set your blending equation /alpha test how ever you want.
Yep doggy, adding the alpha channel by hand is a good way (unless you want to use TGAs) - it’s also not that hard once you get over thinking about it (I used to think it was a strange way to do things, but it turns out pretty good). However, you’re touching each pixel in the image again so it may slow down your loading (although that won’t be too much of a problem if you’re caching your textures on startup).