[cl-opengl-devel] Some issues porting an example from nehe.gamedev.net

Malcolm Reynolds malcolm.reynolds at gmail.com
Mon Oct 5 18:43:52 UTC 2009


Hello,

I'll start by saying I'm fairly new to Common Lisp and almost entirely
new to doing any practical graphics programming, and I could well have
missed something hugely obvious here.. but I hope not.

I'm going to need to write some graphics code in the phd program I've
just started. Someone pointed me at nehe.gamedev.net's opengl
tutorials and after slogging through up to number 5 -
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=05 - reading
through people's objective C, I decided to try and port it to Lisp
using cl-opengl. I looked at a couple of examples (cube.lisp and
gears.lisp) to get the boilerplate about window generation, and from
there it was pretty much just a case of porting the drawRect method
from the Objective C version to the glut:display method for my code.

I have clearly missed something though, as the visibility for my
geometry is all off - for example the base of the triangle is drawn in
front of anything else and most faces of the cube do something a bit
whacky. I know that which order points are drawn in is crucial because
that defines the 'front' of a triangle/quad, but I'm pretty sure I
have copied the points in the same order as my Objective C version
(which works fine, see screenshots)

Working version (objective C): http://img260.imageshack.us/i/picture3g.png/
Non working version: http://img209.imageshack.us/i/picture4k.png/

In case it's not clear, in the non-working version above the corner
you see in the pyramid is actually the back corner. It shouldn't be
visible. When the pyramid rotates so that you should be looking down
on the point at it, you see only the base instead of only the four top
faces. I have similar issues with the cube faces, some of them only
being visible from the 'inside'.

>From what I can tell from M-.'ing through the source, cl-opengl passes
directly through to the corresponding C functions, so I'm pretty
confident the 'which order to specify points' hasn't changed. This
means presumably something in my setup is off, something to do with
the depth buffer maybe? I guess the issue might be in the keyword args
in function calls in #'glut:display-window method but it's hard to
figure out exactly what the arguments to these functions will be
except a guess at translating them into lisp-ish hyphenated lowercase.

Here's the entire source to my lisp program:
http://paste.lisp.org/display/88230

and the relevant file from my Obj-C version (I basically tried to copy
everything from the drawRect and reshape methods):
http://paste.lisp.org/display/88231


If anyone can point me in the right direction that would be most
appreciated.. I'm looking forward to using Lisp for some serious work
once I get these niggles sorted out.

Cheers,

Malcolm




More information about the cl-opengl-devel mailing list