I am porting my program from mac/windows to the iPad. Up until now, I have been using the GLUT functions for drawing text, such as:
glutBitmapCharacter (GLUT_BITMAP_HELVETICA_10,theString[i]);
But those functions are not supported on the iPad, so I am trying to use SDL_ttf for text.
There are 2 examples that demonstrate SDL_ttf.
http://lackeyccg.com/glfont.c shows how things are done with OpenGL.
http://lackeyccg.com/showfont.c shows how things are done with just SDL.
I’m not sure what is the better method for my uses.
I am using text for essentially 3 kinds of uses:
Labels for things like buttons and menus.
Text for text fields.
?
And text labels that appear in 3D space. (The text itself is flat, but it appears in 3D OpenGL space.)
??
If I understand things correctly, with SDL_ttf, fonts are loaded and then you can use those fonts to create surface images, or load those images into opengl which you can refer to later by the texture id. In either case, it seems like you need to store a unique image in memory for each unique bit of text. Alternatively, you can generate this image every time you display the text, but it seems like generating the image every display cycle, while simpler to implement, would be a drag on the system. Is that correct, or could I simply generate everything I need every display cycle and not suffer a performance hit?
What I think might be the best thing to do is create some persistent record of all text images. Whenever a new word or phrase is needed (or with different style, like italics or bold) then a new entry to the record is added for that surface image (or opengl texture id). This is pretty straight-forward for something like a button label, but a text field seems to be more complicated. I think the best approach for a text field would be to store in the record only those lines of the text field that are currently visible, and have a separate entry for each line.
Another idea is to persistently store the images for all of a font’s glyphs, and then generate any needed word or phrase by cobbling them together. I would hope that SDL_ttf does this for me somehow to save me all the work. I would love to be able to just call a function, passing it a string to display, its X,Y,Z coordinates, it’s color, and size, and it would just draw it to the screen with all of the complex stuff like memory management and kerning all done behind the scenes. Does anyone know if anything like that already exists? All I can currently find is functions like?TTF_RenderText_Solid?that create a surface image that I then have to manage in a complex way as stated above.
As far as the text labels that appear in 3D space, I am not sure but I think this requires the opengl method like in the?glfont.c?example instead of the pure SDL method.
Does anyone have any suggestions for me? Do you think I am thinking about things in the right manner? How have you handled rendering both non-dynamic and dynamic text with SDL_ttf?
Any insight you have on this subject would be helpful.
Thanks in advance.
-Trevor