[cl-opengl-devel] textures
Bart Botta
00003b at gmail.com
Sat Sep 8 18:14:43 UTC 2007
On 9/8/07, Tudor Achim <t.achim at gmail.com> wrote:
> Hi,
> I'm following nehe's tutorials at nehe.gamedev.net, and I'm having a lot of
> trouble with loading and binding textures.
Which one(s) are you looking at?
> I opened a stream to the bmp file with
> (setf test (open "/home/tudor/email.bmp" :element-type
> '(cl-user::unsigned-byte 8)))
> Then, I made an 1d array of 5000 elements (just so it was 'big enough') and
> stored the rgb values in it with
> (read-sequence test-array test)
>
You'll probably need something more complicated than that (to deal
with the BMP file format, etc), but it should at least give you
something that would show up if you uploaded it correctly... (though
are you sure that is actually 'big enough' for your file? that would
only be around 40x40 pixels if I'm counting right.)
> However, when I do (gl:bind-texture gl:tex-image-2d test-array),
> it says that cl-opengl:tex-image-2d is unbound.
>
There are a few things wrong here:
First, you probably want :tex-image-2d instead of gl:tex-image-2d,
cl-opengl converts most OpenGL enums ( things like GL_FOO_BAR in C
source) to keywords in lisp (so :foo-bar for GL_FOO_BAR).
Next, bind-texture should be taking a GL texture name (an int) as the
second parameter, not the actual texture data.
You need to allocate a texture name with gl:gen-textures and store
that somewhere (and remember to deallocate it later).
Then you need to set up the texture, first make it the current texture
with bind-texture, then you will probably want some tex-parameter
calls to set filtering, and finally upload the image data with
tex-image-2d.
The tex-image-2d call is where you would pass the test-array parameter
you loaded above.
If you are only using 1 texture, then you should be able to go from
there, otherwise repeat that for each texture, and call bind-texture
during rendering to activate the particular you need for a batch of
geometry.
--
Bart
More information about the cl-opengl-devel
mailing list