Jump to content
  • Advertisement
Sign in to follow this  

Question about applying Textures on multiple surfaces

This topic is 3718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have a problem. I have n rectangles and n textures. I apply the ith texture to the ith rectangle ( see code below ). I want to apply a fade effect on the last rectangle rendered. However, when I try to apply the fade effect for the last rectangle alone, it gets applied for all the rectangles. I'm not using meshes here and I have generated the rectangles programatically. How do I change the code to apply fade to last rectangle alone?
for ( int m = 0; m <NUMRECTANGLES; ++m )
	{
....
	FillVertices( m ); //Fills Vertex Buffer with coords of mth rectangle
	p_dx_Device->SetStreamSource( 0, p_dx_VertexBuffer, 0, sizeof( Vertex ) );
	p_dx_Device->SetTexture( 0, arrayOfTextures[ m ] );
        if ( m == LastRectangle )
        {
        //Apply fade effect
        //code for fade effect
        }
        p_dx_Device->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );
        }

Thanks, M

Share this post


Link to post
Share on other sites
Advertisement
What does "//Apply fade effect" precisely do? Maybe you forget to unset the effect after rendering the last tile, so that during the next loop the effect will be active for every tile?

Share this post


Link to post
Share on other sites
Hi. This is the code for the fade effect. fTime is the variable with which I vary alpha continuously


if ( m == ct )
{
//RENDERSTATE FOR ALPHA BLENDING
p_dx_Device->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL );
p_dx_Device->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
p_dx_Device->SetRenderState( D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA );
p_dx_Device->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
p_dx_Device->SetRenderState( D3DRS_LIGHTING, TRUE );


//SET TEXTURE ALPHA ARGS
p_dx_Device->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
p_dx_Device->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
p_dx_Device->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
p_dx_Device->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

//SET TEXTURE COLOR ARGS
p_dx_Device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
p_dx_Device->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
p_dx_Device->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
p_dx_Device->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );


p_dx_Device->GetMaterial( &tempMaterial );

D3DCOLORVALUE diffuse = tempMaterial.Diffuse;
if ( fTime< 0.0f )
fTime= 0.0f;
float alpha = fTime;
tempMaterial.Diffuse.r *= (alpha/256.0f);
tempMaterial.Diffuse.g *= (alpha/256.0f);
tempMaterial.Diffuse.b *= (alpha/256.0f);
tempMaterial.Diffuse.a = alpha;
p_dx_Device->SetMaterial( &tempMaterial );
//DISABLING ALPHA BLEND ENABLE
p_dx_Device->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
}


Thanks,
M

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!