OpenGL文字绘制(OpenGL text rendering)
OpenGL文字绘制(OpenGL text rendering)
OpenGL text output, Tuesday, 05 2009, 13:47, 26
OpenGL is a 3D graphical interface, where text is displayed differently from text displayed in a Windows graphic environment. On OpenGL, text requires some special methods, because there are flat text and 3D text on the 3D graphical interface. Especially the display of Chinese characters is more troublesome, because the bottom of the OpenGL does not support the double byte encoding of Chinese characters. The solution in this article can be implemented in three different ways of text display:
Regular text
This text display is an efficient way to draw fonts in bitmaps. It uses a graphic method, so it shows flat text. Unfortunately, this flat text display method can not support Chinese characters.
3D text
Text in OpenGL can also be displayed as a 3D object. This 3D text can scale, rotate, map, and have all the properties of other 3D objects. We also added special processing to the double byte Chinese characters in the program, so it can also display stereoscopic Chinese characters.
Flat Chinese characters
OpenGL flat Chinese characters. The basic principle is: build a certain font equipment scene within the system (MDC), GDI will form a monochrome bitmap in the text equipment in the scene, and then the OpenGL plane bitmap display function glBitmap (...) Show the text.
Here is the source code:
//GLFont.h----------------------------------------------------------------------
Interface for the CGLFont class. / / GLFont.h:
#if! Defined (AFX_GLFONT_H__88F1F000_50F5_452A_B95E_60ED83712FA5__INCLUDED_)
#define AFX_GLFONT_H__88F1F000_50F5_452A_B95E_60ED83712FA5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif / _MSC_VER > 1000
Class CGLFont
{
Public:
Void, entext (float, x, float, y, LPCTSTR, STR, HFONT, hFont, float, R, float, G, float, B);
Void c3dtext (LPCTSTR, STR, HFONT, hFont, float, Z);
Void Printfc3d (LPCTSTR, strText, HFONT, hFont, float, z=0.05f);
Void, Printftext (int, x, int, y, LPCTS