我正在尝试使用 openGL 绘制文本,该文本将显示在 kinect 相机图像上的窗口中。该程序可以很好地绘制正方形和其他形状,但是当我调用该方法来绘制文本时,它会崩溃。它似乎正在崩溃
glutStrokeCharacter(font, c);
其他一切正常,当我只注释掉这一行时,程序仍然运行良好。下面是我如何尝试绘制文本的代码片段。
void Button::DrawSquare(bool selected)
{
glEnable( GL_POINT_SMOOTH );
glLineWidth(7);
if (selected == true) glColor3f(0,1,0);
else glColor3f((123.0/255.0f),(205/255.0f),(237.0/255.0f));
glBegin(GL_LINE_LOOP);
glVertex2f(X, Y);
glVertex2f(X+length, Y);
glVertex2f(X+length, Y+width);
glVertex2f(X, Y+width);
glEnd();
glLineWidth(3);
glColor3f(0,0,0);
glBegin(GL_LINE_LOOP);
glVertex2f(X, Y);
glVertex2f(X+length, Y);
glVertex2f(X+length, Y+width);
glVertex2f(X, Y+width);
glEnd();
glLineWidth(4);
//Start drawing text
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
if (selected == true) glColor3f(0,1,0);
else glColor3f(1,1,0);
void *font = GLUT_BITMAP_TIMES_ROMAN_10;
glRasterPos2i(this->X+15,this->Y+35);
string s(*this->trackname);
for (string::iterator i = s.begin(); i != s.end(); ++i)
{
char c = *i;
glutStrokeCharacter(font, c);// <<-- Line that gives error
}
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glColor3f(255,255,255);
}
在文本之前绘制正方形效果很好。