• Advertisement
Sign in to follow this  

[SlimDX] Texture dissapears during resizing object.

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

Hi!

I have a problem with drawing textured object in DlimDX (D3DX9).

I have a rectangle that is textured with image from webcam.

It works OK until I resize rectangle.

When I resize the object, texture fades and disappears.

If size is less than 33% - texture is 100% transparent.
If size is 66% or more - texture 100% visible.
Between that values transparency is linear.

When I turn off the alpha blending in effect file object gets dark instead of transparent.

There is creation of my texture from memory:
tex = new Texture(_device, SourceWidth, SourceHeight, 0, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);
var data = tex.LockRectangle(0, LockFlags.None);
for (int i = 0; i < SourceHeight; i++)
{
data.Data.Write(TextureBytes, (SourceHeight - 1 - i)*SourceStride, SourceStride);
}
tex.UnlockRectangle(0);



There is creation of rectangle (updated every time)
if (Resize)
{
Width *= (WidthRatio/100);
Height *= (HeightRatio/100);
}
var v = new[] {
new BillboardVertex() {Position = Center - Height*NUp - Width*NRight, Texcoord = new Vector2(0, 1)},
new BillboardVertex() {Position = Center + Height*NUp - Width*NRight, Texcoord = new Vector2(0, 0)},
new BillboardVertex() {Position = Center - Height*NUp + Width*NRight, Texcoord = new Vector2(1, 1)},
new BillboardVertex() {Position = Center + Height*NUp + Width*NRight, Texcoord = new Vector2(1, 0)},
};
_vertices.Lock(0, 0, LockFlags.None).WriteRange(v);
_vertices.Unlock();


And used Effect file:
float4x4 worldViewProj;
texture tex0;

sampler2D sampler0 = sampler_state
{
texture = tex0;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};

void vsmain(float3 pos : POSITION, float2 texc : TEXCOORD0, out float4 oPos : POSITION, out float2 oTexc : TEXCOORD0)
{
oPos = mul(float4(pos,1), worldViewProj);
oTexc = texc;
}

float4 psmain(float2 texc : TEXCOORD0) : COLOR
{
float4 color = tex2D(sampler0, texc);
return color;
}

technique std
{
pass
{
AlphaBlendEnable = true;
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha ;
ZWriteEnable = false;
CullMode = NONE;
VertexShader = compile vs_2_0 vsmain();
PixelShader = compile ps_2_0 psmain();
}
}

It would be great if anyone could tell me how to fix that.

Thanks,
Simin

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement