Jump to content
  • Advertisement
Sign in to follow this  
Pushapjit

alpha channel

This topic is 4623 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

I am trying to render textures with alpha channel. Below is the code. I am getting problem with alpha channel which is showing blue color around the object having alpha channel. Grill.dds file is used for grill texture.
HRESULT CMyD3DApplication::DrawMeshData(SMeshData *pMeshData)
{
    
    // Set diffuse blending for alpha set in vertices
    m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
    m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND,  D3DBLEND_SRCALPHA );
    m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

    // Enable alpha testing (skips pixels with less than a certain alpha.)
    if( m_d3dCaps.AlphaCmpCaps & D3DPCMPCAPS_GREATEREQUAL )
    {
        m_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
        m_pd3dDevice->SetRenderState( D3DRS_ALPHAREF,        0x08 );
        m_pd3dDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
    } 


    // Set and draw each of the materials in the mesh
    for( DWORD iMaterial=0; iMaterial < m_dwNumMaterials; iMaterial++ )
    {
        m_pd3dDevice->SetMaterial( &m_pMeshMaterials[iMaterial] );
        m_pd3dDevice->SetTexture( 0, m_pMeshTextures[iMaterial] );

        if( !m_bShowStrips && !m_bShowSingleStrip)
        {
            pMeshData->m_pMesh->DrawSubset( iMaterial );
        }
    }

      // Restore Alpha state
	m_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,    FALSE );
      m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   FALSE );

    return S_OK;
}


HRESULT CMyD3DApplication::RestoreDeviceObjects()
{

    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1 );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );

}

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Pushapjit
I am trying to render textures with alpha channel. Below is the code. I am getting problem with alpha channel which is showing blue color around the object having alpha channel. Grill.dds file is used for grill texture.

*** Source Snippet Removed ***


You're code looks overly complex. To just get alpha blending all you need to do is:


m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
m_pd3dDevice->SetRenderState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );


That's it. No alpha test is needed :)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!