Hi,

I was trying to create textures using glu:build-2d-mipmaps (I also tried using gl:tex-image-2d) and I had a few problems. I'm using jpeg:decode-image which produces a vector of unsigned bytes from the image that it loads. However, the function build-2d-mipmaps cannot handle properly a vector of data (or so I think). So I had to use cffi:with-foreign-pointer to allocate memory and copy all the bytes from the image to a cffi pointer so that it could be passed correctly to the underlying cffi layer through build-2d-mipmaps. This is the code I have now

(defmethod glut:display-window :before ((window texture-window))
  (gl:clear-color 0 0 0 0)
  (gl:shade-model :flat)

  (multiple-value-bind (data height width channels)
      (jpeg:decode-image "/home/joe/tux.jpg")

    (let ((texture (first (gl:gen-textures 1))))
      (gl:bind-texture :texture-2d texture)
      (setf (texture window) texture)
      (gl:tex-env :texture-env :texture-env-mode :modulate)
(gl:tex-parameter :texture-2d :texture-min-filter :linear-mipmap-linear)
      (gl:tex-parameter :texture-2d :texture-mag-filter :linear)
      (gl:tex-parameter :texture-2d :texture-wrap-s :repeat)
      (gl:tex-parameter :texture-2d :texture-wrap-t :repeat)

      (cffi:with-foreign-pointer (buf (* width height channels))
        (loop for i from 0 below (* width height channels)
             do (setf (cffi:mem-ref buf :char i) (aref data i)))

(glu:build-2d-mipmaps :texture-2d :rgb width height :bgr :unsigned-byte buf)))))

I would like to avoid cffi calls. Do you have any suggestion?

Regards,
José Lopes
_______________________________________________
cl-opengl-devel mailing list
cl-opengl-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cl-opengl-devel

Reply via email to