Sign in to follow this  
Oliver_zx

[Texture Stage] Blending textures

Recommended Posts

Hi everyone,

im currently facing an issue with texture render states. Im not much familiar with them so i'd like to ask if someone could give me a hint on that. What i have is two textures. One contains the ARGB texture with a shape i want to use to display a second texture. So i.e. my first texture is a circle and my second contains the real texture. The final texture shall have the shape of a circle and display the content of the second texture inside (w/o uv changes).

The result comes quite unexpected to me. The shape of the final texture is ok - its a circle. Yet the color is wrong. The whole shape is filled with the color of just the very first texel of the second texture (from position 0,0).


Would be great if someone could help me out here. The code below shows a view on what i'm doing.


Thanks alot,
Oliver


[code]
device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

//use texel color value of the second texture
device->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
device->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);


//apply alpha from first texture
device->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
device->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_CURRENT );

//disable
device->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_DISABLE );
device->SetTextureStageState( 2, D3DTSS_ALPHAOP, D3DTOP_DISABLE );


device->SetTexture(0, tex1);
device->SetTexture(1, tex2);
[/code]

Share this post


Link to post
Share on other sites
The texture stage also specify which tex-coord is used. The default for stage 1 is 1, and your vertex probably does not have a second tex-coord (with index 1), so it's always (0,0). Try

[code]
device->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX , 0 );
[/code]
to use the same tex-coord for both stages.

Share this post


Link to post
Share on other sites
[quote name='unbird' timestamp='1311545730' post='4839760']
The texture stage also specify which tex-coord is used. The default for stage 1 is 1, and your vertex probably does not have a second tex-coord (with index 1), so it's always (0,0). Try

[code]
device->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX , 0 );
[/code]
to use the same tex-coord for both stages.
[/quote]


ah...ok, good to know. Thanks alot unbird. It helps - looks as expected now. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this