2009/04/17

まだ cl-opengl cube.c

frustum が透視法射影で、ortho が正射影。前者が遠近法。

カメラの位置と方向。上方向ベクトルって何?

ちょっとずつわかってきた。嬉しい。

『OpenGLプログラミングガイド 第2版』の cube.c を cl-opengl で。

(eval-when (:compile-toplevel :load-toplevel :execute)
(require :cl-glu)
(require :cl-glut))

(defclass cube-window (glut:window)
()
(:default-initargs :title "Cube"
:mode '(:single :rgb)
:width 500 :height 500
:pos-x 200 :pos-y 100))

(defmethod glut:keyboard ((window cube-window) key x y)
(declare (ignore x y))
(case key
((#\Esc #\q) (glut:destroy-current-window))))

(defmethod glut:display-window :before ((window cube-window))
(%gl:clear-color 0 0 0 0)
(%gl:shade-model :flat))

(defmethod glut:display ((window cube-window))
(gl:clear :color-buffer-bit)
(%gl:color-3f 1 1 1)
(%gl:load-identity)
(glu:look-at 0 0 5 ; カメラの位置
0 0 0 ; カメラの方向
0 1 0) ; カメラの上方向ベクトル
(%gl:scale-f 1 2 1)
(glut:wire-cube 1)
(%gl:flush))

(defmethod glut:reshape ((window cube-window) width height)
(%gl:viewport 0 0 width height)
(%gl:matrix-mode :projection)
(%gl:load-identity)
(%gl:frustum ; 透視法射影
-1 ; left
1 ; right
-1 ; bottom
1 ; top
1.5 ; near
20) ; far
(%gl:matrix-mode :modelview))

;;(glut:display-window (make-instance 'cube-window))

mesa 系の lib をインストールしたら freeglut は動かなくなる?

0 件のコメント: