;;; glut-template.lisp ;;; load opengl (require :asdf) (asdf:load-system :cl-opengl) (asdf:load-system :cl-glu) (asdf:load-system :cl-glut) (defclass my-window (glut:window) () (:default-initargs :width 400 :height 300 :title "My Window Title" :x 100 :y 100 :mode '(:double :rgb :depth))) ;;; initilization method (defmethod glut:display-window :before ((win my-window)) ;;; prepage opengl (gl:shade-model :smooth) ; enables smooth shading (gl:clear-color 0 0 0 0) ; background will be black (gl:clear-depth 1) ; clear buffer to minimum depth (gl:enable :depth-test) ; enable depth testing (gl:depth-func :lequal) ; okay to write pixel if its depth ; is less-than-or-equal to the ; depth xcurrently written (gl:hint :perpective-correction-hint :nicest) ; really nice perspective correction ) ;;; additional glut methods (defmethod glut:display ((win my-window)) (gl:clear :color-buffer-bit :depth-buffer-bit) (gl:load-identity)) (defmethod glut:reshape ((win my-window) width height) ;;; prepare viewport (gl:viewport 0 0 width height) ; reset current viewport ;;; glut reshape -- prepare project (gl:matrix-mode :projection) ; select the projection matrix (gl:load-identity) ; reset the matrix ;; set perspective based on window aspect ratio (glu:perspective 45 (/ width (max height 1)) 1/10 100) ;;; glut reshape -- switch to model view (gl:matrix-mode :modelview) ;select the model view matrix (gl:load-identity) ; reset the matrix ) ;;; create an instance of our window (glut:display-window (make-instance 'my-window))