From 763300daf081c87e57eb3a3453254cfbbfc0d5bf Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Thu, 30 Jun 2011 09:08:12 -0700 Subject: [PATCH] tried converting cube to sdl... and tried adding fps counter to 3bb --- 3bb-1.lisp | 16 +++++++++++++++- cube.lisp | 23 ++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/3bb-1.lisp b/3bb-1.lisp index ac710f8..ce59758 100644 --- a/3bb-1.lisp +++ b/3bb-1.lisp @@ -36,6 +36,9 @@ (rotate-vertex (second tri) time) (rotate-vertex (third tri) time))) +(defparameter *last-time* nil) +(defparameter *num-frames* 0) + (defun draw () "draw a frame" (let* ((time (- (wall-time) *start-time*)) @@ -61,7 +64,18 @@ ;; finish the frame (gl:flush) - (sdl:update-display))) + (sdl:update-display) + (incf *num-frames*) + ;(if (not (eql (floor *last-time*) time)) + (let* ((short-interval (- time (if *last-time* *last-time* time))) + (long-interval (- time *start-time*)) + (short-fps (if (zerop short-interval) 0 (/ 1 short-interval))) + (long-fps (if (zerop long-interval) 0 (/ *num-frames* long-interval)))) + + + (format t "FPS since last:~a->~a since start:~a/~a->~a ~%" short-interval short-fps *num-frames* long-interval long-fps)))) + + (setf *last-time* (wall-time))) diff --git a/cube.lisp b/cube.lisp index 47ec0b8..c749088 100644 --- a/cube.lisp +++ b/cube.lisp @@ -1,3 +1,9 @@ +(defmacro restartable (&body body) + `(restart-case + (progn ,@body) + (continue () :report "Continue"))) + + (defparameter *light-diffuse* (vector 1.0 0.0 0.0 1.0)) ;; red diffuse light (defparameter *light-position* (vector 1.0 1.0 1.0 0.0)) ;; infinite light position @@ -27,10 +33,13 @@ (dotimes (x 4) (gl:vertex (3delt face x *v* 0) (3delt face x *v* 1) (3delt face x *v* 1))))))) -(cffi:defcallback display :void () +;(cffi:defcallback display :void () +(defun display () (gl:clear :color-buffer-bit :depth-buffer-bit) (draw-box) ;;glut:swap-buffers + (gl:flush) + (sdl:update-display) ) (defun init () @@ -55,7 +64,7 @@ (gl:rotate 60 1.0 0.0 0.0) (gl:rotate -20 0.0 0.0 1.0)) -(defun cube-main () +(defun cube-main-glut () (glut:init "Cube") (glut:init-display-mode :double :rgb :depth) (glut:create-window "red 3D lighted cube") @@ -63,4 +72,12 @@ (init) (glut:main-loop) ) - \ No newline at end of file + +(defun cube-main-sdl () + (sdl:with-init () + (sdl:window 320 240 :flags sdl:sdl-opengl) + (setf cl-opengl-bindings:*gl-get-proc-address* #'sdl-cffi::sdl-gl-get-proc-address) + (sdl:with-events () + (:quit-event () t) + (:idle () + (restartable (display)))))) \ No newline at end of file