From 59c6358dbcfbb70e3796fef5d3063ffb9491ae8b Mon Sep 17 00:00:00 2001 From: Xerxes Rånby Date: Thu, 20 Sep 2012 13:20:13 +0200 Subject: Improve frame rendering smoothness in src/demos/es2/RawGL2ES2demo.java by using Animator instead of FPSAnimator. Calculate the time deltas for the theta movement using milliseconds passed between two frames. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Xerxes Rånby --- src/demos/es2/RawGL2ES2demo.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/demos/es2/RawGL2ES2demo.java b/src/demos/es2/RawGL2ES2demo.java index 6cccc6f..4423c33 100644 --- a/src/demos/es2/RawGL2ES2demo.java +++ b/src/demos/es2/RawGL2ES2demo.java @@ -222,8 +222,9 @@ static final String fragmentShader = * yet it do take some extra lines of code to setup. * */ - private double theta=0; - private double s=0; + private double t0 = System.currentTimeMillis(); + private double theta; + private double s; private static int width=1920; private static int height=1080; @@ -281,7 +282,7 @@ static final String fragmentShader = // GLWindow will call the GLEventListener init, reshape, display and dispose // functions when needed. glWindow.addGLEventListener(new RawGL2ES2demo() /* GLEventListener */); - FPSAnimator animator = new FPSAnimator(glWindow,60); + Animator animator = new Animator(glWindow); animator.add(glWindow); animator.start(); } @@ -374,7 +375,9 @@ static final String fragmentShader = public void display(GLAutoDrawable drawable) { // Update variables used in animation - theta += 0.08; + double t1 = System.currentTimeMillis(); + theta += (t1-t0)*0.005f; + t0 = t1; s = Math.sin(theta); // Get gl -- cgit v1.2.3