Merge pull request #597 from ppy/fix-white-flash

Fix white flash when starting GameWindow based application on windows
This commit is contained in:
Fraser Waters 2017-08-01 13:50:30 +01:00 committed by GitHub
commit 302ec5001a
2 changed files with 33 additions and 3 deletions

View file

@ -1421,9 +1421,8 @@ namespace OpenTK.Platform.Windows
}
}
[DllImport("gdi32.dll", SetLastError = true)]
internal static extern IntPtr GetStockObject(int index);
internal static extern IntPtr GetStockObject(StockObjects fnObject);
[DllImport("gdi32.dll", SetLastError = true)]
internal static extern BOOL DeleteObject([In]IntPtr hObject);
@ -3944,6 +3943,33 @@ namespace OpenTK.Platform.Windows
Baltic = 186,
}
/// <summary>
/// Identifiers for the GetStockObject method.
/// </summary>
internal enum StockObjects
{
WHITE_BRUSH = 0,
LTGRAY_BRUSH = 1,
GRAY_BRUSH = 2,
DKGRAY_BRUSH = 3,
BLACK_BRUSH = 4,
NULL_BRUSH = 5,
HOLLOW_BRUSH = NULL_BRUSH,
WHITE_PEN = 6,
BLACK_PEN = 7,
NULL_PEN = 8,
OEM_FIXED_FONT = 10,
ANSI_FIXED_FONT = 11,
ANSI_VAR_FONT = 12,
SYSTEM_FONT = 13,
DEVICE_DEFAULT_FONT = 14,
DEFAULT_PALETTE = 15,
SYSTEM_FIXED_FONT = 16,
DEFAULT_GUI_FONT = 17,
DC_BRUSH = 18,
DC_PEN = 19,
}
internal enum MapVirtualKeyType
{
/// <summary>uCode is a virtual-key code and is translated into a scan code. If it is a virtual-key code that does not distinguish between left- and right-hand keys, the left-hand scan code is returned. If there is no translation, the function returns 0.</summary>

View file

@ -727,7 +727,9 @@ namespace OpenTK.Platform.Windows
break;
case WindowMessage.ERASEBKGND:
return new IntPtr(1);
// This is triggered only when the client area changes.
// As such it does not affect steady-state performance.
break;
case WindowMessage.WINDOWPOSCHANGED:
HandleWindowPositionChanged(handle, message, wParam, lParam);
@ -934,6 +936,8 @@ namespace OpenTK.Platform.Windows
{
ExtendedWindowClass wc = new ExtendedWindowClass();
wc.Size = ExtendedWindowClass.SizeInBytes;
// Setting the background here ensures the window doesn't flash gray/white until the first frame is rendered.
wc.Background = Functions.GetStockObject(StockObjects.BLACK_BRUSH);
wc.Style = DefaultClassStyle;
wc.Instance = Instance;
wc.WndProc = WindowProcedureDelegate;