/// <summary> /// Function to handle idle time for the application. /// </summary> /// <returns><b>true</b> to continue processing, <b>false</b> to stop.</returns> private static bool Idle() { // This will clear the swap chain to the specified color. _swap.RenderTargetView.Clear(Color.CornflowerBlue); // Draw our triangle. _graphics.Submit(_drawCall); GorgonExample.BlitLogo(_graphics); // Now we flip our buffers on the swap chain. // We need to this or we won't see anything at all except the standard window background color. Clearly, we don't want that. // This method will take the current frame back buffer and flip it to the front buffer (the window). If we had more than one swap chain tied to multiple // windows, then we'd need to do this for every swap chain. _swap.Present(1); return(true); }
/// <summary> /// Function to handle idle time for the application. /// </summary> /// <returns><b>true</b> to continue processing, <b>false</b> to stop.</returns> private static bool Idle() { // This will clear the swap chain to the specified color. // For our example, we'll cycle through multiple colors so we don't end up with a boring old screen with a static color. This will also prove that our // swap chain is working and rendering data to the window. // Set up the clear to clear the upper left and lower right of the swap chain: switch (_clearPattern) { case 1: _clearRegions[0] = new DX.Rectangle(0, 0, _swap.Width / 2, _swap.Height / 2); _clearRegions[1] = new DX.Rectangle(_swap.Width / 2, _swap.Height / 2, _swap.Width / 2, _swap.Height / 2); _swap.RenderTargetView.Clear(_clearColor, _clearRegions); break; case 2: _clearRegions[0] = new DX.Rectangle(_swap.Width / 2, 0, _swap.Width / 2, _swap.Height / 2); _clearRegions[1] = new DX.Rectangle(0, _swap.Height / 2, _swap.Width / 2, _swap.Height / 2); _swap.RenderTargetView.Clear(_clearColor, _clearRegions); break; default: _swap.RenderTargetView.Clear(_clearColor); break; } // This specifies how much color to apply to the channel. // We're using the GorgonTiming.Delta property here to retrieve the number of seconds that it takes to draw a single frame. This allows us to smooth // the animation speed by basing it on the frame rate of the device. If we didn't do this, the colors would cycle way too quickly. _channelValue = GorgonTiming.Delta * _direction * 0.4f; switch (_channel) { case 0: _channelValue = _clearColor.Red + _channelValue; _clearColor = new GorgonColor(_channelValue, 0, 0); break; case 1: _channelValue = _clearColor.Green + _channelValue; _clearColor = new GorgonColor(0, _channelValue, 0); break; case 2: _channelValue = _clearColor.Blue + _channelValue; _clearColor = new GorgonColor(0, 0, _channelValue); break; } // If we've exceeded the min/max amount of color for the channel, move on to the next. if (_channelValue > 1.0f) { _direction = -1; _channelValue = 1.0f; } if (_channelValue < 0.0f) { _direction = 1; _channelValue = 0.0f; _channel += _channelDirection; } // Flip directions and set to the middle channel. if (_channel > 2) { _channel = 1; _channelDirection = -1; ++_clearPattern; if (_clearPattern > 2) { _clearPattern = 0; } } if (_channel < 0) { _channel = 1; _channelDirection = 1; ++_clearPattern; if (_clearPattern > 2) { _clearPattern = 0; } } GorgonExample.BlitLogo(_graphics); // Now we flip our buffers on the swap chain. // We need to this or we won't see anything at all except the standard window background color. Clearly, we don't want that. // This method will take the current frame back buffer and flip it to the front buffer (the window). If we had more than one swap chain tied to multiple // windows, then we'd need to do this for every swap chain. _swap.Present(); return(true); }