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); }
/// <summary> /// Attempts to begin drawing the control. Returns an error message string /// if this was not possible, which can happen if the graphics device is /// lost, or if we are running inside the Form designer. /// </summary> string BeginDraw() { // If we have no graphics device, we must be running in the designer. if (graphicsDeviceService == null) { return(Text + "\n\n" + GetType()); } // Make sure the graphics device is big enough, and is not lost. string deviceResetError = HandleDeviceReset(); if (!string.IsNullOrEmpty(deviceResetError)) { return(deviceResetError); } GLControl control = GLControl.FromHandle(graphicsDeviceService.GraphicsDevice.PresentationParameters.DeviceWindowHandle) as GLControl; if (control != null) { control.Context.MakeCurrent(WindowInfo); graphicsDeviceService.GraphicsDevice.PresentationParameters.BackBufferHeight = ClientSize.Height; graphicsDeviceService.GraphicsDevice.PresentationParameters.BackBufferWidth = ClientSize.Width; control.KeyDown += new KeyEventHandler(control_KeyDown); } // Many GraphicsDeviceControl instances can be sharing the same // GraphicsDevice. The device backbuffer will be resized to fit the // largest of these controls. But what if we are currently drawing // a smaller control? To avoid unwanted stretching, we set the // viewport to only use the top left portion of the full backbuffer. Viewport viewport = new Viewport(); viewport.X = 0; viewport.Y = 0; viewport.Width = ClientSize.Width; viewport.Height = ClientSize.Height; viewport.MinDepth = 0; viewport.MaxDepth = 1; GraphicsDevice.Viewport = viewport; return(null); }
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; if (GraphicsDevice.Viewport.Bounds != viewport.Bounds) { GraphicsDevice.Viewport = viewport; } return(null); }