dx11/main.cpp
//-----------------------------------------------------------------------------
// [SECTION] example specific setup function implementations
//-----------------------------------------------------------------------------
[SECTION] example specific setup function implementations
[ SECTION ] example specific setup function implementations
static void
create_pipeline_states()
{
    {
        ID3DBlob* shaderCompileErrorsBlob;
        HRESULT hResult = ::D3DCompileFromFile(L"../shaders.hlsl", 
            nullptr, nullptr, "vs_main", "vs_5_0", 0, 0, &g_vsBlob, &shaderCompileErrorsBlob);
        if (FAILED(hResult))
        {
            const char* errorString = nullptr;
            if (hResult == ::HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
                errorString = "Could not compile shader; file not found";
            else if (shaderCompileErrorsBlob)
                errorString = (const char*)shaderCompileErrorsBlob->GetBufferPointer();
            MessageBoxA(0, errorString, "Shader Compiler Error", MB_ICONERROR | MB_OK);
            assert(false);
        }
        hResult = g_device->CreateVertexShader(g_vsBlob->GetBufferPointer(), 
            g_vsBlob->GetBufferSize(), nullptr, &g_vertexShader);
        assert(SUCCEEDED(hResult));
        if(shaderCompileErrorsBlob)
            shaderCompileErrorsBlob->Release();
    }
    {
        ID3DBlob* psBlob;
        ID3DBlob* shaderCompileErrorsBlob;
        HRESULT hResult = ::D3DCompileFromFile(L"../shaders.hlsl", 
            nullptr, nullptr, "ps_main", "ps_5_0", 0, 0, &psBlob, &shaderCompileErrorsBlob);
        if (FAILED(hResult))
        {
            const char* errorString = nullptr;
            if (hResult == ::HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
                errorString = "Could not compile shader; file not found";
            else if (shaderCompileErrorsBlob)
                errorString = (const char*)shaderCompileErrorsBlob->GetBufferPointer();
            ::MessageBoxA(0, errorString, "Shader Compiler Error", MB_ICONERROR | MB_OK);
            assert(false);
        }
        hResult = g_device->CreatePixelShader(psBlob->GetBufferPointer(), 
            psBlob->GetBufferSize(), nullptr, &g_pixelShader);
        assert(SUCCEEDED(hResult));
        psBlob->Release();
        if(shaderCompileErrorsBlob)
            shaderCompileErrorsBlob->Release();
    }
    {
        D3D11_INPUT_ELEMENT_DESC inputElementDesc[] =
        {
            { "Position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
            { "TexCoord", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }
        };
        HRESULT hResult = g_device->CreateInputLayout(inputElementDesc, ARRAYSIZE(inputElementDesc), 
            g_vsBlob->GetBufferPointer(), g_vsBlob->GetBufferSize(), &g_inputLayout);
        assert(SUCCEEDED(hResult));
    }
}
static void create_pipeline_states ( ) { { ID3DBlob * shaderCompileErrorsBlob ; HRESULT hResult = :: D3DCompileFromFile ( L" " , nullptr , nullptr , " " , " " , 0 , 0 , & g_vsBlob , & shaderCompileErrorsBlob ) ; if ( FAILED ( hResult ) ) { const char * errorString = nullptr ; if ( hResult == :: HRESULT_FROM_WIN32 ( ERROR_FILE_NOT_FOUND ) ) errorString = " " ; else if ( shaderCompileErrorsBlob ) errorString = ( const char * ) shaderCompileErrorsBlob -> GetBufferPointer ( ) ; MessageBoxA ( 0 , errorString , " " , MB_ICONERROR | MB_OK ) ; assert ( false ) ; } hResult = g_device -> CreateVertexShader ( g_vsBlob -> GetBufferPointer ( ) , g_vsBlob -> GetBufferSize ( ) , nullptr , & g_vertexShader ) ; assert ( SUCCEEDED ( hResult ) ) ; if ( shaderCompileErrorsBlob ) shaderCompileErrorsBlob -> Release ( ) ; } { ID3DBlob * psBlob ; ID3DBlob * shaderCompileErrorsBlob ; HRESULT hResult = :: D3DCompileFromFile ( L" " , nullptr , nullptr , " " , " " , 0 , 0 , & psBlob , & shaderCompileErrorsBlob ) ; if ( FAILED ( hResult ) ) { const char * errorString = nullptr ; if ( hResult == :: HRESULT_FROM_WIN32 ( ERROR_FILE_NOT_FOUND ) ) errorString = " " ; else if ( shaderCompileErrorsBlob ) errorString = ( const char * ) shaderCompileErrorsBlob -> GetBufferPointer ( ) ; :: MessageBoxA ( 0 , errorString , " " , MB_ICONERROR | MB_OK ) ; assert ( false ) ; } hResult = g_device -> CreatePixelShader ( psBlob -> GetBufferPointer ( ) , psBlob -> GetBufferSize ( ) , nullptr , & g_pixelShader ) ; assert ( SUCCEEDED ( hResult ) ) ; psBlob -> Release ( ) ; if ( shaderCompileErrorsBlob ) shaderCompileErrorsBlob -> Release ( ) ; } { D3D11_INPUT_ELEMENT_DESC inputElementDesc [ ] = { { " " , 0 , DXGI_FORMAT_R32G32_FLOAT , 0 , 0 , D3D11_INPUT_PER_VERTEX_DATA , 0 } , { " " , 0 , DXGI_FORMAT_R32G32_FLOAT , 0 , D3D11_APPEND_ALIGNED_ELEMENT , D3D11_INPUT_PER_VERTEX_DATA , 0 } } ; HRESULT hResult = g_device -> CreateInputLayout ( inputElementDesc , ARRAYSIZE ( inputElementDesc ) , g_vsBlob -> GetBufferPointer ( ) , g_vsBlob -> GetBufferSize ( ) , & g_inputLayout ) ; assert ( SUCCEEDED ( hResult ) ) ; } }
[SECTION] example specific setup function implementations
[ SECTION ] example specific setup function implementations
//----------------------------------------------------------------------------- // Create Vertex Shader //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Create Pixel Shader //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Create Input Layout //-----------------------------------------------------------------------------