Do not try to pass a pointer to your HWND. You must pass HWND as not a pointer. Other than that, I don't see anything massive wrong.
This is what DXErrorLookup says about your error:
HRESULT: 0x887a0001 (2289696769) Name: DXGI_ERROR_INVALID_CALL Description: The application has made an erroneous API call that it had enough information to avoid. This error is intended to denote that the application should be altered to avoid the error. Use of the debug version of the DXGI.DLL will provide run- time debug output with further information. Severity code: Failed Facility Code: FACILITY_DXGI (2170) Error Code: 0x0001 (1)
So, have you considered using the debug version of DXGI to find out what the error is?
Btw my working initialization of the DX10 is as follows (Warning a lot of code!):
HRESULT hr = S_OK; // Wrong init params passed in. if ( pParams->paramSize != sizeof( D3D10InitParams ) ) return false; // Upgrade the initparams to the correct version mInitParams = *(D3D10InitParams*)pParams; // Create factory. IDXGIFactory* pFactory = NULL; if ( FAILED( CreateDXGIFactory( __uuidof( IDXGIFactory ), (void**)&pFactory ) ) ) { return false; } if ( FAILED( pFactory->MakeWindowAssociation( mInitParams.hWnd, 0 ) ) ) { return false; } HWND hTemp; pFactory->GetWindowAssociation( &hTemp ); // Enumerate adapters. unsigned int count = 0; IDXGIAdapter * pAdapter; std::vector<IDXGIAdapter*> vAdapters; while( pFactory->EnumAdapters( count, &pAdapter ) != DXGI_ERROR_NOT_FOUND ) { vAdapters.push_back( pAdapter ); count++; } unsigned int selectedAdapter = mInitParams.display; if ( vAdapters.size() > 1 ) { // Need to handle multiple available adapters. } // Release all other adapters. count = 0; unsigned int max = (unsigned int)vAdapters.size(); while( count < max ) { if ( count != selectedAdapter ) { vAdapters[count]->Release(); } count++; } // Device should support all basic DX10 features. // Caps does not support enough basic features. //if ( !CheckCaps( &caps ) ) // return false; // Create the D3D 10 device. DXGI_MODE_DESC dxgiModeDesc; dxgiModeDesc.Width = mInitParams.width; dxgiModeDesc.Height = mInitParams.height; dxgiModeDesc.RefreshRate.Numerator = (mInitParams.refreshRate == 0) ? 60 : mInitParams.refreshRate; dxgiModeDesc.RefreshRate.Denominator = 1; dxgiModeDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; dxgiModeDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE; dxgiModeDesc.Scaling = DXGI_MODE_SCALING_CENTERED; DXGI_SAMPLE_DESC dxgiSampleDesc; dxgiSampleDesc.Count = 1; dxgiSampleDesc.Quality = 0; //DXGI_USAGE dxgiUsage; //dxgiUsage. DXGI_SWAP_CHAIN_DESC dxgiSwapChainDesc; dxgiSwapChainDesc.BufferDesc = dxgiModeDesc; dxgiSwapChainDesc.SampleDesc = dxgiSampleDesc; dxgiSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; dxgiSwapChainDesc.BufferCount = 2; dxgiSwapChainDesc.OutputWindow = mInitParams.hWnd; dxgiSwapChainDesc.Windowed = mInitParams.windowed; dxgiSwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; dxgiSwapChainDesc.Flags = 0;//DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; // Set the device as a debug device when compiled for debug. #ifdef _DEBUG unsigned int flags = D3D10_CREATE_DEVICE_DEBUG; #else unsigned int flags = 0; #endif mpAdapter = vAdapters[selectedAdapter]; // Create the device and swap chain. if ( FAILED( D3D10CreateDeviceAndSwapChain( mpAdapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, flags, D3D10_SDK_VERSION, &dxgiSwapChainDesc, &mpSwapChain, &mpDevice ) ) ) { return false; } // Get the back buffer. ID3D10Texture2D* pBuffer = NULL; if ( FAILED( mpSwapChain->GetBuffer( 0, __uuidof( ID3D10Texture2D ), (void**)&pBuffer ) ) ) { return false; } // Create the default render target view. hr = mpDevice->CreateRenderTargetView( pBuffer, NULL, &mDefaultRenderTarget ); pBuffer->Release(); if ( FAILED( hr ) ) { return false; } // Create depth stencil texture D3D10_TEXTURE2D_DESC descDepth; descDepth.Width = mInitParams.width; descDepth.Height = mInitParams.height; descDepth.MipLevels = 1; descDepth.ArraySize = 1; descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; descDepth.SampleDesc.Count = 1; descDepth.SampleDesc.Quality = 0; descDepth.Usage = D3D10_USAGE_DEFAULT; descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL; descDepth.CPUAccessFlags = 0; descDepth.MiscFlags = 0; if ( FAILED( mpDevice->CreateTexture2D( &descDepth, NULL, &mpDepthStencilTex ) ) ) { return false; } // Create the depth stencil view D3D10_DEPTH_STENCIL_VIEW_DESC descDSV; descDSV.Format = descDepth.Format; descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D; descDSV.Texture2D.MipSlice = 0; if ( FAILED( mpDevice->CreateDepthStencilView( mpDepthStencilTex, &descDSV, &mDefaultDepthStencilTarget ) ) ) { return false; } // Set the default render targets. mpDevice->OMSetRenderTargets( 1, &mDefaultRenderTarget, mDefaultDepthStencilTarget ); mpEffectDevice = new D3D10EffectStateDevice( GetDevice() ); // Set the default render states. SetupRenderStates(); // Set the default viewport. D3D10_VIEWPORT d3d10ViewPort; d3d10ViewPort.Width = mInitParams.width; d3d10ViewPort.Height = mInitParams.height; d3d10ViewPort.TopLeftX = 0; d3d10ViewPort.TopLeftY = 0; d3d10ViewPort.MinDepth = 0.0f; d3d10ViewPort.MaxDepth = 1.0f; GetDevice()->RSSetViewports( 1, &d3d10ViewPort );
Hope this helps!
source share