• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

WPF and D3DImage and D3D surface has annoying Flicker?

B

BartMan

#1
Greetings,

I am doing a project where I am copying a texture onto a D3D surface, and I
am using D3DImage to use it in a WPF panel.

Unfortunately I am getting a very noticable flicker when the image is being
drawn?
I am not sure how to make this go away?

I modeled it from the sample code found on MS web site:
CRendererManager,CRenderer, and CTriangleRenderer.

I modified the CTriangleRenderer to be a plane object, and I applied a
texture to it.
Now that the texture is being applied it flickers? I am not sure how to fix
this? Any suggestions?

// Render code.
HRESULT hr = S_OK;

IFC(m_pd3dDevice->BeginScene());
m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB(255,255,255), 1.0f, 0L );

// Set up the rotation
UINT iTime = GetTickCount() % 1000;
FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 1000.0f;
//D3DXMatrixRotationY(&matWorld, fAngle);
D3DXMatrixRotationY(&matWorld, 0);
IFC(m_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld));

// Make sure that we can see the texture.
// (NOTE:) If this isn't here, the texture will appear black.
m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE);
m_pd3dDevice->SetRenderState( D3DRS_CLIPPING, FALSE);

if(m_pTexture)
{
IFC( m_pd3dDevice->SetTexture( 0, m_pTexture));
D3DTSS_COLORARG1, D3DTA_TEXTURE));
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

}


IFC(m_pd3dDevice->SetStreamSource(0, m_pd3dVB, 0, sizeof(CUSTOMVERTEX)));
IFC(m_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX));

IFC(m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2));

if(m_pTexture)
IFC( m_pd3dDevice->SetTexture( 0, NULL));

IFC(m_pd3dDevice->EndScene());


// WPF Render code.
void CompositionTarget_Rendering(object sender, EventArgs e)
{
try
{

RenderingEventArgs args = (RenderingEventArgs)e;
if (d3dImage.IsFrontBufferAvailable)
{
IntPtr pSurface = myWrapperD3DClass.RenderScene();

if (pSurface != IntPtr.Zero)
{
d3dImage.Lock();
// Repeatedly calling SetBackBuffer with the same IntPtr is
// a no-op. There is no performance penalty.
d3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, pSurface);
d3dImage.AddDirtyRect(new Int32Rect(0, 0, d3dImage.PixelWidth,
d3dImage.PixelHeight));
d3dImage.Unlock();

}

}

Thanks for any suggestions?
 

My Computer