Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm using OpenGL on windows (have been for a while now), and I've come across a strange issue.

Once every so often, the rate at which frames are presented on the screen drops to roughly 10 fps. However, my framerate counter stays at the usual framerate (2000fps in the menu, 300fps in game).

My framerate counter is based on the time between draw calls, so the graphics card is definitly rendering 2000 frames a second.

What is the problem? How can I fix it?

EDIT: I forgot to mention, this only happens when running in windowed mode.

share|improve this question
2  
You need to profile your code. –  Maik Semder Aug 10 '11 at 20:21
add comment

1 Answer

Definitely rendering at 2000 fps? Nah, I guess you're measuring elapsed frame time like usual, which means you're measuring time it took for the driver to generate the GPU commands and not the time it took the GPU to actually render the frame. After a while CPU waits for the GPU to catch up and it shows as spike in frame time.

As for possible reasons... Well, it could be everything starting from bad hardware or drivers and ending with bad code. Try to do the simplest graphics call possible:

while(1) 
{
  glXSwapBuffers();
  // This should use QueryPerformanceCounter/QueryPerformanceFrequency
  CalculateElapsedTime(); 
}

And then see if it still spikes. If it doesn't, add a code until it spikes again, and if it does, then it's a technical issue. For additional confirmation enable VSync and see if spiking rate changes. Launch a HWMonitor and see if temperatures and voltages are OK, check System Event Log, use GPUView with xperf, maybe try to somehow debug it with gDEBugger, change drivers, change hardware... Possibilities are endless :)

EDIT: Maik Semder actually gave a better advice :) Your problem may be completely unrelated to the video at all, so check what you're doing every frame, look at the GC, wrap different OpenGL calls with QueryPerformanceCounter.

share|improve this answer
    
Definitly 2000 fps. I mesure the time it takes for the CPU to issue the commands too. It takes the GPU 0.4ms to render, and the CPU 0.06ms to issue the drawing commands. I should not that this problem doesn't happen in fullscreen. –  Hannesh Aug 11 '11 at 9:49
    
Sounds esoteric. If your fps drop, and you counter says its still 2000 fps, either fps didn't drop or your counter is wrong :) Maybe there is some third possibility, but it's hard to guess without looking at your code and pc. Windowed mode differs from fullscreen in it's need to render both your graphics and the other desktop windows, also it will never have vsync on. Disable all background apps if you haven't tried it yet, maybe some of them is interfering in some way. Back to the GPU theory, you can launch GPU-Z and look at GPU utilization at the moment of fps spike, look for a drop. –  Vigil Aug 12 '11 at 7:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.