Home > Back-end >  Consult a demon elder brother and you, can display the Chinese characters for openGL code
Consult a demon elder brother and you, can display the Chinese characters for openGL code

Time:10-04

Demon elder brother, can display the Chinese characters for openGL code

CodePudding user response:

Direct output text on a Panel with OpenGL

CodePudding user response:

OpenGL display text - Chinese characters
http://blog.csdn.net/zhouhangjay/article/details/6715332

CodePudding user response:

refer to the second floor songhtao response:
OpenGL display text - Chinese characters
http://blog.csdn.net/zhouhangjay/article/details/6715332

Would you help me with BC debugging the

CodePudding user response:

No one on Sunday?

CodePudding user response:

# include & lt; GL/glut. H>
# include & lt; Windows. H>
# define MAX_CHAR 128

Void drawString (const char * STR) {
Static int isFirstCall=1;
The static GLuint lists;
If (isFirstCall) {//if it is the first call, performs initialization
//for each ASCII characters to create a display list
IsFirstCall=0;
//application MAX_CHAR consecutive number display list
Lists=glGenLists (MAX_CHAR);
//put every character of drawing commands to the corresponding display list
WglUseFontBitmaps (wglGetCurrentDC (), and 0, MAX_CHAR, lists).
}
//call each character corresponding to the display list, draw each character
For (; * STR!='\ 0'; + + STR)
GlCallList (lists + * STR);
}

Void drawCNString (const char * STR) {
int len, i;
Would be * wstring;
HDC HDC=wglGetCurrentDC ();
GLuint list=glGenLists (1);
//calculate the number of characters
//if it's a double-byte characters (Chinese characters), two bytes is a character
//otherwise a byte count one character
Len=0;
for(i=0; STR [I]!='\ 0'; + + I)
{
If (IsDBCSLeadByte (STR [I]))
+ + I;
+ + len.
}
//will be mixed character into wide character
Wstring=(*) would be malloc sizeof (len (+ 1) * (would));
MultiByteToWideChar (CP_ACP MB_PRECOMPOSED, STR, 1, wstring, len);
Wstring [len]=L '\ 0';
//output one character
for(i=0; i{
WglUseFontBitmapsW (hDC, wstring [I], 1, list);
GlCallList (list);
}
//recycle all temporary resources
Free (wstring);
GlDeleteLists (list 1);
}

Void selectFont (int size, int charset, const char * face) {
HFONT HFONT=CreateFontA (size, 0, 0, 0, FW_MEDIUM, 0, 0, 0,
Charset, OUT_DEFAULT_PRECIS CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, face);
HFONT hOldFont=(HFONT) SelectObject (wglGetCurrentDC (), HFONT);
DeleteObject (hOldFont);
}

Void the display (void) {
GlClear (GL_COLOR_BUFFER_BIT);
SelectFont (48, ANSI_CHARSET, "Comic Sans MS");
GlColor3f (0.0 1.0 f, 0.0 f, f);
GlRasterPos2f (0.4 0.7 f, f);
DrawString (" Hello, World!" );
SelectFont (48, GB2312_CHARSET, "regular script _GB2312");
GlColor3f (0.0 1.0 f, 1.0 f, f);
GlRasterPos2f (0.7 f, 0.1 f);
DrawCNString (" contemporary Chinese characters ");
SelectFont (48, DEFAULT_CHARSET, "Chinese imitation song dynasty style typeface");
GlColor3f (0.0 0.0 f, 1.0 f, f);
GlRasterPos2f (0.7 f, 0.6 f);
DrawCNString (" traditional Chinese characters ");
GlutSwapBuffers ();
}
Void init (void)
{
GlClearColor (0.0, 0.0, 0.0, 0.0);/* select clearing olor */
//glMatrixMode (GL_PROJECTION);/* the initialize viewing values */
//glLoadIdentity ();
//glOrtho (1.0, 1.0, 1.0, 1.0, 1.0, 1.0);//attention of the visual range and geometric center
}
Int main (int arg c, char * * argv)
{
GlutInit (& amp; Arg c, argv);
GlutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
GlutInitWindowSize (500, 500);//to glutInitWindowSize (250, 250); Can be seen that transform is only in proportion to the size of the object change
GlutInitWindowPosition (100, 100);
GlutCreateWindow (" First ");
The init ();
GlutDisplayFunc (display);
GlutMainLoop ();
Return 0;
}

That hello brother help with CB debugged, debugging, and the teacher there is an error

CodePudding user response:

To be unfamiliar with OpenGL, you tell me what the mistake?
  • Related