Hello, To begin, as it's my first post, I'd like to thank all the developers who started and maintain this project. As a hobbiest beginner, this package allows me to play with the two things that I'm interested in most these days, Lisp and OpenGL.
With that said, I was working my way through OpenGL Distilled by Paul Martz, I noticed that section 2.8 on Vertex Arrays of the OpenGL spec was missing. I wasn't quite sure if this was on purpose or not, in favor of a more "Lispy" way but since I couldn't find any equivalent functionality I decided it was a big TODO. So I've after researching and playing with the system, I believe I've made a mostly function patch to add Vertex Arrays to cl-opengl. Of course this has caveats. The biggest caveat is I am still new to OpenGL and Lisp however my patch does produce nearly accurate results of rb-varray in the cl-glut-examples and I have hope that many of the other Vertex Array functions that aren't tested in the rb-varray example work as well. The "nearly accurate" results is why I've decided to mail in my patch. For the there is something odd about how OpenGL is getting one vertex and I can't for the life of me pinpoint it (hopefully due to my green-thumbedness). I /think/ it's either with CFFI itself or the 'with-opengl-array' / 'with-opengl-sequence' macros or maybe even my ATI mobitlity chip :( I'd be interested to hear if rb-varray works for anyone else. Sorry for the long explanation. Here's a short change summary followed by the patch attachment generated by 'darcs whatsnew' gl/package.lisp, funcs.lisp, opengl.lisp added the code for Vertex Arrays through CFFI and the export symbols necessary gl/util.lisp probably my more "dangerous" code as I modified slightly with-opengl-sequence to get rid of the eval quick hack and modified with-opengl-array to look like with-opengl-sequence with out the extra gynsym for array. I hope I did it right and didn't shoot myself in the foot... examples/rb-varray.lisp adjusted until if gave me output using rb-cube.lisp as a reference Thanks again and I hope this code is useful. Charlie Mac
{ hunk ./examples/examples.lisp 11 - rb-double rb-hello #|rb-varray|# rb-lines rb-polys rb-cube rb-model + rb-double rb-hello rb-varray rb-lines rb-polys rb-cube rb-model hunk ./examples/redbook/varray.lisp 14 - (deref-method :accessor deref-method :initform 'draw-array))) + (deref-method :accessor deref-method :initform 'draw-array)) + (:default-initargs :width 350 :height 350 :title "varray.lisp" + :mode '(:single :rgb))) + +(defparameter varray-win (make-instance 'varray-window)) hunk ./examples/redbook/varray.lisp 20 -(defun setup-pointers () - ;; XXX TODO -#|| - static GLint vertices[] = {25, 25, - 100, 325, - 175, 25, - 175, 325, - 250, 25, - 325, 325}; - static GLfloat colors[] = {1.0, 0.2, 0.2, - 0.2, 0.2, 1.0, - 0.8, 1.0, 0.2, - 0.75, 0.75, 0.75, - 0.35, 0.35, 0.35, - 0.5, 0.5, 0.5}; hunk ./examples/redbook/varray.lisp 21 - glEnableClientState (GL_VERTEX_ARRAY); - glEnableClientState (GL_COLOR_ARRAY); +(defun setup-pointers () + (let ((vertices (vector 25 25 + 100 325 + 175 25 + 175 325 + 250 25 + 325 325)) + (colors (vector 1.0 0.2 0.2 + 0.2 0.2 1.0 + 0.8 1.0 0.2 + 0.75 0.75 0.75 + 0.35 0.35 0.35 + 0.5 0.5 0.5))) hunk ./examples/redbook/varray.lisp 35 - glVertexPointer (2, GL_INT, 0, vertices); - glColorPointer (3, GL_FLOAT, 0, colors); -||# ) + (gl:enable-client-state :vertex-array) + (gl:enable-client-state :color-array) + [_$_] + (gl:vertex-pointer 2 :int 0 vertices) + (gl:color-pointer 3 :float 0 colors))) + [_$_] hunk ./examples/redbook/varray.lisp 42 -(defun setup-interlave () -#|| static GLfloat intertwined[] = - {1.0, 0.2, 1.0, 100.0, 100.0, 0.0, - 1.0, 0.2, 0.2, 0.0, 200.0, 0.0, - 1.0, 1.0, 0.2, 100.0, 300.0, 0.0, - 0.2, 1.0, 0.2, 200.0, 300.0, 0.0, - 0.2, 1.0, 1.0, 300.0, 200.0, 0.0, - 0.2, 0.2, 1.0, 200.0, 100.0, 0.0}; - [_$_] - glInterleavedArrays (GL_C3F_V3F, 0, intertwined); - ||#) +(defun setup-interleave () + (let ((intertwined (vector 1.0 0.2 1.0 100.0 100.0 0.0 + 1.0 0.2 0.2 0.0 200.0 0.0 + 1.0 1.0 0.2 100.0 300.0 0.0 + 0.2 1.0 0.2 200.0 300.0 0.0 + 0.2 1.0 1.0 300.0 200.0 0.0 + 0.2 0.2 1.0 200.0 100.0 0.0))) + [_$_] + (gl:interleaved-arrays :c3f-v3f 0 intertwined))) hunk ./examples/redbook/varray.lisp 52 -(defmethod initialize-instance :after ((w varray-window) &key) +(defmethod glut:display-window :after ((w varray-window)) hunk ./examples/redbook/varray.lisp 59 - (ecase deref-method + (ecase (deref-method varray-win) hunk ./examples/redbook/varray.lisp 68 - (gl:draw-elements :polygon 4 :unsigned-int '(0 1 3 4)))) + (gl:draw-elements :polygon 4 :unsigned-int (vector 0 1 3 4)))) hunk ./examples/redbook/varray.lisp 82 - (case (setup-method varray-window) + (case (setup-method varray-win) hunk ./examples/redbook/varray.lisp 84 - (setf (setup-method varray-window) 'interleaved) + (setf (setup-method varray-win) 'interleaved) hunk ./examples/redbook/varray.lisp 86 - (interlaved - (setf (setup-method varray-window) 'pointer) + (interleaved + (setf (setup-method varray-win) 'pointer) hunk ./examples/redbook/varray.lisp 92 - (setf (deref-method varray-window) - (case (deref-method varray-window) + (setf (deref-method varray-win) + (ecase (deref-method varray-win) hunk ./examples/redbook/varray.lisp 107 - [_$_] - (glut:init-display-mode :single :rgb) - (make-instance 'varray-window - :width 350 :height 350 - :pos-x 100 :pos-y 100 - :title "varray.lisp" - :events '(:display :reshape :mouse :keyboard)) - (glut:main-loop)) + (glut:display-window varray-win)) + + + +; :events '(:display :reshape :mouse :keyboard) + + + hunk ./gl/funcs.lisp 55 +(defglfun ("glArrayElement" %glArrayElement) :void + (i int)) + hunk ./gl/funcs.lisp 170 +(defglfun ("glClientActiveTexture" %glClientActiveTexture) :void + (texture enum)) + hunk ./gl/funcs.lisp 198 +(defglfun ("glColorPointer" %glColorPointer) :void + (size int) + (type enum) + (stride sizei) + (pointer :pointer)) + hunk ./gl/funcs.lisp 329 +(defglfun ("glDisableClientState" %glDisableClientState) :void + (array enum)) + +(defglfun ("glDisableVertexAttribArray" %glDisableVertexAttribArray) :void + (index uint)) + +(defglfun ("glDrawArrays" %glDrawArrays) :void + (mode enum) + (first int) + (count sizei)) + + hunk ./gl/funcs.lisp 348 +(defglfun ("glDrawElements" %glDrawElements) :void + (mode enum) + (count sizei) + (type enum) + (indices :pointer)) + hunk ./gl/funcs.lisp 359 +(defglfun ("glEdgeFlagPointer" %glEdgeFlagPointer) :void + (stride sizei) + (pointer :pointer)) + hunk ./gl/funcs.lisp 366 +(defglfun ("glEnableClientState" %glEnableClientState) :void + (array enum)) + +(defglfun ("glEnableVertexAttribArray" %glEnableVertexAttribArray) :void + (index uint)) + hunk ./gl/funcs.lisp 419 +(defglfun ("glFogCoordPointer" %glFogCoordPointer) :void + (type enum) + (stride sizei) + (pointer :pointer)) + hunk ./gl/funcs.lisp 581 +(defglfun ("glIndexPointer" %glIndexPointer) :void + (type enum) + (stride sizei) + (pointer :pointer)) + hunk ./gl/funcs.lisp 588 +(defglfun ("glInterleavedArrays" %glInterleavedArrays) :void + (frmat enum) + (stride sizei) + (pointer :pointer)) + hunk ./gl/funcs.lisp 739 +(defglfun ("glNormalPointer" %glNormalPointer) :void + (type enum) + (stride sizei) + (pointer :pointer)) + hunk ./gl/funcs.lisp 899 +(defglfun ("glSecondaryColorPointer" %glSecondaryColorPointer) :void + (size int) + (type enum) + (stride sizei) + (pointer :pointer)) + hunk ./gl/funcs.lisp 967 +(defglfun ("glTexCoordPointer" %glTexCoordPointer) :void + (size int) + (type enum) + (stride sizei) + (pointer :pointer)) + hunk ./gl/funcs.lisp 1191 +(defglfun ("glVertexAttribPointer" %glVertexAttribPointer) :void + (index uint) + (size int) + (type enum) + (normalized boolean) + (stride sizei) + (pointer :pointer)) + +(defglfun ("glVertexPointer" %glVertexPointer) :void + (size int) + (type enum) + (stride sizei) + (pointer :pointer)) + hunk ./gl/opengl.lisp 125 +;;; +;;; 2.8 Vertex Arrays +;;; + +(defun vertex-pointer (size type stride lisp-array) + (with-opengl-array (array type lisp-array) + (%glVertexPointer size type stride array))) + +(defun normal-pointer (type stride lisp-array) + (with-opengl-array (array type lisp-array) + (%glNormalPointer type stride array))) + +(defun color-pointer (size type stride lisp-array) + (with-opengl-array (array type lisp-array) + (%glColorPointer size type stride array))) + +(defun secondary-color-pointer (size type stride lisp-array) + (with-opengl-array (array type lisp-array) + (%glSecondaryColorPointer size type stride array))) + +(defun index-pointer (type stride lisp-array) + (with-opengl-array (array type lisp-array) + (%glIndexPointer type stride array))) + +(defun edge-flag-pointer (stride lisp-array) + (with-opengl-array (array :boolean lisp-array) + (%glEdgeFlagPointer stride array))) + +(defun fog-coord-pointer (type stride lisp-array) + (with-opengl-array (array type lisp-array) + (%glFogCoordPointer type stride array))) + +(defun tex-coord-pointer (size type stride lisp-array) + (with-opengl-array (array type lisp-array) + (%glTexCoordPointer size type stride array))) + +(defun vertex-attrib-pointer (index size type normalized stride lisp-array) + (with-opengl-array (array type lisp-array) + (%glVertexAttribPointer index size type normalized stride array))) + +(declaim (inline enable-client-state)) +(defun enable-client-state (state) + (%glEnableClientState state)) + +(declaim (inline disable-client-state)) +(defun disable-client-state (state) + (%glDisableClientState state)) + +(declaim (inline client-active-texture)) +(defun client-active-texture (enum) + (%glClientActiveTexture enum)) + +(declaim (inline array-element)) +(defun array-element (i) + (%glArrayElement i)) + +(declaim (inline draw-arrays)) +(defun draw-arrays (mode first count) + (%glDrawArrays mode first count)) + +;; (defun multi-draw-arrays ()) + +(defun draw-elements (mode count type lisp-indices) + (with-opengl-array (indices type lisp-indices) + (%glDrawElements mode count type indices))) + +;; (defun draw-range-elements ()) + +(defun interleaved-arrays (format stride lisp-array) + ;;array type needs more logic I think + ;;float is quick hack to get working with redbook varray example + (with-opengl-array (array :float lisp-array) + (%glInterleavedArrays format stride array))) + hunk ./gl/opengl.lisp 209 - (with-opengl-sequence (array 'uint buffers) + (with-opengl-sequence (array :uint buffers) hunk ./gl/opengl.lisp 333 - (with-opengl-sequence (p 'double eqn) + (with-opengl-sequence (p :double eqn) hunk ./gl/package.lisp 65 + ;; 2.8 Vertex Arrays + #:vertex-pointer + #:normal-pointer + #:color-pointer + #:secondary-color-pointer + #:index-pointer + #:edge-flag-pointer + #:fog-coord-pointer + #:tex-coord-pointer + #:vertex-attrib-pointer + #:enable-client-state + #:disable-client-state + #:client-active-texture + #:array-element + #:draw-arrays +;; #:multi-draw-arrays + #:draw-elements +;; #:multi-draw-elements +;; #:draw-range-elements + #:interleaved-arrays hunk ./gl/util.lisp 88 - (let ((count (gensym "COUNT")) - (array (gensym "ARRAY"))) - (once-only (type) - `(let* ((,array ,lisp-array) - (,count (length ,array))) + (let ((count (gensym "COUNT"))) + (once-only (type lisp-array) + `(let ((,count (length ,lisp-array))) hunk ./gl/util.lisp 93 - do (setf (mem-aref ,var ,type i) (aref ,array i))) + do (setf (mem-aref ,var ,type i) (aref ,lisp-array i))) hunk ./gl/util.lisp 111 - (flet ((converting (form) ; um, assuming type is constant - (case (eval type) ; silly hack.. FIXME - (float `(float ,form)) - (double `(float ,form 1.0d0)) - (t form)))) + (flet ((converting (type1 form) ; um, assuming type is constant + (case type1 [_$_] + (:float `(float ,form)) + (:double `(float ,form 1.0d0)) + (t form)))) hunk ./gl/util.lisp 122 - ,(converting `(elt ,lisp-sequence i)))) + ,(converting type `(elt ,lisp-sequence i)))) }
_______________________________________________ cl-opengl-devel mailing list cl-opengl-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/cl-opengl-devel