;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;

;; A simple example which uses OpenGL for 

;; efficient image processing.

;;

;; As of Impromptu 2.5 CIImage is the preferred default image

;; format and gfx:image2image now supports CIImage natively

;; in both from and to positions.

;;

;; gfx:get-live-frame and gfx:get-movie-frame both return images

;; in CIImage format and gl:draw-ciimage allows CIImages to be

;; rendered directly to an impromptu opengl canvas.

;; 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(gfx:start-live-video)


(define *gl* (gl:make-opengl))

(gl:close-opengl *gl*)

(gl:open-opengl *gl* #t)

(define res (gfx:get-display-resolution *gl*))

(print res)

(gfx:hide-menu)


(define fx1 (gfx:make-filter "CIEdges"))

(define fx2 (gfx:make-filter "CIBloom"))

(print (car res))

(define playback

   (lambda (beat) 

      (let* ((i1 (objc:r (gfx:get-live-frame)))

             (i2 (objc:r (gfx:apply-filter fx1 i1)))

             (i3 (objc:r (gfx:apply-filter fx2 i2)))

             (i4 (objc:r (gfx:make-image 640 480 "CI"))))

         (gfx:image2image i3 i4 1.0 (list 0 0 640 480) (list 0 0 640 480))

         (gfx:set-filter-param fx1 "inputIntensity" (cosr 2 2 1/8))

         (gfx:set-filter-param fx2 "inputIntensity" (cosr 1 1 1/2))

         (gl:draw-ciimage *gl* i4 (list 0 0 (car res) (cdr res)))

         (gl:flush *gl*)

         (callback (*metro* (+ beat (* 1/2 1/12))) 'playback (+ beat 1/12)))))


(playback (*metro* 'get-beat 4))