Sign in to follow this  
Palidine

Bitmap Fonts with a Texture Atlas

Recommended Posts

Hey, So I already have built a system for generating texture atlases from TTF files: generates the texture and the texture index file. The question is how to render this in my shader. What I'm going to do for simplicity's sake is basically iterate the string and render each character as it's own draw call, passing relevant parameters into the shader. Since it's a texture atlas the texture is only bound once for the text. The question is how to pass in the UV information since that's looked up per character in the index data. Is it better to bind the index data as a texture and have a sampler find it somehow (don't know how to do this. if it's the right way, tips would be useful). Or is it fine to just do the lookup on the CPU and pass the uv as shader parameters. I already know how to do this, it just seems that the former option would be faster. -me

Share this post


Link to post
Share on other sites
Quote:
Or is it fine to just do the lookup on the CPU and pass the uv as shader parameters.
This seems like a perfectly reasonable approach to me. You don't necessarily even need a separate draw call per character (when rendering a string, you could instead build up a temporary buffer containing the relevant vertex data).

Maybe there are alternative techniques that I'm not aware of though (if so, I'm sure someone will point them out).

Share this post


Link to post
Share on other sites
Quote:
write a seperate txt file that contains the nesseray information when creating the texture atlas.
It sounds to me like that's exactly what the OP's doing (he stated that he already has a system that generates a texture and an index file).

The question wasn't how to generate the font data, but rather how to render text using a shader.

Share this post


Link to post
Share on other sites
Lookup via the CPU is just fine. I´m doing it the same way. I use a single quad, and build it´s UVs depending on the char. Than move that quad to the next position and so on. I would say that´s a passable way of doing that.

Share this post


Link to post
Share on other sites
Pass the texture coordinate data for the location of the font to the vertex shader, and pass that onto the fragment shader to render that portion of the font texture.

letter 'a' located at 256, 128 of a 512x512 texture 256/512 = .5 128/512 = .25 and that for each of the 4 vertices of the quad. If your font is 32x32 just add that to the 256,128 or subtract however you have this texture setup... Off the top of my head that is what I would do... Been awhile since I coded :( To busy at work...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this