PDA

View Full Version : Rendering a Hint-Image in front of a planet



Firlefanz
16-02-2006, 08:05 AM
Hello,

I have an image I want to render in front of a 3d planet.
This 'banner' should be influenced by the light (like the planet) but not by the planet, because then the colors look ugly.

But black parts of the banner should not be drawn!

Does not work.
When I turn Alphablend on, the banner looks ugly and colors strange etc.

When I trun Alphablend off it is perfect but I see the black parts, they should not be seen!

I tried Alphabland on/off with Modulate/2x and Add.

The banner has PNG format, I also made an alphachannel for the black parts, but still they are there. I also tried DDS with A8r8g8b8.

What do I have to do?

Rendering


setrenderstate(d3drs_alphablendenable,dword(true)) ;
//setrenderstate(d3drs_alphablendenable,dword(false) );
D3DXVec3Subtract(PlanettoCam, D3DXVector3(camera.x,camera.y,camera.z),D3DXVector 3(x,y,z));
D3DXVec3Normalize(PlanettoCam,PlanettoCam);
D3DXVec3Scale(PlanettoCamScale, PlanettoCam,planettyp[i].nradius/400);
D3DXVec3Add(SpritePos, D3DXVector3(x,y,z), PlanettoCamScale);
D3DXVec3Cross(Left, PlanettoCam,D3DXVector3(0,1,0));
D3DXVec3Normalize(Left, Left);
D3DXVec3Cross(NewUp, Left, PlanettoCam);
D3DXVec3Normalize(NewUp, NewUp);
D3DXVec3Add(Punkt1, SpritePos, Left);
D3DXVec3Add(Punkt1, Punkt1, NewUp);
D3DXVec3Subtract(Punkt2, SpritePos, Left);
D3DXVec3Add(Punkt2, Punkt2, NewUp);
D3DXVec3Subtract(Punkt3, SpritePos, Left);
D3DXVec3Subtract(Punkt3, Punkt3, NewUp);
D3DXVec3Add(Punkt4, SpritePos, Left);
D3DXVec3Subtract(Punkt4, Punkt4, NewUp);
D3DXMatrixIdentity(matIdentity);
SetTransform(D3DTS_WORLD, matIdentity);
D3DXVec3Subtract( v1, punkt2, punkt1 );
D3DXVec3Subtract( v2, punkt3, punkt1 );
D3DXVec3Cross( vNormal, v1, v2 );
D3DXVec3Normalize( vNormal, vNormal );
m_PlanetVertices[0].vNorm := vNormal;
m_PlanetVertices[1].vNorm := vNormal;
m_PlanetVertices[2].vNorm := vNormal;
m_PlanetVertices[3].vNorm := vNormal;
m_PlanetVertices[1].tu := 0.0;
m_PlanetVertices[1].tv := 0.0;
m_PlanetVertices[0].tu := 1.0;
m_PlanetVertices[0].tv := 0.0;
m_PlanetVertices[3].tu := 0.0; //2 oder 3 erst?
m_PlanetVertices[3].tv := 1.0;
m_PlanetVertices[2].tu := 1.0;
m_PlanetVertices[2].tv := 1.0;
if FAILED(m_PlanetSpriteBuffer.lock(0,4*sizeof(Planet Vertex),m_pVertices,0)) then exit;
m_PlanetVertices[0].vpos:=punkt1;
m_PlanetVertices[1].vpos:=punkt2;
m_PlanetVertices[3].vpos:=punkt3;
m_PlanetVertices[2].vpos:=punkt4;
Move(m_PlanetVertices,m_pVertices^,4*sizeof(Planet Vertex));
m_PlanetSpriteBuffer.unlock;
SetStreamSource(0, m_PlanetSpriteBuffer, 0 , sizeof(PlanetVertex) );
if planetdone[i-1] then SetTexture(0,PlanetDoneTexture)
else SetTexture(0,PlanetForbiddenTexture);
SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_Diffuse);
SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_Texture);
SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_modulate2x);
SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_disable);
SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_disable);
SetRenderState(D3DRS_CULLMODE, D3DCULL_none);
xenscreen.Device.SetFVF(D3DFVF_D3DVERTEX);
xenscreen.Device.DrawPrimitive(D3DPT_TRIANGLESTRIP , 0, 2);



Loading (many tries):


if d3dxcreatetexturefromfilea(xenScreen.device,PChar( 'PlanetForbidden.png'),planetforbiddentexture)<>s_ok
then exceptionmsg('PlanetForbidden.png');



if d3dxcreatetexturefromfile(xenScreen.device,PChar(' PlanetForbidden.png'),planetforbiddentexture)<>s_ok
then exceptionmsg('PlanetForbidden.png');



D3DXCreateTextureFromFileEx(xenScreen.device,PChar ('PlanetForbidden.png'),256, 256,0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_DEFAULT,D3DX_DEFAULT, D3DCOLOR_ARGB(255,0,0,0), 0, 0,planetforbiddentexture);

Is rendering wrong or loading wrong?

Thanks,
Firle

Mirage
16-02-2006, 10:16 AM
Try alpha test:
SetRenderState(D3DRS_ALPHATESTENABLE, 1);
SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
SetRenderState(D3DRS_ALPHAREF, 0);

Firlefanz
16-02-2006, 10:35 AM
Hi Mirage,

I'll try that, thanks a lot.

Firle

Firlefanz
16-02-2006, 06:11 PM
Works perfect, thanks a lot Mirage. :D

Firle