protected override void OnCreateControl() { if( !DesignMode ) { _deviceService = GraphicsDeviceService.AddRef( Handle, ClientSize.Width, ClientSize.Height ); ServiceLocator.Add<IGraphicsDeviceService>( _deviceService ); ServiceLocator.Add( _deviceService.GraphicsDevice ); ServiceLocator.Add<IEntityService>( new EntityService() ); ServiceLocator.Add<ICollisionService>( new CollisionService() ); _camera = new Camera( _deviceService.GraphicsDevice.Viewport ); if( !ServiceLocator.Has<Camera>() ) ServiceLocator.Add( _camera ); if( ControlInitializing != null ) { ControlInitializing( this, EventArgs.Empty ); } // Start the animation timer. _timer = Stopwatch.StartNew(); Initialize(); if( ControlInitialized != null ) { ControlInitialized( this, EventArgs.Empty ); } Application.Idle += ( o, args ) => Invalidate( true ); } }
private string BeginDraw() { if( _deviceService == null ) { return Text + "\n\n" + GetType(); } string deviceResetError = HandleDeviceReset(); if( !string.IsNullOrEmpty( deviceResetError ) ) { return deviceResetError; } GLControl control = GLControl.FromHandle( _deviceService.GraphicsDevice.PresentationParameters.DeviceWindowHandle ) as GLControl; if( control != null ) { control.Context.MakeCurrent( WindowInfo ); _deviceService.GraphicsDevice.PresentationParameters.BackBufferHeight = ClientSize.Height; _deviceService.GraphicsDevice.PresentationParameters.BackBufferWidth = ClientSize.Width; } Viewport viewport = new Viewport(); viewport.X = 0; viewport.Y = 0; viewport.Width = ClientSize.Width; viewport.Height = ClientSize.Height; viewport.MinDepth = 0; viewport.MaxDepth = 1; Viewport viewport2 = new Viewport(); viewport2.X = 0; viewport2.Y = 0; viewport2.Width = 0; viewport2.Height = 0; viewport2.MinDepth = 0; viewport2.MaxDepth = 1; if( GraphicsDevice.Viewport.Equals( viewport ) == false ) { GraphicsDevice.Viewport = viewport; var zoom = _camera.Zoom; _camera = new Camera(viewport2); _camera.Zoom = zoom; ServiceLocator.Add(_camera); } return null; }