I've been stuck on this for the last two weeks and I'm feeling frustrated. Hopefully someone here can help. I'm using cl-opengl with sbcl on an Ubuntu box. Everything been working well but I've run into trouble with vertex (and other) arrays. I'm trying to create a vertex, normal, tex-coord, and edge array format. I keep getting an error when I try to bind the vertex array.
Undefined function: CL-OPENGL::TEX-COORD-POINTER
I've looked and there is a tex-coord-pointer defined in cl-opengl!
Anyway, here is my code below (Just the one object, if you want the rest I can send it). Thanks in advance for your time.
(in-package #:qix)
(gl:define-gl-array-format vnte (gl:vertex :type :float :components (x y z)) (gl:normal :type :float :components (nx ny nz)) (gl:tex-coord :type :float :components (tx ty)) (gl:edge-flag :type :float :components (e)))
(defclass 3d-model (display-list) ((vertex-array :accessor vertex-array :initarg vertex-array :initform nil) (size)))
(defclass 3d-square (3d-model) ((top :initarg :top :initform nil :accessor top) (left :initarg :left :initform nil :accessor left) (width :initarg :width :initform nil :accessor width) (height :accessor height :initarg :height :accessor height) (x-size :accessor x-size :initarg :x-size :initform 10) (y-size :accessor y-size :initarg :y-size :initform 10)))
(defmethod initialize-instance :after ((this 3d-square) &rest args) (print "starting init!") (with-accessors ((vertex-array vertex-array) (width width) (height height) (x-size x-size) (y-size y-size) (top top) (left left)) this (setf (slot-value this 'size) (* x-size y-size)) (let ((dx (/ width x-size)) (dy (/ height y-size)) (tdx (/ x-size)) (tdy (/ y-size))) (setf vertex-array (gl:alloc-gl-array 'vnte (slot-value this 'size))) (loop for i from 0 to (- x-size 1) do (loop for j from 0 to (- y-size 1) do (let ((startx (+ left (* i dx))) (starty (- top (* j dy))) (endx (+ left (* i dx) dx)) (endy (- top (* j dy) dy)) (tex-startx (* i tdx)) (tex-starty (* j tdy)) (tex-endx (+ (* i tdx) tdx)) (tex-endy (+ (* j tdy) tdy)) (offset (+ (* i y-size 6 3) (* j 6 3))))
; first triangle (setf (gl:glaref vertex-array offset 'x) (float startx)) (setf (gl:glaref vertex-array offset 'y) (float starty)) (setf (gl:glaref vertex-array offset 'z) (float 0)) (setf (gl:glaref vertex-array (+ offset 1) 'x) (float endx)) (setf (gl:glaref vertex-array (+ offset 1) 'y) (float starty)) (setf (gl:glaref vertex-array (+ offset 1) 'z) (float 0)) (setf (gl:glaref vertex-array (+ offset 2) 'x) (float startx)) (setf (gl:glaref vertex-array (+ offset 2) 'y) (float endy)) (setf (gl:glaref vertex-array (+ offset 2) 'z) (float 0)) ; second triangle (setf (gl:glaref vertex-array (+ offset 3) 'x) (float startx)) (setf (gl:glaref vertex-array (+ offset 3) 'y) (float endy)) (setf (gl:glaref vertex-array (+ offset 3) 'z) (float 0)) (setf (gl:glaref vertex-array (+ offset 4) 'x) (float endx)) (setf (gl:glaref vertex-array (+ offset 4) 'y) (float starty)) (setf (gl:glaref vertex-array (+ offset 4) 'z) (float 0)) (setf (gl:glaref vertex-array (+ offset 5) 'x) (float endx)) (setf (gl:glaref vertex-array (+ offset 5) 'y) (float endy)) (setf (gl:glaref vertex-array (+ offset 5) 'z) (float 0))
; first triangle normals (setf (gl:glaref vertex-array offset 'nx) (float 0)) (setf (gl:glaref vertex-array offset 'ny) (float 0)) (setf (gl:glaref vertex-array offset 'nz) (float 1)) (setf (gl:glaref vertex-array (+ offset 1) 'nx) (float 0)) (setf (gl:glaref vertex-array (+ offset 1) 'ny) (float 0)) (setf (gl:glaref vertex-array (+ offset 1) 'nz) (float 1)) (setf (gl:glaref vertex-array (+ offset 2) 'nx) (float 0)) (setf (gl:glaref vertex-array (+ offset 2) 'ny) (float 0)) (setf (gl:glaref vertex-array (+ offset 2) 'nz) (float 1)) ;second triangle... (setf (gl:glaref vertex-array (+ offset 3) 'nx) (float 0)) (setf (gl:glaref vertex-array (+ offset 3) 'ny) (float 0)) (setf (gl:glaref vertex-array (+ offset 3) 'nz) (float 1)) (setf (gl:glaref vertex-array (+ offset 4) 'nx) (float 0)) (setf (gl:glaref vertex-array (+ offset 4) 'ny) (float 0)) (setf (gl:glaref vertex-array (+ offset 4) 'nz) (float 1)) (setf (gl:glaref vertex-array (+ offset 5) 'nx) (float 0)) (setf (gl:glaref vertex-array (+ offset 5) 'ny) (float 0)) (setf (gl:glaref vertex-array (+ offset 5) 'nz) (float 1))
; first triangle texture (setf (gl:glaref vertex-array offset 'tx) (float tex-startx)) (setf (gl:glaref vertex-array offset 'ty) (float tex-starty)) (setf (gl:glaref vertex-array (+ offset 1) 'tx) (float tex-endx)) (setf (gl:glaref vertex-array (+ offset 1) 'ty) (float tex-starty)) (setf (gl:glaref vertex-array (+ offset 2) 'tx) (float tex-startx)) (setf (gl:glaref vertex-array (+ offset 2) 'ty) (float tex-endy)) ; second triangle texture (setf (gl:glaref vertex-array (+ offset 3) 'tx) (float tex-startx)) (setf (gl:glaref vertex-array (+ offset 3) 'ty) (float tex-endy)) (setf (gl:glaref vertex-array (+ offset 4) 'tx) (float tex-endx)) (setf (gl:glaref vertex-array (+ offset 4) 'ty) (float tex-starty)) (setf (gl:glaref vertex-array (+ offset 5) 'tx) (float tex-endx)) (setf (gl:glaref vertex-array (+ offset 1) 'ty) (float tex-endy)) ; First triangle edges (setf (gl:glaref vertex-array offset 'e) (float (if (zerop i) 1 0))) (setf (gl:glaref vertex-array (+ offset 1) 'e) (float 0)) (setf (gl:glaref vertex-array (+ offset 2) 'e) (float (if (zerop j) 1 0))) ;Seconde Triangle Edges (setf (gl:glaref vertex-array (+ offset 3) 'e) (float 0)) (setf (gl:glaref vertex-array (+ offset 4) 'e) (float (if (eql j (- y-size 1)) 1 0))) (setf (gl:glaref vertex-array (+ offset 5) 'e) (float (if (eql i (- x-size 1)) 1 0)))))))))
(defmethod render ((this 3d-square)) ;;enable the correct arrays (gl:enable-client-state :vertex-array) (gl:enable-client-state :edge-flag-array) (gl:enable-client-state :normal-array) (gl:enable-client-state :texture-coord-array) (print "two") (gl:bind-gl-vertex-array (vertex-array this)) (format t "size = ~a~%" (slot-value this 'size)) (%gl:draw-arrays :triangles 0 (slot-value this 'size)))