Sign in to follow this  
simin

[SlimDX] Texture dissapears during resizing object.

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:
[code]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);[/code]


There is creation of rectangle (updated every time)
[code] 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();[/code]

And used Effect file:
[code]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();
}
}[/code]
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this