<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#ffffff">
Hi,<br>
<br>
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.<br>
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<br>
<br>
<font face="Courier New, Courier, monospace">(defmethod
glut:display-window :before ((window texture-window))<br>
(gl:clear-color 0 0 0 0)<br>
(gl:shade-model :flat)<br>
<br>
(multiple-value-bind (data height width channels)<br>
(jpeg:decode-image "/home/joe/tux.jpg")<br>
<br>
(let ((texture (first (gl:gen-textures 1))))<br>
(gl:bind-texture :texture-2d texture)<br>
(setf (texture window) texture)<br>
(gl:tex-env :texture-env :texture-env-mode :modulate)<br>
(gl:tex-parameter :texture-2d :texture-min-filter
:linear-mipmap-linear)<br>
(gl:tex-parameter :texture-2d :texture-mag-filter :linear)<br>
(gl:tex-parameter :texture-2d :texture-wrap-s :repeat)<br>
(gl:tex-parameter :texture-2d :texture-wrap-t :repeat)<br>
<br>
(cffi:with-foreign-pointer (buf (* width height channels))<br>
(loop for i from 0 below (* width height channels)<br>
do (setf (cffi:mem-ref buf :char i) (aref data i)))<br>
<br>
(glu:build-2d-mipmaps :texture-2d :rgb width height :bgr
:unsigned-byte buf)))))</font><br>
<br>
I would like to avoid cffi calls. Do you have any suggestion?<br>
<br>
Regards,<br>
José Lopes<br>
</body>
</html>