GLCanvas display() called twice (by FPSAnimator?)

Hello java-gaming board!

I’m having problems with using FPSAnimator on a GLCanvas. The problem is, it seems to be updated twice.
For example if I set the FPS to 2 like this:


Canvas canvas = new Canvas(this,glCaps);
this.add(canvas);
FPSAnimator animator = new FPSAnimator(canvas, 2);
animator.add(canvas);
animator.start();

and in the GLCanvas’ display method I write this:


timeDiff = time-tick;
tick = time;
time= System.currentTimeMillis();
System.out.println(timeDiff);

the output alternates between the expected (~500) and 2-4 !! ms. Why is it called twice? I even tried setIgnoreRepaint(true); on the canvas, doesn’t help.
Also gl.setSwapInterval(1); does not seem to have any effect on this.

What could be causing this?
Any help would be appreciated! Thanks!

Hi

At first, FPSAnimator should be used on an AWT GLCanvas, SWT GLCanvas, GLWindow or GLJPanel, not with a plain AWT Canvas. Secondly, System.currentTimeMillis() is not very accurate under Windows, you should use the usual hack to force the use of the high precision timer. Thirdly, setSwapInterval allows to enable or disable V-sync, it may be inefficient if it is not taken into account by your driver. At last, do you really want to get only 2 frames per second? I assume you use JOGL 2.0, I remind you that JOGL 1 os no more maintained.

The 2 FPS was just an example, I want 50.
That Canvas is my own class extending GLCanvas, sorry I forgot to add that.

It’s the same with System.nanoTime()

As far as I know, FPSAnimator doesn’t work very reliably on Windows or Linux. That’s why I don’t use it. Why not simply enabling v-sync? (setSwapInterval)

Ok.

The usual hack to force the use of the high precision timer under Windows affects System.nanoTime() too. I was speaking about that:
http://bugs.sun.com/view_bug.do?bug_id=6435126

Of course, it is possible to compute the time spent between two frames. That’s why v-sync should be enough.

Thank you for the replies! I’ve just found the cause of my problem:


FPSAnimator animator = new FPSAnimator(canvas, 2);
animator.add(canvas);
animator.start();

should have been:


FPSAnimator animator = new FPSAnimator(canvas, 2);
animator.start();

I’ll try v-sync thanks!

Sorry, this mistake was so obvious.