glwindowtest.monkey2 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. Namespace myapp
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. Using std..
  5. Using mojo..
  6. Using opengl..
  7. Class MyWindow Extends GLWindow
  8. Method New()
  9. Super.New( "GL Window",640,480,WindowFlags.Resizable )
  10. 'Disable default window clearing - we're clearing ourselves.
  11. '
  12. 'This is necessary if you're using a depth/stencil buffer. If not, you can just
  13. 'use normal ClearColor property.
  14. '
  15. ClearEnabled=False
  16. End
  17. Protected
  18. 'You don't need to implement this, but it allows you to combine opengl/mojo rendering.
  19. '
  20. Method OnRender( canvas:Canvas ) Override
  21. 'Can move this to OnRenderGL if you want.
  22. '
  23. App.RequestRender()
  24. 'This will result in OnRenderGL being called.
  25. '
  26. Super.OnRender( canvas )
  27. 'Do some mojo rendering!
  28. '
  29. canvas.DrawText( "FPS="+App.FPS,Width,0,1,0 )
  30. canvas.DrawText( "Mojo Rendering+OpenGL rendering!",Width/2,Height/2,.5,.5 )
  31. End
  32. 'GL rendering code goes here...
  33. '
  34. Method OnRenderGL() Override
  35. 'Clear window ourselves...
  36. '
  37. glClearColor( 0,0,1,1 )
  38. glClearDepth( 0 )
  39. glClearStencil( 0 )
  40. glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT )
  41. 'Drawing area. You're always drawing to the entire window in GL regardless of Layout.
  42. '
  43. 'Don't really need this for this example is it only affects glDrawBlah, but nice to know...
  44. '
  45. glViewport( 0,0,Frame.Width,Frame.Height )
  46. 'Shader-less rect
  47. '
  48. glEnable( GL_SCISSOR_TEST )
  49. glScissor( Mouse.X-32,Frame.Height-Mouse.Y-32,64,64 )
  50. glClearColor( 1,0,0,1 )
  51. glClear( GL_COLOR_BUFFER_BIT )
  52. glDisable( GL_SCISSOR_TEST )
  53. End
  54. End
  55. Function Main()
  56. New AppInstance
  57. New MyWindow
  58. App.Run()
  59. End