/extra/bunny/bunny.factor

http://github.com/abeaumont/factor · Factor · 60 lines · 51 code · 9 blank · 0 comment · 3 complexity · 76b5f39d17a5262e84f07755b3155a04 MD5 · raw file

  1. USING: accessors arrays bunny.cel-shaded bunny.fixed-pipeline
  2. bunny.model bunny.outlined destructors kernel math opengl.demo-support
  3. opengl.gl sequences ui ui.gadgets ui.gadgets.worlds ui.gestures
  4. ui.render words ui.pixel-formats ;
  5. IN: bunny
  6. TUPLE: bunny-world < demo-world model-triangles geom draw-seq draw-n ;
  7. : get-draw ( gadget -- draw )
  8. [ draw-n>> ] [ draw-seq>> ] bi nth ;
  9. : next-draw ( gadget -- )
  10. dup [ draw-seq>> ] [ draw-n>> ] bi
  11. 1 + swap length mod
  12. >>draw-n relayout-1 ;
  13. : make-draws ( gadget -- draw-seq )
  14. [ <bunny-fixed-pipeline> ]
  15. [ <bunny-cel-shaded> ]
  16. [ <bunny-outlined> ] tri 3array
  17. sift ;
  18. M: bunny-world begin-world
  19. GL_DEPTH_TEST glEnable
  20. 0.0 0.0 0.375 set-demo-orientation
  21. maybe-download read-model
  22. [ >>model-triangles ] [ <bunny-geom> >>geom ] bi
  23. dup make-draws >>draw-seq
  24. 0 >>draw-n
  25. drop ;
  26. M: bunny-world end-world
  27. dup find-gl-context
  28. [ geom>> [ dispose ] when* ]
  29. [ draw-seq>> [ [ dispose ] when* ] each ] bi ;
  30. M: bunny-world draw-world*
  31. dup draw-seq>> empty? [ drop ] [
  32. 0.15 0.15 0.15 1.0 glClearColor
  33. GL_DEPTH_BUFFER_BIT GL_COLOR_BUFFER_BIT bitor glClear
  34. dup demo-world-set-matrix
  35. GL_MODELVIEW glMatrixMode
  36. 0.02 -0.105 0.0 glTranslatef
  37. [ geom>> ] [ get-draw ] bi draw-bunny
  38. ] if ;
  39. bunny-world H{
  40. { T{ key-down f f "TAB" } [ next-draw ] }
  41. } set-gestures
  42. MAIN-WINDOW: bunny-window {
  43. { world-class bunny-world }
  44. { title "Bunny" }
  45. { pixel-format-attributes {
  46. windowed
  47. double-buffered
  48. T{ depth-bits { value 16 } }
  49. } }
  50. { pref-dim { 640 480 } }
  51. } ;