(asdf:oos 'asdf:load-op :cl-opengl)
(asdf:oos 'asdf:load-op :cl-glu)
(load "glut.lisp")
(load "/Users/topo/slime-2.0/swank-loader.lisp")
(defparameter *window-width* 640)
(defparameter *window-height* 480)
(defvar a nil)
(defvar *object3* nil)
(defparameter *time* 0)
(defun time-in-seconds ()
(float (/ (get-internal-real-time) internal-time-units-per-second)))
(defmacro safe-cffi-callback (lisp-function &rest parameter-list &aux (callback-tmpname (gensym)))
`(prog2
(cffi:defcallback ,callback-tmpname :void ,parameter-list
(handler-case (,lisp-function ,@(mapcar #'car parameter-list))
(error (condition)
(setf (symbol-function ',lisp-function) (constantly nil))
(format t "Error in ~a: ~a~%" ',lisp-function condition))))
(cffi:callback ,callback-tmpname)))
;; (glu:Quadric-Draw-Style qobj GLU_FILL)
;; (gl:New-List list GL_COMPILE)
;; (glu:Sphere qobj 0.7d0 20 20) ; qobj, radius, slices, stacks
;; (gl:End-List)
;; list))
(defun random-elt2 (list)
(eval (elt list (random (length list)))))
(defun hola( )
(random-elt2
'((cons 'CL-OPENGL:ROTATE (cons 122 (cons 1233 (cons 15 (cons 15 nil) ))))
(cons 'CL-OPENGL:TRANSLATE (cons 1 (cons 2 (cons 1.3 nil) )))
(cons 'CL-OPENGL:TRANSLATE (cons 0 (cons 26 (cons 0 nil)))))))
(defun creapush-pop( )
(cons (random-elt2
'(
(cons 'CL-OPENGL:ROTATE (cons 122 (cons 1233 (cons 15 (cons 15 nil) ))))
(cons 'CL-OPENGL:TRANSLATE (cons 31 (cons 2 (cons 1.3 nil) )))
(cons 'CL-OPENGL:TRANSLATE (cons 0 (cons 6 (cons 0 nil) )))
(cons 'CL-OPENGL:TRANSLATE (cons 131 (cons 22 (cons 11.3 nil) )))
(make-structure)
))
(cons '(glut:solid-sphere 26.529d0 9 6) (cons '(gl:pop-matrix) nil ))))
(defun random-elt (list)
(elt list (random (length list))))
(defun make-structure ()
(case (random-elt '(transformation iterations geo push-pop))
(transformation
(let ((trans+geo (copy-seq (random-elt '((gl:scale 1 0.1 0)
(gl:translate -1 -3 -1.5)
(gl:translate (* (sin (* *time* 0.3)) 59) -3 -1.5)
(glut:solid-sphere 12.529d0 13 3)
(glut:solid-torus 3.2d0 14.2d0 20 32)
(gl:color 0.2 0.8 0)
(gl:color 0.0 0.3 0.6)
(gl:color 0.2 0.0 0.9)
(gl:color 0.5 0.1 1)
(gl:rotate 119 997 27 1))))))
(concatenate 'list (list trans+geo) (make-structure))))
(iterations (list (cons 'dotimes
(cons
(cons 'i (cons '10 nil) )
(cons (hola ) (make-structure))))))
(push-pop (let ((cpp (creapush-pop))) (list (list 'gl:push-matrix) (first cpp) (second cpp) (third cpp))))
(geo (list (random-elt '((glut:solid-sphere 19.529d0 13 3)
(glut:solid-cube 19.d0)
(glut:wire-cube 12.2d0)
(glut:solid-cone 20.2d0 80.2d0 6 6)
(glut:solid-dodecahedron )
(glut:solid-octahedron)
(glut:wire-sphere 14.2d0 20 32)
(glut:wire-torus 13.2d0 50.2d0 30 42)
(glut:solid-torus 8.2d0 14.2d0 20 32))) ))))
( setf a (make-structure))
(defun draw ()
(gl:clear-color 1 0 0 1)
(gl:clear :color-buffer-bit :depth-buffer-bit)
(gl:matrix-mode :projection)
(gl:load-identity)
(glu:perspective 60 (/ 800 600) 1 700)
(gl:matrix-mode :modelview)
(gl:load-identity)
(gl:enable :lighting)
(gl:enable :light0)
(gl:enable :depth-test)
(gl:enable :color-material)
(gl:enable :auto-normal)
(gl:enable :normalize)
(gl:translate -60 3 -390)
(gl:rotate -14 -77 88 1)
(dolist (primitive a)
(eval primitive))
(glut:swap-buffers))
(defun animate (dt))
(defun init ()
(glut:init-posix-argv sb-ext:*posix-argv*)
(glut:init-window-size *window-width* *window-height*)
(glut:init-display-string "rgb double depth>=16 samples=8")
(glut:create-window "GLUT - <Untitled>")
(glut:display-func (safe-cffi-callback draw))
(let ((last-time))
(flet ((aux-animate (&aux (current-time (time-in-seconds))
(dt (- current-time
(if last-time last-time current-time))))
(setq *time* (+ *time* dt)
last-time current-time)
(animate dt)
(sb-sys:serve-all-events 0.01)
(glut:post-redisplay)))
(glut:idle-func (safe-cffi-callback aux-animate))))
(flet ((window-resize (width height)
(setq *window-width* width
*window-height* height)
(gl:viewport 0 0 *window-width* *window-height*)))
(glut:reshape-func (safe-cffi-callback window-resize (width :int) (height :int))))
(swank:create-server)
(glut:main-loop))
(unless (boundp 'inited)
(defparameter inited nil)
(init))