Sign in to follow this  
chiranjivi

GLFW/GLUT glutBitmapString - high CPU usage?

Recommended Posts

chiranjivi    208

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
bubu LV    1436

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this