Jump to content
  • Advertisement
Sign in to follow this  
crslimin

OpenGL How to display chinese characters with wglUseFontOutlines?

This topic is 4762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there anyone has experience in using wglUseFontOutlines or Do you have any sample code about draw chinese characters with OpenGL? I am using wglUseFontOutlines, glCallLists, but it doesn't work. Please see my program(modified from nehe program) below: GLvoid BuildFont(GLvoid) // Build Our Bitmap Font { HFONT font; // Windows Font ID base = glGenLists(256); // Storage For 256 Characters font = CreateFont( -12, // Height Of Font 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout CHINESEBIG5_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch " 宋体"); // Font Name SelectObject(hDC, font); // Selects The Font We Created wglUseFontOutlines( hDC, // Select The Current DC 0, // Starting Character 255, // Number Of Display Lists To Build base, // Starting Display Lists 0.0f, // Deviation From The True Outlines 0.2f, // Font Thickness In The Z Direction WGL_FONT_POLYGONS, // Use Polygons, Not Lines gmf); } GLvoid glPrint(const char *fmt, ...) // Custom GL "Print" Routine { float length=0; // Used To Find The Length Of The Text char text[256]; // Holds Our String va_list ap; // Pointer To List Of Arguments if (fmt == NULL) // If There's No Text return; // Do Nothing va_start(ap, fmt); // Parses The String For Variables vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers va_end(ap); // Results Are Stored In Text for (unsigned int loop=0;loop<(strlen(text));loop++) // Loop To Find Text Length { length+=gmf[text[loop]].gmfCellIncX; // Increase Length By Each Characters Width } glTranslatef(-length/2,0.0f, 0.0f); // Center Our Text On The Screen glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits glListBase(base); // Sets The Base Character to 0 glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text glPopAttrib(); } int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Reset The Current Modelview Matrix glTranslatef(0.0f,0.0f,-1.0f); // Move One Unit Into The Screen glScalef(0.04, 0.04, 0.04); glRotatef(-20.0f,0.0f,1.0f,0.0f); // Rotate On The Y Axis // Pulsing Colors Based On Text Position glColor3f(1.0f,0.0f,0.5f); glPrint("Active OpenGL Text With NeHe abc中文def-%7.2f", 10.0); // Print GL Text To The Screen return TRUE; // Everything Went OK } After runing the program, I can see English characters only, no chinese characters. It will be grateful if you can let me know what it is wrong in the program.

Share this post


Link to post
Share on other sites
Advertisement
I'm rather ignorant on the subject, but surely there's more than one byte to a character in any Chinese encoding? And won't there be more than 255 glyphs? You're only making display lists for the first 255, which are probably just the normal ASCII ones.

Since you're using a char array, I'm guessing you're using UTF-8. If you are, then even if you had enough display lists, you'd still need to redo your glPrint to handle UTF-8 correctly.

Even if the WGL functions can do it, I'd see about using FreeType as Promit suggests. It's generally more featureful, and it'll be useful knowledge to have if you ever need to develop for a platform which doesn't have WGL. Google says you might like to look here and here, amongst other places.

Share this post


Link to post
Share on other sites
Having examined the source on the other end of the links I posted, it looks like neither of them are exactly what you want. NeHe's still can't cope with UCS2 or UTF-8 strings, and the other will do Unicode if you want to link it with Qt. Unless another library turns up which can do Unicode text in OpenGL using FreeType, I'd go with modifying NeHe's, since it's probably the easier starting point.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!