effects.monkey2 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. Namespace myapp
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. #Import "<mojo3d>"
  5. #Import "assets/"
  6. Using std..
  7. Using mojo..
  8. Using mojo3d..
  9. Class MyWindow Extends Window
  10. Field _scene:Scene
  11. Field _camera:Camera
  12. Field _light:Light
  13. Field _donut:Model
  14. Field _bloom:BloomEffect
  15. Field _mono:MonochromeEffect
  16. Field _godrays:GodraysEffect
  17. Field _fxaa:FXAAEffect
  18. Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
  19. Super.New( title,width,height,flags )
  20. _scene=Scene.GetCurrent()
  21. _scene.ClearColor=Color.Sky
  22. 'create camera
  23. '
  24. _camera=New Camera( self )
  25. _camera.Move( 0,10,-10 )
  26. New FlyBehaviour( _camera )
  27. 'create light
  28. '
  29. _light=New Light
  30. _light.Rotate( 120,0,0 )
  31. 'create effects
  32. '
  33. _godrays=New GodraysEffect
  34. _godrays.Enabled=false
  35. _godrays.Light=_light
  36. _bloom=New BloomEffect
  37. _bloom.Enabled=False
  38. _mono=New MonochromeEffect
  39. _mono.Enabled=False
  40. _fxaa=New FXAAEffect
  41. _fxaa.Enabled=False
  42. _scene.AddPostEffect( _bloom )
  43. _scene.AddPostEffect( _mono )
  44. _scene.AddPostEffect( _godrays )
  45. _scene.AddPostEffect( _fxaa )
  46. Local material:=New PbrMaterial( New Color( 2,.5,0,1 ),0,1 )
  47. _donut=Model.CreateTorus( 2,.5,48,24,material )
  48. _donut.AddComponent<RotateBehaviour>().Speed=New Vec3f( .1,.2,.3 )
  49. _donut.Move( 0,10,0 )
  50. End
  51. Method OnRender( canvas:Canvas ) Override
  52. RequestRender()
  53. If Keyboard.KeyHit( Key.Key1 ) _godrays.Enabled=Not _godrays.Enabled
  54. If Keyboard.KeyHit( Key.Key2 ) _bloom.Enabled=Not _bloom.Enabled
  55. If Keyboard.KeyHit( Key.Key3 ) _mono.Enabled=Not _mono.Enabled
  56. If Keyboard.KeyHit( Key.Key4 ) _fxaa.Enabled=Not _fxaa.Enabled
  57. _scene.Update()
  58. _scene.Render( canvas )
  59. canvas.DrawText( "(1) Godrays="+_godrays.Enabled,0,0 )
  60. canvas.DrawText( "(2) Bloom="+_bloom.Enabled,0,16 )
  61. canvas.DrawText( "(3) Monochrome="+_mono.Enabled,0,32 )
  62. canvas.DrawText( "(4) FXAA="+_fxaa.Enabled,0,48 )
  63. End
  64. End
  65. Function Main()
  66. ' SetConfig( "MOJO_OPENGL_PROFILE","es" )
  67. New AppInstance
  68. New MyWindow
  69. App.Run()
  70. End