Problems with FTGL display of custom TrueType fonts on iOS

Source: Internet
Author: User

I didn't expect this to be a 2-month period, and of course it was about working on and off.

FTGL is the OpenGL implementation of FreeType. I contacted FTGL initially just to practice OpenGL and write a few simple game apps. Started to try FTGL feel very simple and easy to use, do not need to be too familiar with OpenGL underlying things, so decided to formally add in their own app with FTGL display art True Type font function, it is expected to be completed soon.

Started very smoothly, seems to be working gaocheng, the result suddenly found a problem: Art font (Chinese) after the display of a number of paragraphs, the sudden rendering is not normal, always show some confusing characters, after the application logic error, to determine the FTGL library problem, this began a lengthy debugging process.

I am not familiar with OpenGL, the first two months because of another project to use a little GL, read the development of the document, after the completion of the fact is not intended to further research. Did not expect to encounter this problem now, give up and unwilling to heart, in order to debug FTGL library, must not have begun to devote some effort to start research GL.

After trying some tracking, the general reason for the error was clear: I was probably lucky enough to start off with Fttexturefont. FTGL Display the texture font, first create the face from the TTF file, read the glyph in the face based on the string that the user wants to display, and then generate bitmap, which cannot be saved in memory. So FTGL will write these bitmap into one texture of the GPU. The problem is that the texture size is always limited, so FTGL supports multiple texture, that is, once a texture is fully written, a new texture is created until the GPU memory is exhausted. And the problem I came across was that the first texture was full, and after creating a new texture, the character display began to clutter;

But I still think this question is very strange: FTGL Library is a very old library, and as far as I have checked the development version of this support multi-texture features in the 2010 when the support, is it so many years I was the first person to meet this bug? FTGL Library to see the code author level is still relatively high, this bug he did not test the discovery?

No way, the search for a few days apart from a friend in a forum mentioned a similar situation, there is no clue, and this man incredibly resigned to the problem as FTGL inherent limitations, without a little resistance to the intention, actually proposed instead of Polygonfont or Bufferfont :-(

Careful study of a few days FTGL code, horizontal look at the vertical look no problem; Is it a problem with iOS porting? Is the limitation of the iphone hardware? Or is it a cache problem? Guess the causes of all kinds of errors are proved to be unreliable; this afternoon was another bad news hit a bit after the head of a flash, suddenly thought Ah, is this?

Sure enough or FTGL. When the author adds multiple texture support, the consideration is not thoughtful, the test estimate is not done (in fact, is a very obvious bug, if the test case coverage will be exposed); Because of the presence of multiple texture, FTGL rendering needs to be switched between multiple texture , not taking into account the different characters in a string bitmap cache may be in different texture, or with the same texture rendering, naturally there will be a problem.

Consider two methods of modification, one is the use of multitexturing technology, this should sound cool, performance should be better, but to compare more time, but also the original string as a unit rendering to the character rendering, performance is not necessarily good, but the 2 lines of code to solve the problem, It is natural to do so first, and then have time to do it again:-)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.