This project has moved and is read-only. For the latest updates, please go here.

Drawing sprites using a blend factor.

Jan 15, 2014 at 1:02 AM
Can anyone tell me what I'm may be doing wrong. I was trying to render a sprite using a custom blend state that uses a blend factor. I would set the blend factor on the Output Merger and call SpriteBatch->Draw() with custom blend state. However, it seems that SpriteBatch->Draw()/End() is overwriting the blend factor. I got around this by setting the blend factor via callback. However, it feels hackish...

Any suggestions for a more elegant approach?

Jan 15, 2014 at 7:49 AM
Edited Jan 15, 2014 at 7:53 AM
Instead of using the Begin() parameter blendState, use the setCustomShaders parameter.

Here's an example using a C++11 lambda expression (which is just a nicer way of writing an inline function and passing a pointer to it) if your blend state requires custom blend factors or sample mask.
spriteBatch->Begin(SpriteSortMode_Deferred, nullptr, nullptr, nullptr, nullptr, [=]
    deviceContext->OMSetBlendState( blendState, factor, mask );
See the SpriteBatch docs under Alpha blending and Custom render states
Marked as answer by walbourn on 1/21/2014 at 11:14 AM