glutBitmapCharacter doesn't work with GLFW?

Hey guys,

I’ve been looking up literally everywhere and everything I could about glutBitmapCharacter() and nothing seems to help me. I use GLFW in my code for creating the window and basically for everything besides also but I decided to use freeglut for rendering text onto my 3D game (as an overlay text, so 2D on the screen)… the code compiles and runs correctly (e.g. skybox and objects are visible…) however no text has been displayed. Any ideas why? I paste my code here:

    void display()
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0.0, WindowWidth, 0.0, WindowHeight, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glDisable(GL_DEPTH_TEST);

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

    std::string s = "Some text";
    void* font = GLUT_BITMAP_TIMES_ROMAN_24;

    for (std::string::iterator i = s.begin(); i != s.end(); ++i)
    {
        char c = *i;
        glColor3d(1.0, 0.0, 0.0);
        glutBitmapCharacter(font, c);
    }

    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glEnable(GL_DEPTH_TEST);
}



int main(int argc, char** argv)
{
    glfwInit();
    glutInit(&argc, argv);
    GLFWwindow* window = glfwCreateWindow(WindowWidth, WindowHeight, "The Maze Game", nullptr, nullptr);
 glfwMakeContextCurrent(window);
//.....
// shaders, textures, VAOs and VBOs created ...


    while (!glfwWindowShouldClose(window)) {
//...
glfwPollEvents();
 glClearColor(53.0f / 255.0f, 81.0f / 255.0f, 92.0f / 255.0f, 0.0f); // glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
display();
//...
// skybox, object drawn here

glfwSwapBuffers(window);
}
//...
}

Call glGetError before and after glutBitmapCharacter; does it report an error?

Also, according to the comment, the skybox is drawn afterwards, which might be obscuring it. Does it work if you draw the text last?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.