glwindow.monkey2 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. Namespace mojo.app
  2. Class GLWindow Extends Window
  3. Method New( title:String="Window",width:Int=640,height:Int=480,flags:WindowFlags=Null )
  4. Super.New( title,width,height,flags )
  5. Init()
  6. End
  7. Method New( title:String,rect:Recti,flags:WindowFlags=Null )
  8. Super.New( title,rect,flags )
  9. Init()
  10. End
  11. #rem monkeydoc Switches from shared GL context to private GL context.
  12. #end
  13. Method BeginGL()
  14. #If __HOSTOS__="macos"
  15. glFlush()
  16. #Endif
  17. SDL_GL_MakeCurrent( SDLWindow,_sdlGLContext )
  18. End
  19. #rem monkeydoc Switches from private GL back to shared GL context.
  20. #end
  21. Method EndGL()
  22. #If __HOSTOS__="macos"
  23. glFlush()
  24. #Endif
  25. SDL_GL_MakeCurrent( Super.SDLWindow,Super.SDLGLContext )
  26. End
  27. Protected
  28. #rem monkeydoc Override this method with your mojo rendering code.
  29. Note: If you override this method, you must call Super.OnRender() at some point for [[OnRenderGL]] to be called.
  30. #end
  31. Method OnRender( canvas:Canvas ) Override
  32. BeginGL()
  33. OnRenderGL()
  34. EndGL()
  35. End
  36. #rem monkeydoc Override this method with your custom GL rendering code.
  37. #end
  38. Method OnRenderGL() Virtual
  39. End
  40. Private
  41. Field _sdlGLContext:SDL_GLContext
  42. Method Init()
  43. _sdlGLContext=SDL_GL_CreateContext( SDLWindow )
  44. Assert( _sdlGLContext,"FATAL ERROR: SDL_GL_CreateContext failed" )
  45. End
  46. End