Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

wannabe H4x0r

Texture alpha question

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

hey, i''m trying to draw a textured rectangle with transparency. the texture itself is fine. i create a texture from a .tga file with a 32-bit RGBA values, but when i draw the textured rectangle itself, the white color i had specified for the rectangle''s vertices shows through. in my little test program, i have a red clear color, and my texture is this yellow spot that fades (less and less alpha) from the center. what i want to see is a yellow dot fading to red, but instead i see the yellow dot fading into the white rectangle. when i specified the vertices for the rectangle (actually a triangle fan but same thing), i specified them as RGBA(255,255,255,0) so the alpha value is 0 but the rectangle is still showing up. the rendering code is as follows pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,0,0), 1.0f, 0 ); pD3DDevice->BeginScene(); LPDIRECT3DTEXTURE8 g_pTexture; D3DXCreateTextureFromFile( pD3DDevice, "test1.tga", &g_pTexture ); pD3DDevice->SetTexture( 0, g_pTexture ); pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO); pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); LPDIRECT3DVERTEXBUFFER8 g_pVB = NULL; CUSTOMVERTEX g_Vertices[] = { { 0.0f, 0.0f, 0.5f, 1.0f, D3DCOLOR_RGBA(255,255,255,0), 0.0, 0.0, }, { 69.0f, 0.0f, 0.5f, 1.0f, D3DCOLOR_RGBA(255,255,255,0), 1.0, 0.0,}, { 69.0f, 69.0f, 0.5f, 1.0f, D3DCOLOR_RGBA(255,255,255,0), 1.0, 1.0,}, { 0.0f, 69.0f, 0.5f, 1.0f, D3DCOLOR_RGBA(255,255,255,0), 0.0, 1.0,}, }; if( FAILED( pD3DDevice->CreateVertexBuffer( 4*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &g_pVB ) ) ) { return E_FAIL; } VOID* pVertices; if( FAILED( g_pVB->Lock( 0, sizeof(g_Vertices), (BYTE**)&pVertices, 0 ) ) ) return E_FAIL; memcpy( pVertices, g_Vertices, sizeof(g_Vertices) ); g_pVB->Unlock(); pD3DDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) ); pD3DDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX ); pD3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2 ); pD3DDevice->EndScene(); pD3DDevice->Present( NULL, NULL, NULL, NULL ); i can''t see how to solve this problem. if anybody can help, thanx a lot in advance

Share this post

Link to post
Share on other sites
Enable alpha before drawing.

You should also put this:
pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
after this:
pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

Should work now.

[edited by - CoderX on June 25, 2002 10:37:22 PM]

Share this post

Link to post
Share on other sites

  • 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!