rendertoimage.monkey2 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. Namespace test
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. Using std..
  5. Using mojo..
  6. #Import "assets/spaceship.png"
  7. Class MyWindow Extends mojo.app.Window
  8. Field image:Image
  9. Field icanvas:Canvas
  10. Method New()
  11. image=New Image( 256,256,TextureFlags.Dynamic )
  12. image.Handle=New Vec2f( .5,.5 )
  13. icanvas=New Canvas( image )
  14. End
  15. Method RenderImage()
  16. 'render to image...
  17. For Local x:=0 Until 16
  18. For Local y:=0 Until 16
  19. If (x~y)&1
  20. icanvas.Color=New Color( Sin( Millisecs()*.01 )*.5+.5,Cos( Millisecs()*.02 )*.5+.5,.5 )
  21. Else
  22. icanvas.Color=Color.Yellow
  23. Endif
  24. icanvas.DrawRect( x*16,y*16,16,16 )
  25. Next
  26. Next
  27. icanvas.Color=Color.White
  28. icanvas.DrawText( "This way up!",icanvas.Viewport.Width/2,0,.5,0 )
  29. icanvas.Flush()
  30. End
  31. Method OnRender( canvas:Canvas ) Override
  32. App.RequestRender()
  33. RenderImage()
  34. canvas.DrawImage( image,App.MouseLocation.x,App.MouseLocation.y )
  35. canvas.DrawText( "Here!",0,0 )
  36. End
  37. Method OnKeyEvent( event:KeyEvent ) Override
  38. Select event.Type
  39. Case EventType.KeyDown
  40. Select event.Key
  41. Case Key.Space
  42. Print "Invalidating graphics!"
  43. mojo.graphics.glutil.glGraphicsSeq+=1
  44. End
  45. End
  46. End
  47. End
  48. Function Main()
  49. New AppInstance
  50. New MyWindow
  51. App.Run()
  52. End