使用GLUT位图字体 [英] Using GLUT bitmap fonts

查看:233
本文介绍了使用GLUT位图字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个使用简单的的OpenGL 应用转运蛋白。我不希望推出自己的字体渲染code,而不是我想用与转运蛋白船简单的位图字体。是什么让他们的工作步骤?

I'm writing a simple OpenGL application that uses GLUT. I don't want to roll my own font rendering code, instead I want to use the simple bitmap fonts that ship with GLUT. What are the steps to get them working?

推荐答案

简单的文本显示屏易于使用GLUT位图字体在OpenGL做。这些都是简单的2D字体和是的的适合显示的的您的3D环境。然而,他们是完美的,需要显示窗口上进行叠加文字。

Simple text display is easy to do in OpenGL using GLUT bitmap fonts. These are simple 2D fonts and are not suitable for display inside your 3D environment. However, they're perfect for text that needs to be overlayed on the display window.

下面是样本步骤显示埃里克·卡特曼最喜爱的报价在绿色的过剩窗口:

Here are the sample steps to display Eric Cartman's favorite quote colored in green on a GLUT window:

我们会被设置在屏幕坐标光栅位置。因此,设置了2D渲染的投影和模型视图矩阵:

We'll be setting the raster position in screen coordinates. So, setup the projection and modelview matrices for 2D rendering:

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, WIN_WIDTH, 0.0, WIN_HEIGHT);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

设置字体颜色。 (就叫这个,而不是以后。)

Set the font color. (Set this now, not later.)

glColor3f(0.0, 1.0, 0.0); // Green

设置要显示的文本窗口位置。这是通过设置在屏幕坐标光栅位置完成。窗口左下角为(0,0)。

Set the window location where the text should be displayed. This is done by setting the raster position in screen coordinates. Lower left corner of the window is (0, 0).

glRasterPos2i(10, 10);

设置字体,并使用显示字符串中的字符 glutBitmapCharacter

string s = "Respect mah authoritah!";
void * font = GLUT_BITMAP_9_BY_15;
for (string::iterator i = s.begin(); i != s.end(); ++i)
{
    char c = *i;
    glutBitmapCharacter(font, c);
}

还原回矩阵。

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glMatrixMode(GL_PROJECTION);
glPopMatrix();

这篇关于使用GLUT位图字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆