Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible, somehow to avoid the single frame of black that appears before a DirectX9 window is displayed in fullscreen? My code looks like this.

WNDCLASSEX wc = { sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle( NULL ), NULL, NULL, NULL, NULL, L"D3D", NULL };
RegisterClassEx( &wc );
LPDIRECT3D9         pD3D = NULL;   
LPDIRECT3DDEVICE9   pd3dDevice = NULL;  
int                 windowWidth = 1280;  
int                 windowHeight = 1024;  
int                 adapter = 3;  
bool                fullscreen = true;      

if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
    return E_FAIL;

HWND hWnd = CreateWindow( L"D3D", L"D3D Test", WS_VISIBLE | WS_POPUP, 0, 0, windowWidth, windowHeight, NULL, NULL, wc.hInstance, NULL );

pD3D->GetAdapterDisplayMode( adapter, &d3ddm );

ZeroMemory( &d3dpp, sizeof(d3dpp) );

d3dpp.Windowed               = !fullscreen;
d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat       = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_ONE;
d3dpp.BackBufferCount        = 1;
d3dpp.BackBufferWidth        = windowWidth;
d3dpp.BackBufferHeight       = windowHeight;
d3dpp.hDeviceWindow          = hWnd;

if( FAILED( pD3D->CreateDevice( adapter, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice ) ) )
    return E_FAIL;

MSG msg;
ZeroMemory( &msg, sizeof( msg ) );
while( msg.message != WM_QUIT )
    pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 255, 255, 255 ), 1.0f, 0 );
    pd3dDevice->Present( NULL, NULL, NULL, NULL );

    if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
        TranslateMessage( &msg );
        DispatchMessage( &msg );

if( pd3dDevice != NULL )

if( pd3dDevice != NULL )

UnregisterClass( L"D3D", wc.hInstance );
return 0;


share|improve this question
try removing the present call in your message pump. – Tordin Jan 10 '13 at 16:48
You need to put your pd3dDevice->* calls into an else connected with if( PeekMessage(...) ), otherwise your app will appear to be unresponsive if there is more than one WM_MESSAGE in the queue – bobobobo Jan 10 '13 at 19:34
Don't use L in front of unicode strings use the TEXT macro instead. L"D3D" should become TEXT("D3D"). – bobobobo Jan 10 '13 at 19:35
up vote 2 down vote accepted

If you're referring to the fact that the screen may go black for a second or two during a switch to fullscreen[*] and before the scene is actually displayed following the switch, then you will very likely not be able to remove it. Changing to a fullscreen mode may involve a video mode change for your display device, and if this needs to happen then the black frame is just part of the normal video mode change process - you'll see the same if you e.g. change the screen resolution using your display control panel (which this is effectively identical to).

It's possible to sometimes avoid the need for this to happen if the fullscreen mode you're using is identical in all respects to the current display mode, but there's another catch - with Vista or higher a switch to fullscreen will also disable the DWM, which also causes a frame of black.

So this isn't a problem with your code and there's nothing you can do in code to avoid it - it's a property of your OS and display driver.

There is however one workaround, and that's to not use a fullscreen mode. Instead create a windowed mode at your desktop resolution, but use no title bar/borders/etc on the window. Of course that will run a little slower compared to a true fullscreen mode, but it may not matter if you're already running fast enough.

[*] - when I say "switch to fullscreen" you may assume that I also mean "starting in a fullscreen mode" here.

share|improve this answer
Thanks, I feared this was the case. It's Windows 7 so I will try disabling Aero and see if that helps. Unfortunately, it "has to be fullscreen" otherwise the borderless window solution would be perfect. – acron Jan 11 '13 at 8:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.