the best way to render in opengl is still relying on vsync. If you want to render in a lower framerate than your refresh rate and it is not that important for you to to renter in a custom framerate you could use this trick:
drawable.setAutoSwapBufferMode(false);
drawable.getGL() .setSwapInterval(1); // enable vsync
final int skip = 1;
new Thread("Bienator's Animator") {
@Override
public void run() {
System.out.println("start");
while(true) {
drawable.display();
drawable.swapBuffers();
for(int i = 0; i < skip; i++) {
drawable.swapBuffers();
}
}
}
}.start();
What does it do?
1. it enables sync
2. renders fast as possible in a while loop
3. but it calls swapBuffers() more as needed (thats the trick, since this will block when vsync is on)
this is the most accurate way (from a timing point of view) to render with
targetFPS = refreshRate/skip. Swapping buffers should be relative inexpensive. In worst case the driver would do active waiting on the CPU - but i don't believe that someone would implement vsync in this way. (works perfectly on a geforce, haven't tested it yet on amd hw)
for example with a refresh rate of 60Hz the animator above can easily fix the framerate to 60,30,20,15,12...
possible issues:
-arcane intel chips do not support vsync
-tripple buffers are enabled
-vsynch disabled in driver configuration