public void SetViewport(int x, int y, int width, int height, float orthoSize = 0, bool virtualScreen = false) { if (zNear == 0 && zFar == 0) { zNear = -1; zFar = 1; } // store values before changes this.viewportPosition = new Vector2(x, y); this.viewportSize = new Vector2(width, height); // fix y as it is downsided in OpenGL y = (this.height - y) - height; if (virtualScreen) { Graphics.Viewport(0, 0, width, height); } else { Graphics.Viewport((int)(x * this.scaleX), (int)(y * this.scaleY), (int)(width * this.scaleX), (int)(height * this.scaleY)); } this._aspectRatio = (float)width / (float)height; if (orthoSize == 0) { orthoSize = this.defaultOrthographicSize; } // use units instead of pixels ? #if __SHARPDX__ if (orthoSize > 0) { Matrix4.OrthoOffCenterRH(0, orthoSize * this._aspectRatio, orthoSize, 0, zNear, zFar, out this.projectionMatrix); } else { Matrix4.OrthoOffCenterRH(0, width, height, 0, zNear, zFar, out this.projectionMatrix); } #else if (orthoSize > 0) { this.projectionMatrix = Matrix4.CreateOrthographicOffCenter(0, orthoSize * this._aspectRatio, orthoSize, 0, zNear, zFar); } else { this.projectionMatrix = Matrix4.CreateOrthographicOffCenter(0, width, height, 0, zNear, zFar); } #endif this.currentOrthographicSize = orthoSize; }