From: stormreaver
Written: 2009-06-07 08:49:47.219079
Subject: Flicker In OpenGL

I'm writing a game to exercise my 3D game engine, and to work out its kinks. After over two years of part time development on the engine, which followed two years of part time development on what was going to be an LGPL application framework compatible with Qt, it has finally progressed far enough to be used as a game platform.

I ran into a puzzling and disturbing problem with the game, though. When the game activity reached a certain threshold, the display would flicker with a seizure-inducing madness that really hurt my head after less than a minute of viewing. I thought I had uncovered some bug in nVidia's Linux OpenGL driver, and was slightly depressed. Linux is my gaming target platform of choice, since it's very under-represented by game makers, and the notion that there were still trivial, but devastating, bugs in the OpenGL driver left me just a little depressed. Firing up any of the Quake or Unreal Tournament games, however, didn't demonstrate any flickering, so the problem must be somewhere in my engine or game. Since it was night time, I decided to put off looking into the problem until morning.

When the morning came, I had an epiphany while showering. I'm performing all my game logic (movements, collision detection, etc) and display in the repaint function, and there is no way all that can be accomplished during the vertical retrace. That means that the page swap is frequently occurring in the middle of the monitor's refresh cycle, and the display back-buffer is being erased and redrawn during that refresh cycle. Eureka! That must be the problem!

After I showered, I restructured my main game loop. I separated the game logic code from the drawing code in all of my game objects, called the update code in the main loop first, then called the paint code on all the active objects after they had all been updated. This means that only the display code is executing during the monitor refresh cycle. Now the flickering is gone, and the game display is rock solid.
You must register an account before you can reply.