• Advertisement
Sign in to follow this  

GLFW/GLUT glutBitmapString - high CPU usage?

This topic is 1663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm messing around with a simple game using GLFW with freeglut to render text. I noticed that it was using far more CPU than I would have expected, and after commenting out various bits of code I realised it was the (minimal) GUI that was causing the problem.

 

Every frame, the game writes about half a dozen strings to the screen ("SCORE: 3000", "LIVES: 5", that kind of thing). If I disable this overlay, the CPU usage drops to about 2-5%. If I re-enable it, CPU usage skyrockets to about 40-50% and the game visibly slows down.

 

This is the code I'm using to render text:

void draw_string(int x, int y, string output) {
    glRasterPos2i(x, y);
    glutBitmapString(GLUT_BITMAP_HELVETICA_12, (const unsigned char*)output.c_str());
}

Am I doing something really stupid here without realising it? I cannot understand why I can render thousands of primitives per frame and OpenGL doesn't even blink, but as soon as I try to render a handful of lines of text my processor begins to buckle under the strain (and it's a 3.4GHz quad, it's not like it's a netbook or whatever).

 

Why is doing something that appears to be fairly simple causing such massive demands of my CPU?

 

Thanks in advance for any responses

Share this post


Link to post
Share on other sites
Advertisement

glutBitmapString internally uses glBitmap function that is not hardware accelerated on modern hardware. So using this function will make CPU do all the rendering.

 

I suggest you to look into rendering fonts using texture. Look here for generating texure: http://www.angelcode.com/products/bmfont/

Or you can render fonts directly from truetype font file: https://code.google.com/p/freetype-gl/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement