textures part 4 : other sources of textures

Not many pictures this time, just a few other examples of texture loaders: (well 1 example for now, more to come...)


We can draw graphics using the vecto library, and load the results as a texture fairly easily:

(defmacro with-vecto-canvas-as-texture ((width height) &body body)
  (let ((texture (gensym "TEXTURE-")))
    `(vecto:with-canvas (:width ,width :height ,height)
       ;; run some vecto code
       ;; and load the result into a texture
       (let ((,texture (car (gl:gen-textures 1))))
         (gl:bind-texture :texture-2d ,texture)
         (gl:tex-parameter :texture-2d :texture-min-filter :linear)
         (gl:tex-parameter :texture-2d :generate-mipmap t)
         (gl:tex-parameter :texture-2d :texture-min-filter :linear-mipmap-linear)
         (gl:tex-image-2d :texture-2d 0 :rgba ,width ,height
                          0 :rgba :unsigned-byte
                          (vecto::image-data vecto::*graphics-state*))

;; example use
(setf *foreground-texture*
      (with-vecto-canvas-as-texture (256 256)
        ;; one of the examples from vecto docs:
        (let ((size 100)
              (angle 0)
              (step (* 2 (/ (* pi 2) 5))))
          (vecto:translate size size)
          (vecto:move-to 0 size)
          (dotimes (i 5)
            (setf angle (+ angle step))
            (vecto:line-to (* (sin angle) size)
                           (* (cos angle) size)))
          (flet ((circle (distance)
                   (vecto:set-rgba-fill distance 0 0
                                        (- 1.0 distance))
                   (vecto:centered-circle-path 0 0 (* size distance))
            (loop for i downfrom 1.0 by 0.05
                  repeat 20 do
                  (circle i))))))