OpenGL + FTGL. Falling productivity

Started by
5 comments, last by globalhost 8 years, 1 month ago

Main function


int main()
{
    init();
    while (!glfwWindowShouldClose(window))
    {
        glClear(GL_COLOR_BUFFER_BIT);
        currentTime = glfwGetTime(); ++frames;
        if (currentTime - lastTime >= 1.0) { fps = frames; frames = 0; lastTime += 1.0; }
        glPushAttrib(GL_TEXTURE_BIT);
        glColor3f(1.0f,1.0f,1.0f);
        for (int j = 0; j < 16; ++j)
        for (int i = 0; i < 12; ++i)
            font->Render(std::to_string(fps).c_str(), -1, FTPoint(i*60, height - j*30 - font->LineHeight(), 0));
        glPopAttrib();
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwDestroyWindow(window);
    glfwTerminate();
}

Create font


FTFont *font;
font = new FTTextureFont("fonts/Linux Biolinum/LinBiolinum_R.otf");
font->FaceSize(20);

The problem

As you can see in the screenshots, with an increase in the number of inscriptions fps drop occurs at times!

Advertisement

So...


Inscriptions =   1, Time per frame = 0.42ms, Time per inscription = 420?s
Inscriptions =  15, Time per frame = 0.82ms, Time per inscription = 55?s
Inscriptions =  56, Time per frame = 2.04ms, Time per inscription = 37?s
Inscriptions = 192, Time per frame = 5.81ms, Time per inscription = 30?s

Performance is increasing (i.e. time per inscription is decreasing) as you draw more of them.

So you do more work and it takes longer. I fail to see the problem.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

It's very slow. On my video card Radeon HD 7870 can be 172 frames. How many frames will be on the graphics card released in 2000 yr? Scary to imagine.


font->Render(std::to_string(fps).c_str(), -1, FTPoint(i*60, height - j*30 - font->LineHeight(), 0));

There is a few parts of that line that you probably only need to do once. (to_string, LineHeight. You could probably make the FTPoint once and add an offset each time rather than recreating it. I honestly wouldn't worry unless it is actually an issue, 172 fps sounds great to me and as has been pointed out it is actually getting more efficient the more you do.

I don't know how FTGL works but looking it up and it suggests it can render fonts using a variety of methods, you could make sure it is using the texture map method as that is probably the most efficient method (which it is probably using from your code - glPushAttrib(GL_TEXTURE_BIT)).

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

It's very slow. On my video card Radeon HD 7870 can be 172 frames. How many frames will be on the graphics card released in 2000 yr? Scary to imagine.

It might have nothing to do with the video card.
Maybe your video card draws all that text in 0.1ms, but your CPU is taking 5ms per loop of that code...

Good. So the optimization is not required. Thank you all for your help!

This topic is closed to new replies.

Advertisement