不管是DirectX9还是GDI,处理文本都是很方便的,但是在OpenGL中,我似乎没找到很方便的处理方式,在网上搜了一下,结果如下:
在http://www.opengl.org/resources/features/fontsurvey/ 里说,处理OpenGL处理文本有三种方式,我试用了一种。
这里要用到glut(把glut下载下来,把头文件glut.h放到...\PlatformSDK\Include\gl下,把两个lib放到...\PlatformSDK\Lib,把两个dll放到system32下)
void
*
bitmap_fonts[
7
]
=
{
GLUT_BITMAP_9_BY_15,
GLUT_BITMAP_8_BY_13,
GLUT_BITMAP_TIMES_ROMAN_10,
GLUT_BITMAP_TIMES_ROMAN_24,
GLUT_BITMAP_HELVETICA_10,
GLUT_BITMAP_HELVETICA_12,
GLUT_BITMAP_HELVETICA_18
}
;
print_bitmap_string(
void
*
font,
const
char
*
s)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (s && strlen(s)) {
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
while (*s) {
glutBitmapCharacter(font, *s);
s++;
}
}
}
int
CDGL::TextOut(
int
x,
int
y,
const
char
*
cstr,
int
color)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
glRasterPos2f(x, y);
print_bitmap_string(bitmap_fonts[4], cstr);
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return 1;
}
我在我的Plot3D项目里试用,能够用,尽管还不是很方便。