# DirectX11 Equivalent of OpenGL code

I am currently porting parts of my engine over to D3D11 from OpenGL and was trying to figure out how I would accomplish the following blending functions in D3D11.

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glDepthFunc(GL_EQUAL);


I believe it should be something like this:

D3D11_BLEND_DESC blendDesc;
ZeroMemory(&blendDesc, sizeof(blendDesc));

D3D11_RENDER_TARGET_BLEND_DESC rtbd;
ZeroMemory(&rtbd, sizeof(rtbd));

rtbd.BlendEnable = true;
rtbd.SrcBlend = D3D11_BLEND_ONE;
rtbd.DestBlend = D3D11_BLEND_ONE;

rtbd.SrcBlendAlpha = D3D11_BLEND_ONE;
rtbd.DestBlendAlpha = D3D11_BLEND_ONE;
blendDesc.AlphaToCoverageEnable = true;
blendDesc.RenderTarget[0] = rtbd;

m_D3D->GetDevice()->CreateBlendState(&blendDesc, &m_blendMode);


However this does not work. How can I achieve the same effect as in the first code snippet?

Thanks

• Did you set the blend state in the device context? – jmegaffin Apr 21 '15 at 12:59
• Yes, I set the blend state in the render method when it is used. m_D3D->GetDeviceContext()->OMSetBlendState(m_blendMode, blendFactor, 0xffffffff); – Nick Apr 21 '15 at 13:00
• Three suggestions: One read this MSDN guide, make sure you have debug enabled, and check the result of every Direct3D function that returns an HRESULT for failure: hr = m_D3D->GetDevice()->CreateBlendState(&blendDesc, &m_blendMode); if ( FAILED(hr) ) ... – Chuck Walbourn Apr 21 '15 at 18:02

 glDepthMask(FALSE) glDepthFunc(GL_EQUAL) `