Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


How do you make an images transparent areas appear transparent in game?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 gchris6810   Members   -  Reputation: 207

Like
0Likes
Like

Posted 30 October 2012 - 10:48 AM

Hi,

I have an image I want to use for my game but when rendered the border which is supposed to be transparent appears black! Which, as you can imagine doesn't look very good. Could anyone post me some code to get this working? Thanks in advance for any replies.

I should probably also add I am using DirectX 11.

Edited by gchris6810, 30 October 2012 - 11:17 AM.


Sponsor:

#2 MJP   Moderators   -  Reputation: 11613

Like
1Likes
Like

Posted 30 October 2012 - 02:54 PM

You probably want to use a blend state that has alpha blending enabled. When you initialize your program, create a blend state with the following settings:

D3D11_BLEND_DESC blendDesc;
    blendDesc.AlphaToCoverageEnable = false;
    blendDesc.IndependentBlendEnable = true;
    for (UINT i = 0; i < 8; ++i)
    {
	    blendDesc.RenderTarget[i].BlendEnable = true;
	    blendDesc.RenderTarget[i].BlendOp = D3D11_BLEND_OP_ADD;
	    blendDesc.RenderTarget[i].BlendOpAlpha = D3D11_BLEND_OP_ADD;
	    blendDesc.RenderTarget[i].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
	    blendDesc.RenderTarget[i].DestBlendAlpha = D3D11_BLEND_ONE;
	    blendDesc.RenderTarget[i].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
	    blendDesc.RenderTarget[i].SrcBlend = D3D11_BLEND_SRC_ALPHA;
	    blendDesc.RenderTarget[i].SrcBlendAlpha = D3D11_BLEND_ONE;
    }
    blendDesc.RenderTarget[0].BlendEnable = true;

Then before you draw, set that blend state on the context using OMSetBlendState.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS