public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { gameWindow = (iPhoneOSGameView)Description.DeviceWindowHandle.NativeHandle; device.InitDefaultRenderTarget(presentationParameters); backBuffer = Texture.New2D(device, Description.BackBufferWidth, Description.BackBufferHeight, presentationParameters.BackBufferFormat, TextureFlags.RenderTarget | TextureFlags.ShaderResource); }
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { gameWindow = (iPhoneOSGameView)Description.DeviceWindowHandle.NativeHandle; device.InitDefaultRenderTarget(presentationParameters); backBuffer = device.DefaultRenderTarget; DepthStencilBuffer = device.windowProvidedDepthTexture; }
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { device.Begin(); device.InitDefaultRenderTarget(presentationParameters); device.End(); backBuffer = device.DefaultRenderTarget; DepthStencilBuffer = device.windowProvidedDepthTexture; }
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { device.InitDefaultRenderTarget(Description); //backBuffer = device.DefaultRenderTarget; // TODO: Review Depth buffer creation for both Android and iOS //DepthStencilBuffer = device.windowProvidedDepthTexture; backBuffer = Texture.New2D(device, Description.BackBufferWidth, Description.BackBufferHeight, presentationParameters.BackBufferFormat, TextureFlags.RenderTarget | TextureFlags.ShaderResource); }
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { PresentInterval = presentationParameters.PresentationInterval; backbuffer = new Texture(device); CreateSurface(); // Initialize the swap chain CreateSwapChain(); }
/// <summary> /// Initializes a new instance of the <see cref="GraphicsPresenter" /> class. /// </summary> /// <param name="device">The device.</param> /// <param name="presentationParameters"> </param> protected GraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) { GraphicsDevice = device.RootDevice; Description = presentationParameters.Clone(); ProcessPresentationParameters(); DefaultViewport = new Viewport(0, 0, Description.BackBufferWidth, Description.BackBufferHeight); // Creates a default DepthStencilBuffer. CreateDepthStencilBuffer(); }
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { PresentInterval = presentationParameters.PresentationInterval; // Initialize the swap chain swapChain = CreateSwapChain(); backBuffer = new Texture(device).InitializeFrom(swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture2D>(0), Description.BackBufferFormat.IsSRgb()); // Reload should get backbuffer from swapchain as well //backBufferTexture.Reload = graphicsResource => ((Texture)graphicsResource).Recreate(swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture>(0)); }
/// <summary> /// Constructor is private, because this is a singleton class: /// client controls should use the public AddRef method instead. /// </summary> GraphicsDeviceService(IntPtr windowHandle, int width, int height) { parameters = new PresentationParameters(); parameters.BackBufferWidth = Math.Max(width, 1); parameters.BackBufferHeight = Math.Max(height, 1); parameters.BackBufferFormat = SurfaceFormat.Color; parameters.DepthStencilFormat = DepthFormat.Depth24; parameters.DeviceWindowHandle = windowHandle; parameters.PresentationInterval = PresentInterval.Immediate; parameters.IsFullScreen = false; graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, parameters); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here GraphicsDevice.SetRenderTarget(renderer); GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); currentState.Draw(spriteBatch); spriteBatch.End(); GraphicsDevice.SetRenderTarget(null); // Obraz będzie wyświetlany na środku ekranu i będą zachowane proporcje niezaleznie od tego, // jakie są wymiary okna. PresentationParameters windowSize = GraphicsDevice.PresentationParameters; Rectangle rendererPosition = new Rectangle(0, 0, windowSize.BackBufferWidth, windowSize.BackBufferHeight); if (rendererPosition.Width > rendererPosition.Height * 4.0 / 3.0) // za szerokie { rendererPosition.Width = (int)(rendererPosition.Height * (4.0 / 3.0)); rendererPosition.X = (int)((windowSize.BackBufferWidth - rendererPosition.Width) / 2.0); } else { rendererPosition.Height = (int)(rendererPosition.Width * (3.0 / 4.0)); rendererPosition.Y = (int)((windowSize.BackBufferHeight - rendererPosition.Height) / 2.0); } GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); spriteBatch.Draw(renderer, rendererPosition, Color.White); spriteBatch.Draw(black_tile, rendererPosition, Color.White * transition_opacity); spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// BeginDraw により使用されるヘルパー。これは、グラフィック デバイスのステータスを /// チェックして、現在のコントロールの描画に十分大きく、デバイスがロストしていない /// ことを確認します。デバイスをリセットできなかった場合、エラー文字列を返します。 /// </summary> string HandleDeviceReset() { bool deviceNeedsReset = false; switch (GraphicsDevice.GraphicsDeviceStatus) { case GraphicsDeviceStatus.Lost: // グラフィック デバイスがロストしている場合は、まったく使用できません。 return("Graphics device lost"); case GraphicsDeviceStatus.NotReset: // デバイスがリセットされていない状態の場合は、リセットを試みる必要があります。 deviceNeedsReset = true; break; default: // デバイスの状態が問題ない場合、十分に大きいかどうかをチェックします。 PresentationParameters pp = GraphicsDevice.PresentationParameters; deviceNeedsReset = (ClientSize.Width > pp.BackBufferWidth) || (ClientSize.Height > pp.BackBufferHeight); break; } // デバイスをリセットする必要がありますか。 if (deviceNeedsReset) { try { graphicsDeviceService.ResetDevice(ClientSize.Width, ClientSize.Height); } catch (Exception e) { return("Graphics device reset failed\n\n" + e); } } return(null); }
public RenderSystem(PresentationParameters parameters) { Adapters = GraphicsAdapter.EnumerateGraphicsAdapter(); Device = new GraphicsDevice(Adapters[0]); SwapChain = new GraphicsSwapChain(parameters, Device); CommandList = new CommandList(Device); Texture = new Texture(Device, SwapChain); Shaders = new Shaders(Device, "Shaders/VertexShader.hlsl", "Shaders/PixelShader.hlsl"); StateWireframe = new PipelineState(Device, FillMode.Wireframe, CullMode.None); StateSolid = new PipelineState(Device, FillMode.Solid, CullMode.None); Grid = new Grid(1, 1, 8, 8); VertexBuffer = new Buffer(Grid.SizeInBytes, Grid.Size, Device, ResourceInfo.VertexBuffer); IndexBuffer = new Buffer(Grid.IndexSizeInBytes, Grid.IndexSize, Device, ResourceInfo.IndexBuffer); ConstantBuffer = new Buffer(Utilities.SizeOf <Transform>(), Utilities.SizeOf <Transform>(), Device, ResourceInfo.ConstantBuffer); TextureAddressMode Wrap = TextureAddressMode.Wrap; SamplerState = new SamplerState(Device, Wrap, Wrap, Wrap, Filter.MinMagMipLinear); Camera = new Camera(CameraType.Static); Camera.Position = new Vector3(0.0f, 0.0f, -2.5f); Camera.SetLens((float)Math.PI / 4, 1.2f, 1.0f, 1000.0f); World = new Matrix[2]; CubesTexture1 = Texture.LoadFromFile(Device, "UV_Grid_Lrg.jpg"); }
protected override void OnPaint(PaintEventArgs e) { dev.Clear(new Microsoft.Xna.Framework.Color(0, 0, 0, 0.0f)); //Stream file = File.Open("icons\\tux.png", FileMode.Open); //Texture2D imageTexture = Texture2D.FromStream(dev, file); PresentationParameters pp = dev.PresentationParameters; SpriteBatch spriteBatch = new SpriteBatch(dev); Vector2 position = new Vector2(0, 0); double me_X = Data.GetMe().Pos1.x; double me_Y = Data.GetMe().Pos1.y; Actor[] actors = Data.GetMapItems(); this.plot_obj.Clear(); foreach (Actor actor in actors) { double dx = (me_X - actor.Pos1.x); double dy = (me_Y - actor.Pos1.y); if (Math.Abs(dx) < 200 && Math.Abs(dy) < 200) { Vector2 fiks = this.CalcMinimapPos(dx, dy, actor.distanceFromMe); this.plot_obj.Add(fiks); } } spriteBatch.Begin(); foreach (Vector2 vec in this.plot_obj) { spriteBatch.Draw(fileTexture, vec, Color.White); } spriteBatch.Draw(fileTexture, minimapCenter, Color.White); spriteBatch.End(); dev.Present(); Invalidate(); }
partial void PlatformInitialize(PresentationParameters presentationParameters) { var surfaceFormat = PreferredBackBufferFormat.GetColorFormat(); var depthStencilFormat = PreferredDepthStencilFormat; // TODO: Need to get this data from the Presentation Parameters SDL.GL.SetAttribute(SDL.GL.Attribute.RedSize, surfaceFormat.R); SDL.GL.SetAttribute(SDL.GL.Attribute.GreenSize, surfaceFormat.G); SDL.GL.SetAttribute(SDL.GL.Attribute.BlueSize, surfaceFormat.B); SDL.GL.SetAttribute(SDL.GL.Attribute.AlphaSize, surfaceFormat.A); switch (depthStencilFormat) { case DepthFormat.None: SDL.GL.SetAttribute(SDL.GL.Attribute.DepthSize, 0); SDL.GL.SetAttribute(SDL.GL.Attribute.StencilSize, 0); break; case DepthFormat.Depth16: SDL.GL.SetAttribute(SDL.GL.Attribute.DepthSize, 16); SDL.GL.SetAttribute(SDL.GL.Attribute.StencilSize, 0); break; case DepthFormat.Depth24: SDL.GL.SetAttribute(SDL.GL.Attribute.DepthSize, 24); SDL.GL.SetAttribute(SDL.GL.Attribute.StencilSize, 0); break; case DepthFormat.Depth24Stencil8: SDL.GL.SetAttribute(SDL.GL.Attribute.DepthSize, 24); SDL.GL.SetAttribute(SDL.GL.Attribute.StencilSize, 8); break; } SDL.GL.SetAttribute(SDL.GL.Attribute.DoubleBuffer, 1); SDL.GL.SetAttribute(SDL.GL.Attribute.ContextMajorVersion, 2); SDL.GL.SetAttribute(SDL.GL.Attribute.ContextMinorVersion, 1); ((SDLGameWindow)_game.Window).CreateWindow(); }
public override void Activate() { #if !EDITOR _content = new ContentManager(this.ScreenManager.Game.Services, "Content"); // Simulate something large loading because why not.. // Also doing it first so that the sounds load when it's finished. //Thread.Sleep(1000); // Setup the Hud elements HUD.Instance.Load(this.ScreenManager); // Initiate and setup the level class. // Load level in a moment Camera.Instance.SetGameplayScreen(this); LoadLevel(); // Setup the SpriteManager. SpriteManager.Instance.Load(this.ScreenManager); // Setup use of shadows if they're enabled. if (GameSettings.Instance.Shadows == SettingLevel.On) { PresentationParameters pp = this.ScreenManager.GraphicsDevice.PresentationParameters; rtMask = new RenderTarget2D(this.ScreenManager.GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight); rtBlur = new RenderTarget2D(this.ScreenManager.GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight); rtEffect = new RenderTarget2D(this.ScreenManager.GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, SurfaceFormat.Color, DepthFormat.Depth24); _silhouetteEffect = _content.Load <Effect>("Assets/Other/Effects/MaskEffect"); } // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. ScreenManager.Game.ResetElapsedTime(); #endif }
/// <summary> /// Helper used by BeginDraw. This checks the graphics device status, /// making sure it is big enough for drawing the current control, and /// that the device is not lost. Returns an error string if the device /// could not be reset. /// </summary> string HandleDeviceReset() { bool deviceNeedsReset = false; switch (GraphicsDevice.GraphicsDeviceStatus) { case GraphicsDeviceStatus.Lost: // If the graphics device is lost, we cannot use it at all. return("Graphics device lost"); case GraphicsDeviceStatus.NotReset: // If device is in the not-reset state, we should try to reset it. deviceNeedsReset = true; break; default: // If the device state is ok, check whether it is big enough. PresentationParameters pp = GraphicsDevice.PresentationParameters; deviceNeedsReset = (ClientSize.Width > pp.BackBufferWidth) || (ClientSize.Height > pp.BackBufferHeight); break; } // Do we need to reset the device? if (deviceNeedsReset) { try { graphicsDeviceService.ResetDevice(ClientSize.Width, ClientSize.Height); } catch (Exception e) { return("Graphics device reset failed\n\n" + e); } } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="GraphicsPresenter" /> class. /// </summary> /// <param name="device">The device.</param> /// <param name="presentationParameters"> </param> protected GraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) { GraphicsDevice = device.RootDevice; var description = presentationParameters.Clone(); // If we are creating a GraphicsPresenter with if (device.Features.HasSRgb && device.ColorSpace == ColorSpace.Linear) { // If the device support SRgb and ColorSpace is linear, we use automatically a SRgb backbuffer if (description.BackBufferFormat == PixelFormat.R8G8B8A8_UNorm) { description.BackBufferFormat = PixelFormat.R8G8B8A8_UNorm_SRgb; } else if (description.BackBufferFormat == PixelFormat.B8G8R8A8_UNorm) { description.BackBufferFormat = PixelFormat.B8G8R8A8_UNorm_SRgb; } } else if (!device.Features.HasSRgb) { // If the device does not support SRgb, but the backbuffer format asked is SRgb, convert it to non SRgb if (description.BackBufferFormat == PixelFormat.R8G8B8A8_UNorm_SRgb) { description.BackBufferFormat = PixelFormat.R8G8B8A8_UNorm; } else if (description.BackBufferFormat == PixelFormat.B8G8R8A8_UNorm_SRgb) { description.BackBufferFormat = PixelFormat.B8G8R8A8_UNorm; } } Description = description; ProcessPresentationParameters(); DefaultViewport = new Viewport(0, 0, Description.BackBufferWidth, Description.BackBufferHeight); // Creates a default DepthStencilBuffer. CreateDepthStencilBuffer(); }
/// <summary> /// /// </summary> private void CreateGraphicsDevice() { // Create Presentation Parameters PresentationParameters pp = new PresentationParameters(); pp.BackBufferCount = 1; pp.IsFullScreen = false; pp.SwapEffect = SwapEffect.Discard; pp.BackBufferWidth = panelViewport.Width; pp.BackBufferHeight = panelViewport.Height; pp.AutoDepthStencilFormat = DepthFormat.Depth24Stencil8; pp.EnableAutoDepthStencil = true; pp.PresentationInterval = PresentInterval.Default; pp.BackBufferFormat = SurfaceFormat.Unknown; pp.MultiSampleType = MultiSampleType.None; // Create device mDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, this.panelViewport.Handle, CreateOptions.HardwareVertexProcessing, pp); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here gameBoard = new GameBoard(GameBoard.BoardName.Unicorn); gameBoard.Initialize(); pp = GraphicsDevice.PresentationParameters; renderTarget1 = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); renderTarget2 = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); lastMouseState = Mouse.GetState(); base.Initialize(); }
public Flash flash; //For anyone reading this: Don't do this. This is a very bodged approach to doing this, because I implemented the foreground/background badly. //If you want to know how to properly do it: I think Draw() supports layers? I haven't looked much into it myself, but that would be how. public GraphicsHelper(Game host) { graphics = new GraphicsDeviceManager(host); graphics.PreferredBackBufferWidth = windowWidth; graphics.PreferredBackBufferHeight = windowHeight; graphics.ApplyChanges(); PresentationParameters pp = graphics.GraphicsDevice.PresentationParameters; render = new RenderTarget2D(graphics.GraphicsDevice, renderWidth, renderHeight, false, SurfaceFormat.Color, DepthFormat.None, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); spriteBatch = new SpriteBatch(graphics.GraphicsDevice); BG = Game1.contentManager.Load <Texture2D>("BG"); FG = Game1.contentManager.Load <Texture2D>("FG"); font = Game1.contentManager.Load <SpriteFont>("font"); flash = new Flash(); //again, don't. please. Objects.List.Add(flash); //please. }
internal void INTERNAL_ResizeGraphicsDevice(int width, int height) { PresentationParameters pp = GraphicsDevice.PresentationParameters; // Only reset if there's an actual change in size if (pp.BackBufferWidth != width || pp.BackBufferHeight != height) { // We're about to reset a device, notify the application. OnDeviceResetting(this, EventArgs.Empty); pp.BackBufferWidth = width; pp.BackBufferHeight = height; GraphicsDevice.Reset(); // We just reset a device, notify the application. OnDeviceReset(this, EventArgs.Empty); // FIXME: When does this actually happen? UpdateTouchPanel(); } }
/// <summary> /// Load your graphics content. /// </summary> public static void LoadContent() { spriteBatch = new SpriteBatch(BeatShift.graphics.GraphicsDevice); bloomExtractEffect = BeatShift.contentManager.Load <Effect>("Shaders/BloomExtract"); bloomCombineEffect = BeatShift.contentManager.Load <Effect>("Shaders/BloomCombine"); gaussianBlurEffect = BeatShift.contentManager.Load <Effect>("Shaders/GaussianBlur"); outputEffect = BeatShift.contentManager.Load <Effect>("Shaders/ShowTexture"); blackTexture = BeatShift.contentManager.Load <Texture2D>("Textures/1pxBlack"); // Look up the resolution and format of our main backbuffer. PresentationParameters pp = BeatShift.graphics.GraphicsDevice.PresentationParameters; int width = pp.BackBufferWidth; int height = pp.BackBufferHeight; SurfaceFormat format = pp.BackBufferFormat; // Create a texture for rendering the main scene, prior to applying bloom. sceneRenderTarget = new RenderTarget2D(BeatShift.graphics.GraphicsDevice, width, height, false, format, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); glowRenderTarget = new RenderTarget2D(BeatShift.graphics.GraphicsDevice, width, height, false, format, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); // Create two rendertargets for the bloom processing. These are half the // size of the backbuffer, in order to minimize fillrate costs. Reducing // the resolution in this way doesn't hurt quality, because we are going // to be blurring the bloom images in any case. width /= 2; height /= 2; renderTarget1 = new RenderTarget2D(BeatShift.graphics.GraphicsDevice, width, height, false, format, DepthFormat.None); renderTarget2 = new RenderTarget2D(BeatShift.graphics.GraphicsDevice, width, height, false, format, DepthFormat.None); }
public SwapChain(Device device, PresentationParameters parameters) : base(device) { Parameters = parameters; SwapchainSource ??= parameters.SwapchainSource; surface = CreateSurface(); CreateSwapChain(); CreateBackBuffers(); //DepthStencil = new Texture(device, new TextureDescription //{ // Flags = TextureFlags.DepthStencil, // Usage = GraphicsResourceUsage.Default, // Width = Parameters.BackBufferWidth, // Height = Parameters.BackBufferHeight, //}); }
string HandleDeviceReset() { bool deviceNeedsReset = false; switch (GraphicsDevice.GraphicsDeviceStatus) { case GraphicsDeviceStatus.Lost: return("Graphics device lost"); case GraphicsDeviceStatus.NotReset: deviceNeedsReset = true; break; default: PresentationParameters pp = GraphicsDevice.PresentationParameters; deviceNeedsReset = (ClientSize.Width > pp.BackBufferWidth) || (ClientSize.Height > pp.BackBufferHeight); break; } if (deviceNeedsReset) { try { graphicsDeviceService.ResetDevice(_renderTarget.Width, _renderTarget.Height); _renderTarget.Dispose(); _renderTarget = new SwapChainRenderTarget(GraphicsDevice, Handle, ClientSize.Width, ClientSize.Height); } catch (Exception e) { return("Graphics device reset failed\n\n" + e); } } return(null); }
private void CreateDevice(IntPtr windowHandle, int width, int height) { parameters = new PresentationParameters(); parameters.BackBufferWidth = Math.Max(width, 1); parameters.BackBufferHeight = Math.Max(height, 1); parameters.BackBufferFormat = SurfaceFormat.Color; parameters.DepthStencilFormat = DepthFormat.Depth24; parameters.DeviceWindowHandle = windowHandle; parameters.PresentationInterval = PresentInterval.Immediate; parameters.IsFullScreen = false; graphicsDevice = new GraphicsDevice( GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, parameters); if (DeviceCreated != null) { DeviceCreated(this, EventArgs.Empty); } }
public void PlatformInitialize(PresentationParameters presentationParameters) { var surfaceFormat = PreferredBackBufferFormat.GetColorFormat(); var depthStencilFormat = PreferredDepthStencilFormat; Sdl.GL.SetAttribute(Sdl.GL.Attribute.RedSize, surfaceFormat.R); Sdl.GL.SetAttribute(Sdl.GL.Attribute.GreenSize, surfaceFormat.G); Sdl.GL.SetAttribute(Sdl.GL.Attribute.BlueSize, surfaceFormat.B); Sdl.GL.SetAttribute(Sdl.GL.Attribute.AlphaSize, surfaceFormat.A); switch (depthStencilFormat) { case DepthFormat.None: Sdl.GL.SetAttribute(Sdl.GL.Attribute.DepthSize, 0); Sdl.GL.SetAttribute(Sdl.GL.Attribute.StencilSize, 0); break; case DepthFormat.Depth16: Sdl.GL.SetAttribute(Sdl.GL.Attribute.DepthSize, 16); Sdl.GL.SetAttribute(Sdl.GL.Attribute.StencilSize, 0); break; case DepthFormat.Depth24: Sdl.GL.SetAttribute(Sdl.GL.Attribute.DepthSize, 24); Sdl.GL.SetAttribute(Sdl.GL.Attribute.StencilSize, 0); break; case DepthFormat.Depth24Stencil8: Sdl.GL.SetAttribute(Sdl.GL.Attribute.DepthSize, 24); Sdl.GL.SetAttribute(Sdl.GL.Attribute.StencilSize, 8); break; } Sdl.GL.SetAttribute(Sdl.GL.Attribute.DoubleBuffer, 1); Sdl.GL.SetAttribute(Sdl.GL.Attribute.ContextMajorVersion, 2); Sdl.GL.SetAttribute(Sdl.GL.Attribute.ContextMinorVersion, 1); ((SdlGameWindow)SdlGameWindow.Instance).CreateWindow(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { const String root = "Sprites01_64"; images = new Texture2D[10]; for (int index = 0; index < 10; index++) { string suffix = (index + 1).ToString().PadLeft(2, '0'); String assetName = String.Format("{0}/{1}/{2}{3}", root, entityType, actionType, suffix); images[index] = Content.Load <Texture2D>(assetName); } // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Render target PresentationParameters pp = GraphicsDevice.PresentationParameters; int width = pp.BackBufferWidth; int height = pp.BackBufferHeight; renderTarget = new RenderTarget2D(GraphicsDevice, width, height, 1, GraphicsDevice.DisplayMode.Format); }
public void SetupCameraTexturesAndFonts() { // Set the form click-through //int initialStyle = GetWindowLong(this.Handle, -20); //SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20); // Create device presentation parameters PresentationParameters p = new PresentationParameters(); p.IsFullScreen = false; p.DeviceWindowHandle = this.Handle; p.BackBufferFormat = SurfaceFormat.Vector4; p.PresentationInterval = PresentInterval.One; // Create XNA graphics device dev = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, p); //dev.BlendState = BlendState.AlphaBlend; // Init basic effect effect = new BasicEffect(dev); //Image2Texture(global::Skype.Properties.Resources.ILTRight1, dev, ref rightArrow); //Image2Texture(global::fishnado.Properties.Resources.Black, dev, ref blackTexture); //Image2Texture(global::fishnado.Properties.Resources.White, dev, ref whiteTexture); Image2Texture(System.Drawing.Image.FromFile("Graphics/Images/WhiteCircle.png"), dev, ref circleTexture); Image2Texture(System.Drawing.Image.FromFile("Graphics/Images/WhiteSquare.png"), dev, ref squareTexture); Image2Texture(System.Drawing.Image.FromFile("Graphics/Images/moe.png"), dev, ref moeTexture); IServiceProvider isp = new ServiceCollection(); CustomGraphicsDeviceService gds = new CustomGraphicsDeviceService(); gds.GraphicsDevice = dev; ((ServiceCollection)isp).AddService <IGraphicsDeviceService>(gds); contentManager = new ContentManager(isp); font = contentManager.Load <SpriteFont>("Graphics/SpriteFonts/Courier"); }
protected override void Initialize() { base.Initialize(); PresentationParameters pp = GraphicsDevice.PresentationParameters; width = pp.BackBufferWidth; height = pp.BackBufferHeight; // Camera Position und View-Vector festlegen camera.Position = new Vector3(0.0f, 3.0f, 10.0f); camera.LookAt(new Vector3(0.0f, 1.0f, 0.0f)); float sin = (float)Math.Sin(MathHelper.ToRadians(30.0f)); float cos = (float)Math.Cos(MathHelper.ToRadians(30.0f)); float lightHeight = 5.0f; float lightRadius = 10.0f; // Eigenschaften der Lichter setzen lights.NearPlaneDistance = 2.0f; lights.FarPlaneDistance = 20.0f; lights.Speed = 0.5f; lights.Add(0.0f, lightHeight, lightRadius); lights.Add(cos * lightRadius, lightHeight, -sin * lightRadius); lights.Add(-cos * lightRadius, lightHeight, -sin * lightRadius); // Würfel und Pick-Ray auf unsichtbar setzen cubes.Visible = false; ray.Visible = false; // Camera-Tracker deaktivieren cameraTracker.Enabled = false; // Antialiasing auf 4x setzen GraphicsDevice.PresentationParameters.MultiSampleCount = 4; }
public void Resize(Vector2 WindowSize) { if (WindowSize.X < 100 || WindowSize.Y < 0) { return; } try { if (renderTarget1 != null) { renderTarget1.Dispose(); } } catch (Exception e) { Console.WriteLine(e.Message); } try { if (renderTarget2 != null) { renderTarget2.Dispose(); } } catch (Exception e) { Console.WriteLine(e.Message); } PresentationParameters pp = Game1.graphicsDevice.PresentationParameters; int width = (int)WindowSize.X / 2; int height = (int)WindowSize.Y / 2; SurfaceFormat format = pp.BackBufferFormat; DepthFormat depthFormat = pp.DepthStencilFormat; renderTarget1 = new RenderTarget2D(Game1.graphicsDevice, width, height, false, format, depthFormat); renderTarget2 = new RenderTarget2D(Game1.graphicsDevice, width, height, false, format, depthFormat); }
/// <summary> /// Helper used by <see cref="OnCompositionTargetRendering"/>. /// This checks the graphics device status, /// making sure it is big enough for drawing the current control, and /// that the device is not lost. Returns an error string if the device /// could not be reset. /// </summary> private GraphicsDeviceResetStatus HandleDeviceReset(int width, int height) { bool deviceNeedsReset; switch (_graphicsService.GraphicsDevice.GraphicsDeviceStatus) { case GraphicsDeviceStatus.Lost: // If the graphics device is lost, we cannot use it at all. return(GraphicsDeviceResetStatus.Lost); case GraphicsDeviceStatus.NotReset: // If device is in the not-reset state, we should try to reset it. deviceNeedsReset = true; break; default: // If the device state is ok, check whether it is big enough. PresentationParameters pp = _graphicsService.GraphicsDevice.PresentationParameters; deviceNeedsReset = (width > pp.BackBufferWidth) || (height > pp.BackBufferHeight); break; } // Do we need to reset the device? if (deviceNeedsReset) { try { _graphicsService.ResetDevice(width, height); } catch { return(GraphicsDeviceResetStatus.ResetFailed); } } return(GraphicsDeviceResetStatus.Normal); }
internal void ResetWindowBounds(bool toggleFullScreen) { Rectangle clientBounds = this.Window.ClientBounds; bool isActive = this.IsActive; this.IsActive = false; GraphicsDeviceManager graphicsDeviceManager = (GraphicsDeviceManager)this.Game.Services.GetService(typeof(IGraphicsDeviceManager)); this.VSyncEnabled = graphicsDeviceManager.SynchronizeWithVerticalRetrace; if (graphicsDeviceManager.IsFullScreen) { clientBounds = new Rectangle(0, 0, graphicsDeviceManager.PreferredBackBufferWidth, graphicsDeviceManager.PreferredBackBufferHeight); if (DisplayDevice.Default.Width != graphicsDeviceManager.PreferredBackBufferWidth || DisplayDevice.Default.Height != graphicsDeviceManager.PreferredBackBufferHeight) { DisplayDevice.Default.ChangeResolution(graphicsDeviceManager.PreferredBackBufferWidth, graphicsDeviceManager.PreferredBackBufferHeight, DisplayDevice.Default.BitsPerPixel, DisplayDevice.Default.RefreshRate); } } else { DisplayDevice.Default.RestoreResolution(); clientBounds.Width = graphicsDeviceManager.PreferredBackBufferWidth; clientBounds.Height = graphicsDeviceManager.PreferredBackBufferHeight; } GraphicsDevice graphicsDevice = graphicsDeviceManager.GraphicsDevice; if (graphicsDevice != null) { PresentationParameters presentationParameters = graphicsDevice.PresentationParameters; presentationParameters.BackBufferHeight = clientBounds.Height; presentationParameters.BackBufferWidth = clientBounds.Width; } if (graphicsDeviceManager.IsFullScreen != this.isCurrentlyFullScreen) { this._view.ToggleFullScreen(); } this._view.ChangeClientBounds(clientBounds); this.isCurrentlyFullScreen = graphicsDeviceManager.IsFullScreen; this.IsActive = isActive; }
/// <summary> /// Creates the <see cref="Microsoft.Xna.Framework.Graphics.GraphicsDevice"/>. /// </summary> /// <param name="control">The host control.</param> /// <param name="width"></param> /// <param name="height"></param> public void CreateDevice(Control control, int width, int height) { this.host = control; PresentationParameters pp; pp = new PresentationParameters(); pp.BackBufferWidth = width; pp.BackBufferHeight = height; pp.BackBufferFormat = SurfaceFormat.Color; pp.EnableAutoDepthStencil = true; pp.AutoDepthStencilFormat = DepthFormat.Depth24; this.GraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, control.Handle, pp); if (this.DeviceCreated != null) { this.DeviceCreated(this, EventArgs.Empty); } }
static public SharpDX.DXGI.SwapEffect ToSwapEffect(PresentationParameters present) { SharpDX.DXGI.SwapEffect effect; switch (present.PresentationInterval) { case PresentInterval.One: case PresentInterval.Two: default: effect = SharpDX.DXGI.SwapEffect.FlipSequential; break; case PresentInterval.Immediate: effect = SharpDX.DXGI.SwapEffect.Sequential; break; } //if (present.RenderTargetUsage != RenderTargetUsage.PreserveContents && present.MultiSampleCount == 0) //effect = SharpDX.DXGI.SwapEffect.Discard; return(effect); }
public LevelSelectState() { //GameCampaign.levelMap = new LevelData[6, 3]; wireframe = TextureLib.getLoadedTexture("shipWireframe.png"); PresentationParameters pp = AnimationLib.GraphicsDevice.PresentationParameters; textureScreen = new RenderTarget2D(AnimationLib.GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, AnimationLib.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); halfTextureScreen = new RenderTarget2D(AnimationLib.GraphicsDevice, pp.BackBufferWidth / 2, pp.BackBufferHeight / 2, false, AnimationLib.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); quarterTextureScreen = new RenderTarget2D(AnimationLib.GraphicsDevice, pp.BackBufferWidth / 4, pp.BackBufferHeight / 4, false, AnimationLib.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); sb2 = new SpriteBatch(AnimationLib.GraphicsDevice); /* * for (int i = 0; i < GameCampaign.levelMap.GetLength(0); i++) * { * for (int j = 0; j < GameCampaign.levelMap.GetLength(1); j++) * { * GameCampaign.levelMap[i, j] = new LevelData(Game1.rand.NextDouble(), Game1.rand.NextDouble(), Game1.rand.NextDouble(), Game1.rand.NextDouble()); * } * } * * GameCampaign.levelMap[0, 0].visible = false; * GameCampaign.levelMap[0, 2].visible = false; * GameCampaign.levelMap[GameCampaign.levelMap.GetLength(0) - 1, 0].visible = false; * GameCampaign.levelMap[GameCampaign.levelMap.GetLength(0) - 1, 2].visible = false; */ selectedLevelX = GameCampaign.PlayerLevelProgress + 1; selectedLevelY = GameCampaign.PlayerFloorHeight; cursorPosition = new Vector2(((GameCampaign.PlayerLevelProgress * 128) + drawMapTestOffset.X), ((GameCampaign.PlayerFloorHeight * 96) + drawMapTestOffset.Y)); cursorAnimationTime = 0; state = LevelSelectStateState.AnimateIn; openingSoundMade = false; }
public OverlayForm(System.Windows.Forms.Screen screen, OverlayData overlay_data) { this.screen = screen; this.overlay_data = overlay_data; InitializeComponent(); ShowInTaskbar = false; StartPosition = System.Windows.Forms.FormStartPosition.Manual; FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; // no borders SetBounds(screen.Bounds.Left, screen.Bounds.Top, screen.Bounds.Width, screen.Bounds.Height); TopMost = true; // make the form always on top Visible = true; // Important! if this isn't set, then the form is not shown at all // Set the form click-through int initialStyle = GetWindowLong(this.Handle, -20); SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20); // Create device presentation parameters PresentationParameters p = new PresentationParameters(); p.IsFullScreen = false; p.DeviceWindowHandle = this.Handle; p.BackBufferFormat = SurfaceFormat.Vector4; p.PresentationInterval = PresentInterval.One; // Create XNA graphics device dev = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, p); scaleX = 2.0f / dev.Viewport.Width; scaleY = 2.0f / dev.Viewport.Height; // Init basic effect effect = new BasicEffect(dev); // Extend aero glass style on form init OnResize(null); refresher = new Thread(new ThreadStart(this.RedrawCycle)); refresher.Start(); }
public HUD(IntPtr windowHandle) { // Create device presentation parameters PresentationParameters p = new PresentationParameters(); p.IsFullScreen = false; p.DeviceWindowHandle = windowHandle; p.BackBufferFormat = SurfaceFormat.Vector4; p.PresentationInterval = PresentInterval.One; // Create XNA graphics device dev = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, p); using (FileStream stream = new FileStream(@"Content\Target.png", FileMode.Open)) { targetTexture = Texture2D.FromStream(dev, stream); } using (FileStream stream = new FileStream(@"Content\Move.png", FileMode.Open)) { moveModeTexture = Texture2D.FromStream(dev, stream); } using (FileStream stream = new FileStream(@"Content\Pointer.png", FileMode.Open)) { pointerModeTexture = Texture2D.FromStream(dev, stream); } using (FileStream stream = new FileStream(@"Content\ControllerNotFound.png", FileMode.Open)) { controllerNotFoundTexture = Texture2D.FromStream(dev, stream); } // Init basic effect effect = new BasicEffect(dev); spriteBatch = new SpriteBatch(dev); }
public bool CreateGraphicsContext(IntPtr hwnd, ref PresentationParameters pp) { //define presentation parameters pp = new PresentationParameters(); pp.BackBufferCount = 1; pp.BackBufferFormat = SurfaceFormat.Unknown; pp.DeviceWindowHandle = hwnd; pp.IsFullScreen = false; pp.SwapEffect = SwapEffect.Discard; pp.BackBufferHeight = Control.FromHandle(hwnd).Height; pp.BackBufferWidth = Control.FromHandle(hwnd).Width; //Initialize Z-buffer - need this for winform pp.EnableAutoDepthStencil = true; pp.AutoDepthStencilFormat = DepthFormat.Depth24; if (m_XNA_GraphicsDevice != null) { return(false); } //create an XNA graphics device m_XNA_GraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, hwnd, pp); //check if graphics device was created Debug.Assert(m_XNA_GraphicsDevice != null, "XNA Graphics Device did not Initialize"); m_EffectPool = new EffectPool(); m_BasicEffect = new BasicEffect(m_XNA_GraphicsDevice, m_EffectPool); //set the model matrix to identity m_BasicEffect.World = Matrix.Identity; m_BasicEffect.View = Matrix.Identity; m_BasicEffect.Projection = Matrix.Identity; m_XNA_GraphicsDevice.RenderState.DepthBufferEnable = true; m_XNA_GraphicsDevice.RenderState.DepthBufferWriteEnable = true; return(true); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { const String root = "Sprites01_64"; monsters = new Texture2D[8]; monstNames = new string[8]; for (int index = 0; index < 4; index++) { int count = index * 2 + 0; String assetName0 = String.Format("{0}/{1}", (MonsterLett)index, (MonsterType)0); monstNames[count] = assetName0.Replace("/", "_"); monsters[count] = Content.Load <Texture2D>(root + "/" + assetName0); count = index * 2 + 1; String assetName1 = String.Format("{0}/{1}", (MonsterLett)index, (MonsterType)1); monstNames[count] = assetName1.Replace("/", "_"); monsters[count] = Content.Load <Texture2D>(root + "/" + assetName1); } players = new Texture2D[5]; playerNames = new string[5]; for (int index = 0; index < 5; index++) { String assetName = String.Format("Player/{0}", (PlayerType)index); playerNames[index] = assetName.Replace("/", "_"); players[index] = Content.Load <Texture2D>(root + "/" + assetName); } // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Render target PresentationParameters pp = GraphicsDevice.PresentationParameters; int width = pp.BackBufferWidth; int height = pp.BackBufferHeight; renderTarget = new RenderTarget2D(GraphicsDevice, width, height, 1, GraphicsDevice.DisplayMode.Format); }
private void AddGraphicsService() { // ----- Storage // Create a "virtual file system" for reading game assets. var titleStorage = new TitleStorage("Content"); var assetsStorage = new ZipStorage(titleStorage, "DigitalRune.Editor.Game.zip"); var digitalRuneStorage = new ZipStorage(titleStorage, "DigitalRune.zip"); var vfsStorage = new VfsStorage(); vfsStorage.MountInfos.Add(new VfsMountInfo(titleStorage, null)); vfsStorage.MountInfos.Add(new VfsMountInfo(assetsStorage, null)); vfsStorage.MountInfos.Add(new VfsMountInfo(digitalRuneStorage, null)); // ----- Content _contentManager = new StorageContentManager(Editor.Services, vfsStorage); //_contentManager = new ContentManager(serviceContainer, "Content"); Editor.Services.Register(typeof(ContentManager), null, _contentManager); // ----- Animations _animationManager = new AnimationManager(); Editor.Services.Register(typeof(IAnimationService), null, _animationManager); // ----- Graphics // Create Direct3D 11 device. var presentationParameters = new PresentationParameters { BackBufferWidth = 1, BackBufferHeight = 1, DeviceWindowHandle = IntPtr.Zero }; var graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.HiDef, presentationParameters); Editor.Services.Register(typeof(IGraphicsDeviceService), null, new GraphicsDeviceManager(graphicsDevice)); // Create and register the graphics manager. _graphicsManager = new GraphicsManager(graphicsDevice, _contentManager); Editor.Services.Register(typeof(IGraphicsService), null, _graphicsManager); }
protected virtual void CreateOrUpdatePresenter() { if (Presenter == null) { PixelFormat resizeFormat; var size = GetRequestedSize(out resizeFormat); var presentationParameters = new PresentationParameters((int)size.X, (int)size.Y, Window.NativeWindow, resizeFormat) { DepthStencilFormat = PreferredDepthStencilFormat }; presentationParameters.PresentationInterval = PresentInterval.Immediate; Presenter = new SwapChainGraphicsPresenter(GraphicsDevice, presentationParameters); isBackBufferToResize = false; } }
/// Initializes a new instance of the AvateeringXNA class. public AvateeringXNA() { Window.Title = "Test1"; IsFixedTimeStep = false; IsMouseVisible = true; // Components.Add(new FrameRateCounter(this)); - откл. т.к. вызывает баг - меняет порядок отрисовки 3Д объектов // Setup the graphics device for rendering graphics = new GraphicsDeviceManager(this); presentationParameters = new PresentationParameters(); SetScreenMode(); graphics.PreparingDeviceSettings += GraphicsDevicePreparingDeviceSettings; graphics.SynchronizeWithVerticalRetrace = true; graphics.PreferMultiSampling = true; // включили anti-aliasing graphics.SynchronizeWithVerticalRetrace = true; // presentationParameters.MultiSampleCount = 4; Content.RootDirectory = "Content"; // The Kinect sensor will use 640x480 for the color stream (default) and 640x480 for depth chooser = new KinectChooser(this, ColorImageFormat.RgbResolution640x480Fps30, DepthImageFormat.Resolution640x480Fps30); Services.AddService(typeof(KinectChooser), chooser); // Optionally set near mode for close range avateering (0.4m up to 3m) chooser.NearMode = true; // Optionally set seated mode for upper-body only tracking here (typically used with near mode for close to camera tracking) chooser.SeatedMode = true; // Adding these objects as XNA Game components enables automatic calls to the overridden LoadContent, Update, etc.. methods Components.Add(chooser); // Create a ground plane for the model to stand on //planarXzGrid = new GridXz(this, new Vector3(0, 0, 0), new Vector2(500, 500), new Vector2(10, 10), Color.Black); //Components.Add(planarXzGrid); //drawGrid = false; worldAxes = new CoordinateCross(this, 500); Components.Add(worldAxes); // Create the avatar animator //animator = new AvatarAnimator(this, RetargetMatrixHierarchyToAvatarMesh, AvateeringXNA.skeletonTranslationScaleFactor); //Components.Add(animator); // Drawing options skeletonDetected = true; // Setup the depth stream depthStream = new DepthStreamRenderer(this); // Setup the skeleton stream the same as depth stream skeletonStream = new SkeletonStreamRenderer(this, SkeletonToDepthMap); // Update Depth and Skeleton Stream size and location based on the back-buffer UpdateStreamSizeAndLocation(); previousKeyboard = Keyboard.GetState(); previousCollideResult2 = ContainmentType.Disjoint; CursorRight = new Cursor(this, "cursor_ball"); CursorLeft = new Cursor(this, "cursor_ball"); // Video_box2 = new IconBoxVideo(this, "wildlife1"); // iconboxAudio1 = new IconBoxAudio(this, "Kalimba"); // iconboxPicture1 = new IconBoxPicture(this, "Lighthouse"); // iconboxText1 = new IconBoxText(this); BossPanel = new MainOperatorPanel(this); CurrentTask[0] = new Task(this, Task.MediaType.Audio, Task.ManagerStatus.Assigned, Task.ProgressStatus.New, Task.PresentationType.PanelIcon, "Kalimba", 12); CurrentTask[0].LoadContent(this); CurrentTask[1] = new Task(this, Task.MediaType.Video, Task.ManagerStatus.NotAssigned, Task.ProgressStatus.New, Task.PresentationType.PanelIcon, "wildlife1", 4); CurrentTask[1].LoadContent(this); CurrentTask[2] = new Task(this, Task.MediaType.Picture, Task.ManagerStatus.Finished, Task.ProgressStatus.New, Task.PresentationType.PanelIcon, "Lighthouse", 37); CurrentTask[2].LoadContent(this); }
private void FitPresentationParametersToWindowRatio(int windowWidth, int windowHeight, PresentationParameters parameters) { var desiredWidth = parameters.BackBufferWidth; var desiredHeight = parameters.BackBufferHeight; if (windowWidth >= windowHeight) // Landscape => use height as base { parameters.BackBufferHeight = (int)(desiredWidth * (float)windowHeight / (float)windowWidth); } else // Portrait => use width as base { parameters.BackBufferWidth = (int)(desiredHeight * (float)windowWidth / (float)windowHeight); } }
private void FitPresentationParametersToWindowSize(int windowWidth, int windowHeight, PresentationParameters parameters) { parameters.BackBufferWidth = windowWidth; parameters.BackBufferHeight = windowHeight; }
private void FitPresentationParametersToDesiredValues(int windowWidth, int windowHeight, PresentationParameters parameters) { // nothing to do (default behavior) }
/// <summary> /// Initializes a new instance of the <see cref="GraphicsDeviceInformation" /> class. /// </summary> public GraphicsDeviceInformation() { Adapter = GraphicsAdapterFactory.Default; PresentationParameters = new PresentationParameters(); }
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { device.InitDefaultRenderTarget(presentationParameters); backBuffer = Texture.New2D(device, Description.BackBufferWidth, Description.BackBufferHeight, presentationParameters.BackBufferFormat, TextureFlags.RenderTarget | TextureFlags.ShaderResource); }
/// <summary> /// Initializes this instance. /// </summary> /// <param name="adapter">The graphics adapter.</param> /// <param name="profile">The graphics profile.</param> protected void Initialize(GraphicsAdapter adapter, GraphicsProfile profile, PresentationParameters presentationParameters, object windowHandle) { throw new NotImplementedException(); }
/// <summary> /// Set and modify any platform specific presentation information. /// </summary> public override void OnPreparePresentationParameters(PresentationParameters parameters) { parameters.BackBufferWidth = 1280; parameters.BackBufferHeight = 720; parameters.DepthStencilFormat = DepthFormat.Depth24Stencil8; }
private void FitPresentationParametersToWindowRatio(int windowWidth, int windowHeight, PresentationParameters parameters) { var panelRatio = (float)windowWidth / windowHeight; var desiredWidth = parameters.BackBufferWidth; var desiredHeight = parameters.BackBufferHeight; if (panelRatio >= 1.0f) // Landscape => use height as base { parameters.BackBufferHeight = (int)(desiredWidth / panelRatio); } else // Portrait => use width as base { parameters.BackBufferWidth = (int)(desiredHeight * panelRatio); } }