I recently learned from HGE to write a 2D game engine and accidentally saw a simple Chinese font solution. Let's take a look at it first.
HGE itself does not support Chinese display, so I use the solution provided by the subtle balance.
The Code provided by the great god contains the gfxfont. h and gfxfont. cpp files. You only need to add these two files to the project.
However, I am too lazy. To avoid adding two files to the project every time, I moved all the CPP Code to the. h file without authorization and made some minor changes.
In this way, you only need to introduce gfxfont. H into the project. Of course, I put this gfxfont. h directly into the include folder of HGE, so that I can directly
Use # include <gfxfont. h> to reference this file. (Of course, add the include directory of HGE to the project first .)
The following is the source code of the gfxfont. h file:
Gfxfont. h # ifndef gdifont_h # define gdifont_h # include
Copy the source code, save it as gfxfont. H, and introduce it to the project.
Usage:
This method is a new solution to support Chinese display in the HGE project.
This solution does not need to rely on any image fonts and supports a wide range of display methods.
The usage is simple. You only need to perform the following steps:
1. Include the "gfxfont. H" header file.
2. Create a font pointer: gfxfont * fontspr = new gfxfont (font name, font size, bold, italic, smooth mode );
3. text color: fontspr-> setcolor (argb );
3. text rendering: fontspr-> Print (coordinate X, coordinate Y, text content );
4. Destroy Font: when the program ends, delete fontspr is used to destroy the font.
--- Subtle balance