Jump to content

  • Log In with Google      Sign In   
  • Create Account


GLFW/GLUT glutBitmapString - high CPU usage?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 chiranjivi   Members   -  Reputation: 197

Like
0Likes
Like

Posted 01 July 2013 - 02:15 PM

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



Sponsor:

#2 Martins Mozeiko   Crossbones+   -  Reputation: 1422

Like
2Likes
Like

Posted 01 July 2013 - 02:55 PM

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/



#3 chiranjivi   Members   -  Reputation: 197

Like
0Likes
Like

Posted 03 July 2013 - 08:00 AM

Martins,

Thanks for your reply, I will look into the alternatives you recommended.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS