【发布时间】:2009-04-09 13:36:13
【问题描述】:
我正在尝试将 gluOrtho2D 与 glutBitmapCharacter 一起使用,以便我可以在屏幕上渲染文本以及我的 3D 对象。但是,当我使用 glOrtho2D 时,我的 3D 对象消失了;我认为这是因为我没有将投影设置回 OpenGL/GLUT 默认值,但我不确定那是什么。
不管怎样,这是我用来渲染文本的函数:
void GlutApplication::RenderString(Point2f point, void* font, string s)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, WindowWidth, 0.0, WindowHeight);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDisable(GL_TEXTURE);
glDisable(GL_TEXTURE_2D);
glRasterPos2f(point.X, point.Y);
for (string::iterator i = s.begin(); i != s.end(); ++i)
{
glutBitmapCharacter(font, *i);
}
glEnable(GL_TEXTURE);
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
而且,渲染功能类似这样:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glLoadIdentity();
// Do some translation here.
// Draw some 3D objects.
glPopMatrix();
// For some reason, this stops the above from being rendered,
// where the camera is facing (I assume they are still being rendered).
Point2f statusPoint(10, 10);
RenderString(statusPoint, GLUT_BITMAP_9_BY_15, "Loading...");
【问题讨论】: