Text from image

I want to draw text from an image (TGA or something)… But how do I read the letters ? I have seen that I can use a singel TGA image with all the letters in it. but how do I read the image so the image will be split in letters ? so I can draw the right one…

You need to set a fixed width and height of each letter. Then you need to know the order of your letters. The simplest solution I can think of right now is to make the order of your letter equal to the ascii table (a-z) that way you just need to know the ascii code of first letter (a) and substitute it from the letter you want to draw. I don’t know the real code for the letter ‘a’ but for example if the code is 66 then ‘b’ is 67, ‘c’ is ‘68’ and so on. If you want do draw the letter ‘c’ all you have to do is:

code for ‘c’ = 68
your starting letter is ‘a’ with code 66

so your index is 68-66=2

If you set your width of the letter to 50 and your height to 60 and you have 10 letters in each row, then you get the texture coordinate as follows:

tex.x=(index%numberOfLettersInRow)*width = (2%10)50=250=100;
tex.y=(index/numberOfLettersInRow)*height = (2/10)*60=0;

Then you have to normalize this values to the range 0-1 by dividing them with the image width and image heigth:


Another solution would be if you’d make a table of letters and put the letters on the indexes on which the letters would be in the picture. Then you’d calculate your index with finding the letter in the table and use the index on which you’ve found your letter.

Hope it helps


thanks that looks easy I hope it works for me