Jump to content
  • Advertisement

Archived

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

Rasta

D3DIM translucent textures

This topic is 6649 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''ve just created a simple spinning cube that is translucent against the background. I''ve enabled alpha blending to use the cube''s material diffuse alpha component. This works ok. Now I want to use textures. I take the SDK media file "wall.bmp" and render it onto my cube. However, the cube is not translucent anymore. So, how can I get this texture to be translucent? I don''t want to modify or change the bitmap itself (like using a graphics program to change the alpha component of all its pixels or something). The docs just confuse me more. Rasta

Share this post


Link to post
Share on other sites
Advertisement
I''m not the best person to ask on this, but one way I was able to succeed is:

When loading the bitmap to the surface, assign each pixel an alpha channel value along with the standard RGB. Then, you should be able to blend it.

Share this post


Link to post
Share on other sites
Thanks, but as I stated, I do not want to modify the bitmap at all.

Isn''t there a way to make a texture translucent after the texture
is loaded? And I would also like to dynamically change the amount
of translucency of the texture during rendering, so it can''t be a
one time thing.

I''m using the SDK help function from D3dtextr.h:

D3DTextr_CreateTextureFromFile( "wall.bmp" );

Rasta

Share this post


Link to post
Share on other sites
I don''t know if it''s my graphics card or my code, but I can''t get it to
work. Here is how I am trying to render my cube. lake.bmp is used
for my background:


// clear the viewport to black
lpdevice->Clear( 1UL, lpViewRect, D3DCLEAR_TARGET, 0x00000000, 0L, 0L);

// begin the scene
lpdevice->BeginScene();

// set texture for the background
lpdevice->SetTexture( 0, D3DTextr_GetSurface("lake.bmp") );

// draw the background
lpdevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX,
Background, 4, 0 );

// set texture for the cube
lpdevice->SetTexture( 0, D3DTextr_GetSurface("wall.bmp") );

// enable alpha blending
lpdevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE );

// source, dest
lpdevice->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
lpdevice->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);

// alpha operatons
lpdevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
lpdevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR );

// 50% translucent
lpdevice->SetRenderState( D3DRENDERSTATE_TEXTUREFACTOR, D3DRGBA(1.0f, 1.0f, 1.0f, 0.5f) );

// draw the cube
lpdevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, D3DFVF_VERTEX,
CubeVertices, NUM_CUBE_VERTICES,
CubeIndices, NUM_CUBE_INDICES, 0 );

lpdevice->SetTexture( 0, NULL );

// end the scene
lpdevice->EndScene();


I did check some flags from the D3D caps of my device and got:
(1=supported, 0=not supported)

D3DTEXOPCAPS_BLENDCURRENTALPHA: 0
D3DTEXOPCAPS_BLENDDIFFUSEALPHA: 0
D3DTEXOPCAPS_BLENDFACTORALPHA: 0
D3DTEXOPCAPS_BLENDTEXTUREALPHA: 0
D3DTEXOPCAPS_SELECTARG1: 1
D3DTEXOPCAPS_SELECTARG2: 0
D3DTEXOPCAPS_MODULATE: 1
D3DTEXOPCAPS_DISABLE: 1

I''m not sure what this really means for my graphics card in terms of
rendering translucent textures, but does it look ok or is it bad?

Rasta

Share this post


Link to post
Share on other sites
I see no error with your code, however from your D3D caps I would say that the card doesn''t support alpha blending. What type of card is it that you have?

Share this post


Link to post
Share on other sites
I have a 3D diamond stealth graphics card w/4MB. Alpha blending does
work if I just set a basic colored material for my cube. I guess I
assumed I could get textures to alpha blend also. But if my card sucks,
it sucks!

Rasta

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.

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

Sign me up!