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.
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
{
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 );
D3DDISPLAYMODE d3ddm;
pD3D->GetAdapterDisplayMode( adapter, &d3ddm );
D3DPRESENT_PARAMETERS d3dpp;
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 )
pd3dDevice->Release();
if( pd3dDevice != NULL )
pd3dDevice->Release();
UnregisterClass( L"D3D", wc.hInstance );
return 0;
}
pd3dDevice->*calls into anelseconnected withif( PeekMessage(...) ), otherwise your app will appear to be unresponsive if there is more than oneWM_MESSAGEin the queue – bobobobo Jan 10 at 19:34Lin front of unicode strings use theTEXTmacro instead.L"D3D"should becomeTEXT("D3D"). – bobobobo Jan 10 at 19:35