D3DIM translucent textures
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
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.
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.
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
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
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
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
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement