# Why am I having these weird framerate issues with OpenGL on Windows?

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.

• You need to profile your code. Aug 10 '11 at 20:21

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.

• 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. 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. Aug 12 '11 at 7:20