glwindow.monkey2 1.3 KB

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