Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Need help making a billboard transparent


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
5 replies to this topic

#1 machosalad   Members   -  Reputation: 117

Like
0Likes
Like

Posted 10 May 2013 - 01:13 PM

I am trying to draw a billboard with a tree texture. The texture has a black background with a tree in the middle. The problem is i can't seem to make it transparent. It always has this black box around it. I have tried to remove it using a colorkey by loading the texture like this:

D3DXCreateTextureFromFileExA(D3D9_Device,FileName.str().c_str() , D3DX_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, D3DCOLOR_XRGB(0, 0, 0), 0, 0 ,&Oak);
 

 

here is the drawing code

    //Draws tree billboard
    D3D9_Device->SetVertexDeclaration(Billboard_Declaration);
    D3D9_Device->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE ); 
    D3D9_Device->SetRenderState(D3DRS_POINTSCALEENABLE, TRUE ); 
    D3D9_Device->SetRenderState(D3DRS_POINTSIZE, FWORD(1.0f) );  
    D3D9_Device->SetRenderState(D3DRS_POINTSIZE_MIN, FWORD(0.0f) ); 
    D3D9_Device->SetRenderState(D3DRS_POINTSCALE_A, FWORD(1.0f) );
    D3D9_Device->SetRenderState(D3DRS_POINTSCALE_B, FWORD(1.0f) );
    D3D9_Device->SetRenderState(D3DRS_POINTSCALE_C, FWORD(1.0f) ); /
    D3D9_Device->SetRenderState(D3DRS_LIGHTING, FALSE );
    D3D9_Device->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
    D3D9_Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
    D3D9_Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
    D3D9_Device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
    Billboard_Vertex* V;
    SAFE_RELEASE(VB_Oak);
    D3D9_Device->CreateVertexBuffer(1*sizeof(Billboard_Vertex),Usage | D3DUSAGE_POINTS, 0, Pool, &VB_Oak, 0);
    VB_Oak->Lock(0,1*sizeof(Billboard_Vertex),(void**) &V,0);
    V[0].Position = D3DXVECTOR3(0,0,0);
    V[0].Color = 0xFFFFFFFF;
    VB_Oak->Unlock();
    D3D9_Device->SetTexture(0,Oak);
    D3D9_Device->SetStreamSource(0,VB_Oak,0,sizeof(Billboard_Vertex));
    D3D9_Device->DrawPrimitive(D3DPT_POINTLIST,0,1);
 

 

And here are the declarations

 

struct Billboard_Vertex
{
    D3DXVECTOR3 Position;
    D3DCOLOR    Color;
};

LPDIRECT3DVERTEXDECLARATION9 Billboard_Declaration;

D3DVERTEXELEMENT9 Billboard_Elements[] =
{
{ 0, 0,  D3DDECLTYPE_FLOAT3,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,  0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR,     0 },
D3DDECL_END()
};

IDirect3DTexture9* Oak; //oak tree texture
LPDIRECT3DVERTEXBUFFER9 VB_Oak; //vertex buffer

 

 

 

 

I have been working on this problem for hours  sad.png . Any ideas on why its not working? Thanks.



Sponsor:

#2 belfegor   Crossbones+   -  Reputation: 2685

Like
0Likes
Like

Posted 10 May 2013 - 01:34 PM

You base your blending on alpha channel, can you confirm that you have alpha channel in texture and it contains "mask" for tree?



#3 machosalad   Members   -  Reputation: 117

Like
0Likes
Like

Posted 10 May 2013 - 01:50 PM

The texture does not have an alpha channel. My goal is to make it transparent without editing the texture file by hand. I know this is possible because i have done it before on normal textured quads using colorkeys, but never on billboards before. Maybe colorkeys do not work on billboards?



#4 belfegor   Crossbones+   -  Reputation: 2685

Like
0Likes
Like

Posted 10 May 2013 - 02:12 PM

"Billboards" do you mean point sprites? Because from what i can tell this is what are you using.

I think you need to change your blending mode, but this is not good solution for "trees"

D3D9_Device->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
    //D3D9_Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
    //D3D9_Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
D3D9_Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
    D3D9_Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCCOLOR);

Why can't you change texture "by hand"?



#5 machosalad   Members   -  Reputation: 117

Like
1Likes
Like

Posted 10 May 2013 - 02:40 PM

Sorry, i meant point sprites, i'm kind of new to directx.

 

I tried your example, it didn't work.

 

I can edit the texture by hand and simply give it an alpha channel, but since there is actually 180 of them, that would take too long time unless there is an automated batch file that does it for you. The reason there are so many textures of one single tree is that i am trying to do an experiment to make 2D trees look more realistic. I have made a texture sequence of a tree from 180 different angles. The tree switches between those textures when the angle between you and the tree changes.

 

The texture sequnce is directly exported from a 3D program called Terragen as a .bmp format. Those .bmp files had no alpha, so i tried improvising to make the textures transparent. So far i have failed.


Edited by machosalad, 10 May 2013 - 02:43 PM.


#6 machosalad   Members   -  Reputation: 117

Like
0Likes
Like

Posted 10 May 2013 - 02:46 PM

I just got it to work. yay.

 

All i had to do was draw the rest of the scene before drawing the trees.


Edited by machosalad, 10 May 2013 - 02:47 PM.





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