在OpenGL的角落显示文字

时间:2018-09-02 18:01:57

标签: c++ opengl

所以最近我试图在openGl中显示一些文本,但是我可以使其显示

void renderBitmapString(float x, float y, char* text) {
    char *c;
    glRasterPos3f(x, y, 6.0f);
    for (c = text; *c != '\0'; c++) {
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *c);
    }
}
void Draw()
    {


        glPushMatrix();

        float m_amb[] = { 1.0f, 1.0f, 1.0f, 1.0f };
        float m_dif[] = { 1.0f, 1.0f, 1.0f, 1.0f };
        float m_spe[] = { 0.0f, 0.0f, 0.0f, 1.0f };
        glMaterialfv(GL_FRONT, GL_AMBIENT, m_amb);
        glMaterialfv(GL_FRONT, GL_DIFFUSE, m_dif);
        glMaterialfv(GL_FRONT, GL_SPECULAR, m_spe);
        glBegin(GL_QUADS);

        glNormal3f(0.0f, 0.0f, 1.0f);
        glVertex3f(place.x -5.0f, place.y -5.0f, place.z + 5.0f);

        glNormal3f(0.0f, 0.0f, 1.0f);
        glVertex3f(place.x + 5.0f, place.y - 5.0f, place.z + 5.0f);

        glNormal3f(0.0f, 0.0f, 1.0f);
        glVertex3f(place.x + 5.0f, place.y + 5.0f, place.z + 5.0f);

        glNormal3f(0.0f, 0.0f, 1.0f);
        glVertex3f(place.x - 5.0f, place.y + 5.0f, place.z + 5.0f);

        glEnd();

        char text[50];
        sprintf(text, "test");
        glColor3f(1, 1, 1);
        renderBitmapString(90, 95, text);

        glEnable(GL_LIGHTING);
        glEnable(GL_CULL_FACE);
        glPopMatrix();
        glMatrixMode(GL_MODELVIEW);

    }

它应该渲染一个平面并在角落进行“测试”,但仅显示平面。 Draw()是Menu类中的公共函数,而renderBitmapString是全局函数

0 个答案:

没有答案