During the past month I have worked on implementing support for East Asian languages. Adding support for Chinese was one of the most requested features after release on Steam! The main problem was that SpaceEngine used 8-bit text strings internally, so it was only able to support ANSI encoding for text in different languages. This means a limit of 256 characters at most (even less in practice, because there are some reserved codes, and English letters and digits are also reserved and cannot be changed to local characters). This is obviously too low of a number for Chinese – the current implementation uses about 1300 characters. So support of Unicode was needed. Unicode is a set of encoding schemes, one of which is 16-bit text strings (used everywhere in Windows internally). The 16-bit strings are able to support up to 65536 characters – enough for Chinese!

Another problem was that SpaceEngine used texture-based fonts, 3 of them for each ANSI code page (small, small with shadows, and large). Creating the font texture for Chinese manually would be hell, so the first thing I did is implement TTF font rendering. TTF is a vector font format used by almost all operating systems to draw text. TTF files describing thousands of Asian characters are very small, only a few megabytes. With the freetype library for C++, working with TTF fonts is easy: it has a function to draw a requested glyph into a memory buffer with specified size. That buffer then can be copied to an OpenGL texture to use in the engine. For more optimal rendering, a single texture must be used for all glyphs, so I implemented a simple texture atlas building algorithm, with the ability to grow the texture if it runs out of free space. I.e. if the needed glyph is not represented in the texture, SE will just add it there. So SE can now display all languages simultaneously.

I also got rid of different textures for different font sizes: all glyphs are added to the same texture. The shadow effect (which makes text better looking over bright backgrounds) is easily added by the font rendering shader.

Example generated font texture for Chinese:

Compare it with the font texture generated for English (all European languages can easily fit into this 512*512 texture, including all font sizes):

After this, the easy part ended. I had to update almost every single source code file where 8-bit strings are used to 16-bit strings to support 16-bit Unicode (UTF-16). This is not as easy as “find & replace all”: some data structures must still use 8-bit strings and 8-bit data fields (the char data type in C/C++). It was long and boring manual work, which took 4-5 days. But after finishing, I converted SE localization files to Unicode (UTF-8), and started debugging, which took another 2 weeks.

I also updated the language selection menu: it now displays the country flag and the self-name (autonym) of a language (see the top image of this post). At the first launch after the update, SpaceEngine should change its language automatically to the language your Steam client is using.

Today I released Build 0.990.37.1690 to the beta branch. It features traditional and simplified Chinese localizations, made by “xingqiu” and “Lidi” (“Freeman”), and a Japanese localization, made by “Luna Knowledge” (“alpha0106” from the old forum) in 2015 and updated now. Yeah, it took too long for me to implement Unicode support!

Other changes in this build:

Build 0.990.37.1690 While exporting planet textures, clouds transparency is not saved into a separate file Ability to specify custom subfolder to save video file/frames in the video capture dialog Fixed bug when some terrain node textures didn’t generated Fixed bug with terrain not generating while recording video Opposition effect on planetary rings; parameters are added to planet scripts and editor Unicode support:

— All localizations updated to UTF-8 encoding

— Texture fonts replaced with ttf fonts

— Added traditional Chinese, simplified Chinese and Japanese localizations

— In language selection menu, country flags and full names of localizations are displayed Apollo 11 ‘Eagle’ Lunar module model on the Moon surface Fixed bug with UI window stuck in moving mode when was closed by hotkey before releasing the left mouse button Fixed selecting of stars in star clusters and nebulae Mouse click in the text input field moves cursor to the nearest character Fixed arrow button of volumetrics resolution sliders

I also updated the adding localizations manual, in case someone would like to add a translation to their own language, or update obsolete translations which were in SE 0.980, but were excluded from 0.990. They are Hungarian, Indonesian, Norwegian, European Portuguese, Brazilian Portuguese, Romanian, Slovak and Turkish.

Upd: this update was released on August 1.

Discuss this post on the forum.