I've been looking at the NeHe openGL examples and I've got up to
number 5 working but I cant seem to get the texture example (http://
nehe.gamedev.net/data/lessons/lesson.asp?lesson=06) to work for some
reason. I have included the code below; maybe someone can take a look
and see what I'm doing wrong.
I don't know openGL that well so I have another question as well: is
there a way to look at the state of the openGL machine for debugging
purposes from cl-opengl?
Cheers,
Charlie
;-- code --
(defpackage :gl-test
(:use :cl)
(:export :test))
(in-package :gl-test)
(defclass tex-win (glut:window)
((tex :accessor tex :initform 0))
(:default-initargs :pos-x 100 :pos-y 100
:width 320 :height 240
:title "TEX WIN"
:mode '(:double :rgb :depth)))
(defmethod glut:display :before ((w tex-win)))
(defun generate-rgb-data (x y)
(let ((data (make-array (* x y 3)
:element-type '(unsigned-byte 8)
:initial-element #x000000)))
(loop for pixel from 0 to (1- (* x y 3)) do
(setf (aref data pixel) (mod pixel
255)))
data))
(defmethod initialize-instance :after ((w tex-win) &key)
(setf (tex w) (car (gl:gen-textures 1)))
(gl:bind-texture :texture-2d (tex w))
(gl:tex-image-2d :texture-2d 0 3 64 64 0 :rgb :unsigned-byte
(generate-rgb-data 64 64))
(gl:tex-parameter :texture-2d :texture-min-filter :linear)
(gl:tex-parameter :texture-2d :texture-mag-filter :linear)
(gl:enable :texture-2d)
(gl:shade-model :smooth)
(gl:clear-color 0 0 0 0)
(gl:clear-depth 1)
(gl:enable :depth-test)
(gl:depth-func :lequal)
(gl:hint :perspective-correction-hint :nicest))
(defmethod glut:keyboard ((w tex-win) key x y)
(case key (#\Esc (glut:destroy-current-window)
(glut:leave-main-loop))))
(defmethod glut:display ((w tex-win))
(gl:clear :color-buffer-bit :depth-buffer-bit)
(gl:load-identity)
(gl:translate 0 0 -5)
(gl:bind-texture :texture-2d (tex w))
(gl:with-primitive :quads
(gl:tex-coord 0 0) (gl:vertex -2 -2)
(gl:tex-coord 0 1) (gl:vertex 2 -2)
(gl:tex-coord 1 0) (gl:vertex 2 2)
(gl:tex-coord 1 1) (gl:vertex -2 2))
(gl:flush)
(glut:swap-buffers))
(defun test ()
(unwind-protect
(glut:display-window (make-instance 'tex-win))))
; -- code --
charlie wrote:
> I've been looking at the NeHe openGL examples and I've got up to
> number 5 working but I cant seem to get the texture example (http://
> nehe.gamedev.net/data/lessons/lesson.asp?lesson=06)
> to work for some
> reason.
Did you also ask on the cl-opengl list?
The code you posted is a lot different than Nehe 6. That makes it harder
to help you. I understand you are trying to simplify, but then you
introduce even more mistakes by not understanding what you are simplifying.
OpenGL is a bear and fails more or less silently when you screw up. You
can try checking glGetError after any dubious call to see if you have
pissed off OpenGL in ways it chooses to flag.
If you can find my Cello project you will find my version of Nehe6,
which uses my own opengl bindings and Tcl/Tk/Togl instead of the Glut, I
am afraid, and may even now have deviated severely from Nehe6 (but it
still spins a cube and lays a texture on its faces.
> I have included the code below; maybe someone can take a look
> and see what I'm doing wrong.
You might want to define more specifically "not work".
>
> I don't know openGL that well so I have another question as well: is
> there a way to look at the state of the openGL machine for debugging
> purposes from cl-opengl?
All you can do is use the OpenGL API to ask it about its internal state,
mebbe write a function that does a glGet on all that stuff and print it
all out.
kt
>
> Cheers,
> Charlie
>
> ;-- code --
>
> (defpackage :gl-test
> (:use :cl)
> (:export :test))
> (in-package :gl-test)
>
> (defclass tex-win (glut:window)
> ((tex :accessor tex :initform 0))
> (:default-initargs :pos-x 100 :pos-y 100
> :width 320 :height 240
> :title "TEX WIN"
> :mode '(:double :rgb :depth)))
>
> (defmethod glut:display :before ((w tex-win)))
>
> (defun generate-rgb-data (x y)
> (let ((data (make-array (* x y 3)
> :element-type '(unsigned-byte 8)
> :initial-element #x000000)))
> (loop for pixel from 0 to (1- (* x y 3)) do
> (setf (aref data pixel) (mod pixel
> 255)))
> data))
>
> (defmethod initialize-instance :after ((w tex-win) &key)
> (setf (tex w) (car (gl:gen-textures 1)))
> (gl:bind-texture :texture-2d (tex w))
> (gl:tex-image-2d :texture-2d 0 3 64 64 0 :rgb :unsigned-byte
>
> (generate-rgb-data 64 64))
> (gl:tex-parameter :texture-2d :texture-min-filter :linear)
> (gl:tex-parameter :texture-2d :texture-mag-filter :linear)
> (gl:enable :texture-2d)
> (gl:shade-model :smooth)
> (gl:clear-color 0 0 0 0)
> (gl:clear-depth 1)
> (gl:enable :depth-test)
> (gl:depth-func :lequal)
> (gl:hint :perspective-correction-hint :nicest))
Uh, and now that array gets thrown away. Did you mean to do something
with it? Nehe loads a BMP into a a dyamically allocated array and saves
a pointer to that array in a global vector of pointers.
>
> (defmethod glut:keyboard ((w tex-win) key x y)
> (case key (#\Esc (glut:destroy-current-window)
> (glut:leave-main-loop))))
>
> (defmethod glut:display ((w tex-win))
> (gl:clear :color-buffer-bit :depth-buffer-bit)
> (gl:load-identity)
> (gl:translate 0 0 -5)
> (gl:bind-texture :texture-2d (tex w))
> (gl:with-primitive :quads
> (gl:tex-coord 0 0) (gl:vertex -2 -2)
> (gl:tex-coord 0 1) (gl:vertex 2 -2)
> (gl:tex-coord 1 0) (gl:vertex 2 2)
> (gl:tex-coord 1 1) (gl:vertex -2 2))
> (gl:flush)
> (glut:swap-buffers))
>
> (defun test ()
> (unwind-protect
> (glut:display-window (make-instance 'tex-win))))
>
> ; -- code --
--
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/
ECLM rant:
http://video.google.com/videoplay?docid=-1331906677993764413&hl=en
ECLM talk:
http://video.google.com/videoplay?docid=-9173722505157942928&q=&hl=en