FreeType2: FreeType2 is a simple cross-platform font drawing engine. It is currently supported by trueType Type1 Type2. However, it is not always supporting OpenType. There are many applications using freeTGL. The famous FTGL is using freeType. I haven't used it in OpenGL high efficiency. I haven't used it. Because I don't want to use FTGL without understanding how to use freetype.
After a night reading code (my code reading ability is very poor). I finally know how to use freetype2. However, it is simple to use, I don't know how to set the bold itainly. It is mainly a simple demonstration. It is ready to make a perfect font engine. Simple introduction below.
First of all of course, it is to include the header file. The header file should include: #include [ft2build.h] #include ft_freeetype_h does not know why. Anyway, it is to include the following is the initialization code of FT2. And draw and release the code> Note that the character drawing the code is unicode. Indicates that you can draw ft2_obj font; font.init ("simsun.ttf", 32); wchat_t ptext [] = l "Pan Li Liang is a wild boar"; for (int N = 0; n / / The following is the code of ft2_obj. The primary reference NEHE's Lesson 43class ft2_obj {ft_library library; int h; ft_face face; Public: void init h); void free (); void Drawaunicode (wchar_t ch)}; void ft2_obj :: init (const char * fname, unsigned int h) {this-> h = h ; // Initialize the Fretype library .. if (ft_init_freetype (& library)) throw std :: runtime_ERROR ("ft_init_freeetypeverage); // Load a font, take default Face, generally regualer if (ft_new_face, 0, ") throw std :: runtime_ERROR (" ft_new_face failed ("The is probably a problem with your font file"); / / The size is to be multiplied by 64. This is specified. You can do it. Ft_set_char_size (Face, H << 6, H << 6, 96, 96); ft_matrix matrix; / * transformation matrix * / ft_uint glyph_index; ft_vector pen; // Set a rotation matrix float angle = -20/180. * 3.14; Matrix.xx = (ft_fixed) (COS (ANGLE) * 0x10000L); Matrix.xy = (ft_fixed) (- sin * 0x10000L); Matrix.Yx = (ft_fixed) (sin (Angle) * 0x10000L ); Matrix.yy = (ft_fixed) (COS (Angle) * 0x10000L); ft_set_transform (face, & matrix, & pen);}. / Drawing operation * * / void FT2_Obj :: DrawAUnicode (wchar_t ch) {if (FT_Load_Glyph (face, FT_Get_Char_Index (face, ch), FT_LOAD_DEFAULT)) throw std :: runtime_error ( "FT_Load_Glyph failed").; // Get a word ft_glyph glyph; if (ft_get_glyph, & glyph) throw std :: runtime_ERROR ("ft_get_glyph failed"); // Translate into bitmap ft_render_glyph (face-> glyph, ft_render_mode_normal); ft_glyph_to_bitmap (& glyph, ft_render_mode_normal, 0, 1); ft_bitmapglyph bitmap_glyph = (ft_bitmapglyph) glyph; // Take a track bitmap data ft_bitmap & bitmap = bitmap_glyph-> bitmap // Copy the bitmap data in your defined data area. This is the old thing you need to draw. Int width = bitmap.width; int Height = bitmap.ROWS; USIGNED Char * expanded_data = new usigned char [3 * width * height]; For (int J = 0; J { For (int i = 0; i { Expanded_data [3 * (i (height-j-1) * width)] = Expanded_data [3 * (i (height-j-1) * width) 1] = Expanded_data [3 * (i (height-j-1) * width) 2] = (i> = bitmap.width || j> = bitmap.rows)? 0: Bitmap.Buffer [i bitmap.width * j]; } } Void ft2_obj :: free () {ft_done_face (face); ft_done_freeetype (library);