/// <summary> /// Function called during idle time. /// </summary> /// <returns><b>true</b> to continue execution, <b>false</b> to stop.</returns> private bool Idle() { _swap.RenderTargetView.Clear(GorgonColor.White); var windowSize = new DX.Size2F(ClientSize.Width, ClientSize.Height); var imageSize = new DX.Size2F(_texture.Width, _texture.Height); // Calculate the scale between the images. var scale = new DX.Size2F(windowSize.Width / imageSize.Width, windowSize.Height / imageSize.Height); // Only scale on a single axis if we don't have a 1:1 aspect ratio. if (scale.Height > scale.Width) { scale.Height = scale.Width; } else { scale.Width = scale.Height; } // Scale the image. var size = new DX.Size2((int)(scale.Width * imageSize.Width), (int)(scale.Height * imageSize.Height)); // Find the position. var bounds = new DX.Rectangle((int)((windowSize.Width / 2) - (size.Width / 2)), (int)((windowSize.Height / 2) - (size.Height / 2)), size.Width, size.Height); _graphics.DrawTexture(_texture, bounds); GorgonExample.BlitLogo(_graphics); _swap.Present(1); return(true); }
/// <summary> /// Function to render the data to the panel assigned in the <see cref="SetPanel"/> method. /// </summary> /// <param name="texture">The texture to render.</param> /// <param name="outputTexture">The output texture to render.</param> public void Render(GorgonTexture2DView texture, GorgonTexture2DView outputTexture) { if (_swapChain == null) { return; } if (_graphics.RenderTargets[0] != _swapChain.RenderTargetView) { _graphics.SetRenderTarget(_swapChain.RenderTargetView); } _swapChain.RenderTargetView.Clear(Color.CornflowerBlue); if ((texture == null) || (outputTexture == null)) { _swapChain.Present(1); return; } // Get aspect ratio. var scale = new DX.Size2F((_swapChain.Width * 0.5f) / texture.Width, (float)_swapChain.Height / texture.Height); // Only scale on a single axis if we don't have a 1:1 aspect ratio. if (scale.Height > scale.Width) { scale.Height = scale.Width; } else { scale.Width = scale.Height; } // Scale the image. var size = new DX.Size2((int)(scale.Width * texture.Width), (int)(scale.Height * texture.Height)); // Find the position. var bounds = new DX.Rectangle((_swapChain.Width / 4) - (size.Width / 2), ((_swapChain.Height / 2) - (size.Height / 2)), size.Width, size.Height); _graphics.DrawTexture(texture, bounds, blendState: GorgonBlendState.Default, samplerState: GorgonSamplerState.PointFiltering); bounds = new DX.Rectangle((_swapChain.Width - (_swapChain.Width / 4)) - (size.Width / 2), ((_swapChain.Height / 2) - (size.Height / 2)), size.Width, size.Height); _graphics.DrawTexture(outputTexture, bounds, blendState: GorgonBlendState.Default, samplerState: GorgonSamplerState.PointFiltering); _swapChain.Present(1); }
/// <summary> /// Function to blit the logo without the aid of the 2D renderer. /// </summary> /// <param name="graphics">The graphics interface to use.</param> public static void BlitLogo(GorgonGraphics graphics) { GorgonRenderTargetView currentRtv = graphics.RenderTargets[0]; if ((currentRtv == null) || (_logo == null)) { return; } var logoRegion = new DX.Rectangle(currentRtv.Width - _logo.Width - 5, currentRtv.Height - _logo.Height - 2, _logo.Width, _logo.Height); graphics.DrawTexture(_logo, logoRegion, blendState: GorgonBlendState.Default); }