develooper Front page | perl.cvs.parrot | Postings from November 2008

[svn:parrot] r32568 - trunk/examples/opengl

From:
japhb
Date:
November 11, 2008 16:22
Subject:
[svn:parrot] r32568 - trunk/examples/opengl
Message ID:
20081112002238.08543CB9AF@x12.develooper.com
Author: japhb
Date: Tue Nov 11 16:22:37 2008
New Revision: 32568

Modified:
   trunk/examples/opengl/shapes.p6
   trunk/examples/opengl/triangle.p6

Log:
[OpenGL] Perl 6 examples fixes

* Don't exit() from a callback.
* shapes.p6:
  + Get rid of $now variable
  + Add comment about += failure
  + Enable keyboard callback
  + Fix braino in FPS display

Modified: trunk/examples/opengl/shapes.p6
==============================================================================
--- trunk/examples/opengl/shapes.p6	(original)
+++ trunk/examples/opengl/shapes.p6	Tue Nov 11 16:22:37 2008
@@ -71,16 +71,15 @@
 our $frames      = 0;
 our $paused      = 0;
 
-our $now         = time();
-our $time_prev   = $now;
-our $time_curr   = $now;
+our $time_prev   = time();
+our $time_curr   = $time_prev;
 our $time_sim    = 0.0;
 our $time_sim_dt = 0.0;
 
 glutIdleFunc(     &idle     );
 glutDisplayFunc(  &draw     );
 # glutReshapeFunc(  &reshape  );
-# glutKeyboardFunc( &keyboard );
+glutKeyboardFunc( &keyboard );
 
 glutMainLoop();
 
@@ -103,11 +102,13 @@
 
 sub idle {
     $time_prev = $time_curr;
-    $time_curr = $now = time();
+    $time_curr = time();
 
-    my $dt = $paused ?? 0 !! $now - $time_prev;
+    my $dt = $paused ?? 0 !! $time_curr - $time_prev;
 
     $time_sim_dt = $dt;
+    # XXXX: Broken because of Parrot RT #60036
+    # $time_sim   += $dt;
     $time_sim    = $dt + $time_sim;
 
     glutPostRedisplay() unless $paused;
@@ -127,9 +128,7 @@
     if ($key == 27 | 81 | 113) {
         glutDestroyWindow($glut_window);
 
-        say "FPS: { $time_sim / ($frames || 1) }";
-
-        exit();
+        say "FPS: { $frames / ($time_sim || .001) }";
     }
     # For all other keys, just toggle pause
     else {

Modified: trunk/examples/opengl/triangle.p6
==============================================================================
--- trunk/examples/opengl/triangle.p6	(original)
+++ trunk/examples/opengl/triangle.p6	Tue Nov 11 16:22:37 2008
@@ -85,7 +85,6 @@
     # For ESCAPE, 'Q', and 'q', exit program
     if ($key == 27 | 81 | 113) {
         glutDestroyWindow($window);
-        exit();
     }
     # For all other keys, just toggle rotation
     else {



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About