Just a quick question. I have written a game in Open gles. How can I render a value such as an integer on the screen ? (In this case int level).
Asked
Active
Viewed 182 times
1 Answers
3
I don't think open gl has any font support, but there are a few font libraries knocking about the internet. There is some discussion of that here:
Is there a decent OpenGL text drawing library for the iPhone SDK?
I needed to do the same thing as you, that fonts are probably overkill for. So, I simply made an array of images 0 to 9, then broke down the integer into a series of those images, by using % 10 to find which digit, then / 10 to move onto the next (more significant) digit.
-
That solution you devised is pretty smart, quick and dirty. I like it. – Aurum Aquila Jan 29 '11 at 10:53
-
Many thank - I've got this nearly working. How do I calculate the digits ? I can do the tens by doing 10%, how do I do the units ? – GuybrushThreepwood Jan 29 '11 at 21:38
-
When I said %, I meant modulus, not percent. Modulus effectively means the remainder when divided. So when you've got any integer n, the least significant digit (let's call it d) is the modulus base 10. For example, lets say n = 349; d = n % 10; so now d equals 9. To find the next digit, divide n by ten and repeat. So n = n / 10; now n equals 34. So d = n % 10; so now d equals 4. Again divide n by 10. n = n / 10; now n equals 3. d = n % 10; so now d equals 3. Again divide n by 10. n = n / 10; n now equals 0, so we can stop. In other words, do it in a while loop, while n > 0. – Dave Jan 29 '11 at 21:55