You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6 KiB

  1. ;;; glut-template.lisp
  2. ;;; load opengl
  3. (require :asdf)
  4. (asdf:load-system :cl-opengl)
  5. (asdf:load-system :cl-glu)
  6. (asdf:load-system :cl-glut)
  7. (defclass my-window (glut:window)
  8. ()
  9. (:default-initargs :width 400 :height 300
  10. :title "My Window Title"
  11. :x 100 :y 100
  12. :mode '(:double :rgb :depth)))
  13. ;;; initilization method
  14. (defmethod glut:display-window :before ((win my-window))
  15. ;;; prepage opengl
  16. (gl:shade-model :smooth) ; enables smooth shading
  17. (gl:clear-color 0 0 0 0) ; background will be black
  18. (gl:clear-depth 1) ; clear buffer to minimum depth
  19. (gl:enable :depth-test) ; enable depth testing
  20. (gl:depth-func :lequal) ; okay to write pixel if its depth
  21. ; is less-than-or-equal to the
  22. ; depth xcurrently written
  23. (gl:hint :perpective-correction-hint :nicest) ; really nice perspective correction
  24. )
  25. ;;; additional glut methods
  26. (defmethod glut:display ((win my-window))
  27. (gl:clear :color-buffer-bit :depth-buffer-bit)
  28. (gl:load-identity))
  29. (defmethod glut:reshape ((win my-window) width height)
  30. ;;; prepare viewport
  31. (gl:viewport 0 0 width height) ; reset current viewport
  32. ;;; glut reshape -- prepare project
  33. (gl:matrix-mode :projection) ; select the projection matrix
  34. (gl:load-identity) ; reset the matrix
  35. ;; set perspective based on window aspect ratio
  36. (glu:perspective 45 (/ width (max height 1)) 1/10 100)
  37. ;;; glut reshape -- switch to model view
  38. (gl:matrix-mode :modelview) ;select the model view matrix
  39. (gl:load-identity) ; reset the matrix
  40. )
  41. ;;; create an instance of our window
  42. (glut:display-window (make-instance 'my-window))