Let ogre support Chinese [original]

zhaozj2021-02-16  54

Let ogre support Chinese [original start]

Let ogre support Chinese

0. Foreword: I am non-computer professional, with hobbies and a blood mixed into the game, the big military standing squad, the plane has not been drilled. In order to hurry, try to rebel to 3D camp, picked up "OGRE" in panic. Nowadays, there can be unknown objects such as the positive body aircraft. But I feel that this engine does not support Chinese display, but I seek high-person advice, but most of the high-person men give pointed: "Write an engine alone." He measured his own weight, I feel that "Write" this thing It's hard to do in the year. Later, I found 3Dcastle forum. After "Bug Wang", "Bug King" and "Renant ☆ Dragon Cat" guidelines, I also passed the tutorial left by the master "renwind", and I misunderstand myself, I have changed my own support, excited. I want to write some things to write a point. 1. Preparation "BUG King" has enabled the Chinese support in Direct 7.0 through WinAPI, and some master said that this is not very efficient, and because I am basically not familiar with WinApi, I will give up this method. It is also the way to display directly through the map. After all, the OGRE itself is also used, and it is better to support the bitmap font in addition to the normal "TTF" font (in fact "TTF" in the engine. Ogre :: font :: createtetextureFromfont () Convert into a bitmap), basically do a big picture, then draw the Chinese characters, you can read it directly, the problem will become - how Looking for this big picture. Fortunately, the developers of GBA games have found a good text source and acquisition method. Get close to 9000 words through Jinshan 16 * 16-point gallery, then read and write the monochrome bitmap of 2048 * 2048 On, convert to "PNG" format picture only 221K. 2. Before the basic knowledge modifies the engine, we must first know how the OGRE shows the font. Ogre itself is very normally beautiful, and it is easy to find class and related functions about display text. It is mainly to see how the bitmap font is displayed on the screen. (1) Reading of the font. There are two classes related to this feature, one is OGRE :: FontManager class, responsible for analyzing font information (* .fontdef) files. Then build an OGRE :: font class with Builder mode. The most important data in the Font class is the four arrays of MTEXCOORDS_U1, MTEXCOORDS_U2, MTEXCOORDS_V1, MTEXCOORDS_V2, which are used to store different texts corresponding to texture coordinates on the image. However, the array size is not enough to store 9,000 Chinese characters, and it is necessary to change. (2) The display of the font. It seems that there is more in the font display. It is Ogre :: textareaguielement class, but it seems to be other, we only look at this here, it is estimated that other things are also small. Look at the function of the only and display font is void textareaGuielement :: updateGeElelelement :: UpdateGeometry (), basically, based on the string on the screen, get the corresponding map coordinates and textures in the OGRE :: Font class, then Painting, the truth is not very difficult. 3. Surgery target locks to OGRE :: Font, Ogre :: FONTMANAGER, OGRE :: TextAreaguielement three classes, back up all files! (1) OGRE :: font class. The first is that the amount of the array of stored text map coordinates is not enough. It is defined to define - wide character set (1024 - 32), ASCII (256 - 32). How can this size enough for me to enter the 9,000-character army into, and the sure is changed (9030 - 32).

There is also the id and get text map IDs are all char types, 256 IDs are not assigned to Chinese characters, it seems to be changed to unsigned long-shaped (in fact, INT is also 32 digits on most machines, but long is fixed 32 The type of bit, feels in the style. (2) OGRE :: FontManager class. The method of parsing the map coordinates from the script file is based on a single character, to support Chinese characters, and change to simultaneous analysis of Int. A Chinese word correspondence is his location code 161 (the first 160 leaves it for half-wing words). (3) OGRE :: TextAreaguielement class. This is relatively troublesome, he wants to distinguish the half-width and Chinese from the string. Add a std :: vector CAPTION to store the resolved result. Add the following lines. Std :: Vector Caption; unsigned char ntemp; string :: itrator it = mcAption.begin (); for (; it! = mcAption.end (); it) {ix (unsigned char (* IT) <= 160) // If it is half angle {caption.push_back (unsigned char) * it);} else // Handling full-corner character {ntemp = (unsigned char); it; if (IT = = mcAption.end ()) BREAK; // The following is the formula of the location code 161. CAPTION.PUSH_BACK ((94 * (NTEMP-0xA0-1) ((unsigned char) (* it) -0xa0-1)) 161);}} then all about McAption replace it with CAPTION is OK . 4. result. Chinese successfully supported Chinese in OpenGL and DX9.0, but there was an operation error in DX7.0, and the specific questions were not clear, but also high-end advice. Because the font itself, the text is very flat, and the sure is changed to change OGRE :: font, OGRE :: FontManager two classes, and the project is supported in the script to modify the exquisite proportional factor, when this value is set to 0.8 It's better to look at it. Related files Chinese.fontdef // Font information files in resource files plus font.png // Font Image placed in resource file plus

Ogrefont.cppogrefont.hogrefontManager.cppogretextAreaguielement.cpp // The above file overrides the same name file to back up

This is changed on the OGRE-Win32-V0-13-1, please go to OGRE-WIN32-V0-13-1.zip Download

The Chinese font name is called Chinese, and it will be a Chinese game in the future!

Free wager QQ: 1850070

转载请注明原文地址:https://www.9cbs.com/read-23505.html

New Post(0)