<?xml version="1.0"?>
<paste-with-annotations>
  <paste>
    <number>
      <integer>50662</integer>
    </number>
    <user>
      <string>topo</string>
    </user>
    <title>
      <string>variable -shader</string>
    </title>
    <contents>
      <string>
(require 'asdf)
(require 'asdf-install)
(asdf:oos 'asdf:load-op :cl-opengl)
(asdf:oos 'asdf:load-op :cl-glu)
(load &quot;glut.lisp&quot;)
(load &quot;/users/topo/slime-2.0/swank-loader.lisp&quot;)

(defparameter *time* 0)
(defun time-in-seconds ()
  (/ (get-internal-real-time) internal-time-units-per-second))

(defparameter *shador* 10.0 )

(defparameter fragment-shader nil)
(defparameter vertex-shader nil)
(defparameter mandelbrot-shader nil)


 (defparameter *fra* (open &quot;dof.frag&quot;))
 (defparameter *ve* (open &quot;dof.ver&quot;))
;;(defparameter *fragment* nil)

;;*****************************************
;; como hago para meter mis shaders en varibles?
;; puede ser f una varible global? o cual es el alcanze de f

;;(with-out-to-string (s)
;;(handler-case (with-open-file (f &quot;tmp.txt&quot;)
;;(loop (write-line (read-line f) s)))
;;(end-of-file () nil)))


;;(apply #'concatenate (cons 'string (with-open-file (in #P&quot;dof.ver&quot;) (loop for line = (read-line in nil nil) while line collect line))))


(defun contents-of-file (pathname)
  &quot;Returns a string with the entire contents of the specified file.&quot;
  (with-output-to-string (contents)
    (with-open-file (in pathname :direction :input)
      (let* ((buffer-size 4096)
             (buffer (make-string buffer-size)))
        (loop for size = (read-sequence buffer in)
              do (write-string buffer contents :start 0 :end size)
              while (= size buffer-size))))))


(defparameter *archivo* (contents-of-file &quot;dof.ver&quot;))


(defun carga-frag-shader (filename)
  (with-open-file (in filename)
    (with-standard-io-syntax
      (setf *fra* (read in)))))

(defun carga-vertex-shader (filename)
  ;;esta funcion carga mis vertex  shaders de un archivo externo y lo pone en una variable

  (with-open-file (in filename)
    (with-standard-io-syntax
      (setf *ve* (read in )))))



 ;;(carga-frag-shader (open &quot;dof.frag&quot;))
 ;;(carga-vertex-shader (open &quot;dof.ver&quot;))  


;;(with-open-file (f &quot;def.frag&quot;)
;;(read f))

;;**********************************************************
;; todo en moviemiento
;; software : explorar con iteracion y manipulacion y recursiones.
;; arboles, fractales.
;; que el codigo se autogenere.
;; todas las posibilidades de formas:
;; hacer muchos shaders,
;;slots
;; que las variables del shader se controlen desde afuera.
;;colores con criterios (circulo cromatico)
;;que mande a supercollider via osc



;;(setq mandelbrot-shader nil)

(defun draw ()
  (gl:clear-color 0.1 0.5 1 1)
  (gl:clear :color-buffer-bit :depth-buffer-bit)
  (gl:matrix-mode :projection)
  (gl:load-identity)
  ;;(glu:ortho-2d 0 1 0 1)
  (glu:perspective 60 (/ 800 600) 1 49000)
  (gl:matrix-mode :modelview)
  (gl:load-identity)
  (gl:color 0 1 0)
  (gl:enable :lighting)
  (gl:enable :light0)
  (gl:enable :depth-test)
  (gl:enable :color-material)
  (gl:enable :auto-normal)
  (gl:enable :normalize)
  (gl:push-matrix)

 ;; (load-shader-pair &quot;terrain&quot; *vertex-shader* *fragment-shader* *shader-program*)
 ;; (load-shader-pair &quot;sea&quot; *sea-vertex-shader* *sea-fragment-shader* *sea-program*)

  (unless mandelbrot-shader
    (setq vertex-shader (gl:create-shader :vertex-shader))
   (gl:shader-source vertex-shader  *archivo*  )


;;(gl:shader-source vertex-shader  
;; *ve*                   
;;'( 
;;

;;&quot;float f1 = 1.0;
;;float f2 = 1.0;
;;float f3 = 2.0 ;
;;float a1 = 5.4 ;
;;float a2 = 1.5 ;
;;float a3 = 2.1 ;
;;float t1 = 4.0 ;
;;float t2 = 5.0 ;
;;float t3 = 2.0 ;
;;
;;void main(void)
;;	{
;;	vec4 v = vec4(gl_Vertex);
;;	float facteur;
;;
;;	facteur = 1. ;
;;	facteur += a1 * sin(t1 + f1*v.z);
;;	facteur += a2 * sin(t2 + f2*v.y);
;;	facteur += a3 * sin(t3 + f3*v.x);
;;
;;	facteur = max (0.,facteur) ;
;;
;;	v *= vec4(facteur,facteur,facteur,1.);
;;
;;	vec3 Normal = normalize(gl_NormalMatrix * v.xyz);
;;
;;	gl_FrontColor = gl_Color  * 0.2 + 0.7 * dot(Normal,vec3(0.,0.3,0.8));
;;		
;;	gl_Position = gl_ModelViewProjectionMatrix * v;
;;	} 
;;

;;&quot;)
;;)
   (gl:compile-shader vertex-shader)
    
    (setq fragment-shader (gl:create-shader :fragment-shader))
    (gl:shader-source fragment-shader
                      ;;'(&quot;void main() { gl_FragColor = vec4(0, 1, 0, 1); }&quot;))
                      '(&quot;
void main()
{	
	gl_FragColor = gl_Color;
} 

&quot;
			))

    (gl:compile-shader fragment-shader)
    (setq mandelbrot-shader (gl:create-program))
    (gl:attach-shader mandelbrot-shader vertex-shader)
    (gl:attach-shader mandelbrot-shader fragment-shader)
    (gl:link-program mandelbrot-shader))
;;prender y apagar shader , comento lo de abajo
;;  (gl:use-program mandelbrot-shader)'

;;*************************************************************************
;; estructura, dif tipos de iteracion, recursion, arboles, etc
;;cambio estructural en el codigo
;;navegar con wii
;;enviar a supercollider osc.
;cambiar las formas

  (gl:translate -3000 90 -00)
  (gl:rotate 500 300 80 0)
  (gl:push-matrix)
  ;;  (glut:solid-sphere 100.2d0 60 50)
  (dotimes (i 1)
    (gl:pop-matrix)  
    (gl:translate -9 -200 -90)
    (gl:pop-matrix)
    (gl:color 5.9 1 3.2 0)
    (gl:translate -200 -1000 -30000)
    (gl:rotate (* *time* 4) 200 200 0)
    (dotimes (i 4)
      (gl:push-matrix)
      ;;(gl:rotate 0 (* *time* 40) 0  0)
      (gl:translate 2600 0 990)
      (gl:rotate (* *time* 40) 0 0 0)
      ;; (glut:solid-sphere 2000.2d0 90 20)
      (gl:pop-matrix))
    (gl:push-matrix)
    (gl:color 1 1 0)
    (gl:rotate -60 -9 -9 0)  
    (gl:translate -8 -80 -91)  
    (dotimes (i 14)
      (gl:rotate (* *time* 0.8) 100 9 0)  
      (gl:translate 200 -200 -8)  
      (gl:pop-matrix)
      (gl:translate 100 0 -100)
      (gl:push-matrix)
      (dotimes (i 4) 
	(gl:rotate (* *time* 4) (* *time* 3) (* *time* 4) 0)  
	(gl:translate (+ 1(* 14.5 (sin (* *time* 3)))) 160 -700)
	
	(gl:scale (+ 1 (* 0.07 (sin (* *time* 1))))
		  (+ 1 (* 0.004 (cos (* *time* 5))))
		  1)
	(gl:pop-matrix)
	
	(gl:push-matrix)
	(gl:color 1.3 0.5 1)
	(gl:translate 200 10 -900)
	(gl:rotate 400 20 90 0)
	
	(glut:solid-sphere 800.2d0 30 52)
	(gl:pop-matrix)
	(gl:rotate 0 400 0 0 )
	(gl:color 0.4 0.3 0.9)
	(gl:begin :quads)
	(gl:tex-coord -1.5 -1.5) (gl:vertex -700 -1000)
	(gl:tex-coord 1.5 -1.5) (gl:vertex 2000 -500)
	(gl:tex-coord 1.5 1.5) (gl:vertex 300 5000)
	(gl:tex-coord -1.5 1.5) (gl:vertex -2000 10000)
	(gl:end) )
      (gl:rotate 400 800 30 0)
      (gl:translate -600 100 -80)
      (gl:push-matrix)
      (gl:translate 40 0 0)
      
       (dotimes (i 10)
	 ;;(gl:scale (+ 1 (* 20.5 (sin (* *time* 1)))) 0 0)  
	(gl:color 1.2 0.2 1.5)
	(gl:rotate 200 50 0 0)
	(gl:translate (+ 1(* 2500 (sin (* *time* 0.7)))) 20 (+ 1(* 800 (sin (* *time* 0.4)))) )
	(gl:rotate 200 -390 30 300))
	(glut:solid-sphere 900.5d0 30 10) 
      (gl:pop-matrix) ))
  (glut:swap-buffers))












;;*******************************************************




(let ((last-time nil)
      (dt 0))
  (defun animate ()
    (let ((current-time (time-in-seconds)))
      (unless (eq last-time nil)
        (setq dt (- current-time last-time)))
      (setq last-time current-time))
    (setq *time* (+ *time* dt))
    (sb-sys:serve-all-events 0.01)
    (glut:post-redisplay)))


(defun initialize-glut ()
  (glut:init-posix-argv sb-ext:*posix-argv*)
  (glut:init-window-size 800 600)
  (glut:init-display-mode (logior glut:+double+ glut:+rgba+ glut:+depth+))
  (glut:create-window &quot;GLUT AS FUCK&quot;)
  
  (cffi:defcallback display-callback :void ()
      (handler-case (draw)
        (error (condition) (format t &quot;Error in draw: ~a~%&quot; condition))))
  (glut:display-func (cffi:callback display-callback))
  
  (cffi:defcallback animate-callback :void ()
    (handler-case (animate)
        (error (condition) (format t &quot;Error in animate: ~a~%&quot; condition))))
  (glut:idle-func (cffi:callback animate-callback)))

(swank:create-server :port 4005 :dont-close t)
(initialize-glut)
(glut:main-loop)</string>
    </contents>
    <universal-time>
      <integer>3403804410</integer>
    </universal-time>
    <channel>
      <string>#xemacs</string>
    </channel>
    <colorization-mode>
      <string>Common Lisp</string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <null/>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </paste>
</paste-with-annotations>
