# High CPU usage on Pong clone

I just made my first game, a clone of Pong, using OpenGL and C++. But its using ~50% of the CPU, which I guess is very high for a game like this. How can I improve that? Can you please look up my code and tell me what all things I am doing wrong? Any feedback is welcome.

http://pastebin.com/L5zE3axh

http://pastebin.com/rMJ6PG9k

Also it would be extremely helpful if you give some general points on how to develop games in OpenGL efficiently..

EDIT 1:

I forced VSync on from CCC, and now the game just shows ~5% CPU usage, except when my own wait() method is called (my fault). I can solve that...but now another problem has come, the game feels very choppy and its not smooth after forcing on VSync. Maybe tearing because of single buffering?

Any ideas?

EDIT 2:

Was calling the display callback twice from my idle function, using display() and glutPostRedisplay()! Also, changed the mode to GLUT_DOUBLE, now Fraps works on it..

One more thing! This game is working fine with VSync on (or forced) at 60fps.. but when I turn off VSync, it goes too fast. Do I have an option to turn on VSync? Or is any any other way?

• Welcome to GDSE. Questions that require people to look at large pastes of code and essentially find problems for you is not a good fit for this site. When you identify the problem, you can ask the specific question and we can assist you. – Justin Skiles Oct 22 '12 at 11:37
• Will keep that in mind! – Max Oct 22 '12 at 12:02
• @JustinSkiles I just edited my question, its now more specific.. can you have a look a it please? – Max Oct 22 '12 at 20:14
• hi max, your Edit2 "it goes too fast when turn off VSync" is because your gameplay depends on how fast your framerate is. see this question and in particular the Fix Your Timestep article – Jimmy Oct 22 '12 at 22:55
• @Jimmy Thank you! I solved it by rendering a frame, then Sleep(1ms) for the rest of the time, until the total time is 1000/FPS milliseconds :) – Max Oct 23 '12 at 6:12

 boost::this_thread::sleep( boost::posix_time::seconds(1) );