使用FtGl库

#include #include #define GLUT_DISABLE_ATEXIT_HACK #include #include #pragma comment(lib,"Font_debug.lib") FTGLPixmapFont *freeTypeFont = NULL; void init(void) { glShadeModel(GL_SMOOTH); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); char filePath[256]={0}; sprintf(filePath, "C://WINDOWS//Fonts//simhei.ttf"); freeTypeFont = new FTGLPixmapFont(filePath); if(freeTypeFont == NULL) { char buf[] = "Font C://WINDOWS//Fonts//simhei.ttf can not be fond./r/n"; printf("%s", buf); exit(0); } else { freeTypeFont->FaceSize(16); freeTypeFont->CharMap(ft_encoding_unicode); } } wchar_t str[128]=L"FreeType 中文输出测试"; void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 10.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor4f(1.0f, 0.0f, 0.0f, 1.0f); glRasterPos2f(0.2, 0.5); freeTypeFont->Render(str); glutSwapBuffers(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective (45.0, (GLdouble)w/(GLdouble)h, 1.0, 10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glutPostRedisplay(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (600, 600); glutInitWindowPosition (100, 100); glutCreateWindow("中文输出测试"); init(); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMainLoop(); return 0; }

你可能感兴趣的:(开源软件)