Jump to content

  • Log In with Google      Sign In   
  • Create Account


[C++ DirectX9] Render to Texture


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 RipeTomatoe   Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 February 2012 - 07:12 PM

Let's just jump straight into code:

void beginRender(void)
{
  pd3dDev->GetRenderTarget(0, &pBackBuffer);
  pRenderTexture->GetSurfaceLevel(0, &pRenderSurface);
  pd3dDev->SetRenderTarget(0, pRenderSurface);
  pd3dDev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
  pd3dDev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
  pd3dDev->BeginScene();
};
void endRender(void)
{
  pd3dDev->EndScene();
  //Do RTT
  effect->SetTexture("Screen", pRenderTexture);
  effect->SetTechnique(effect->GetTechniqueByName("BlackAndWhite"));
  pd3dDev->SetRenderTarget(0, pBackBuffer);
  pd3dDev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(100, 0, 0), 1.0f, 0);
  pd3dDev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
  pd3dDev->BeginScene();
  setUIVertDecl();
  pd3dDev->SetTexture(0, pRenderTexture);
  pd3dDev->SetStreamSource(0, pRenderVB, 0, sizeof(VERTEX2D));
  UINT cPasses;
  effect->Begin(&cPasses, 0);
  for(UINT i = 0; i < cPasses; i++)
  {
   effect->BeginPass(i);
   pd3dDev->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
   effect->EndPass();
  }
  effect->End();
  pd3dDev->SetTexture(0, NULL);
  pd3dDev->EndScene();
  pd3dDev->Present(NULL, NULL, NULL, NULL);
  mouseState.x = mouseState.y = 0;
  SetCursorPos(wWidth/2,wHeight/2);
};

So basically this code works flawlessly on my laptop, but when I try and run it on my desktop the texture is black. I've experimented with the shader and the shader is working fine. The scene itself renders fine when I don't save it to a texture. I'm really stumped on this one, if anyone needs more code snippets I'll be happy to show some more.

Thanks in advance,
Daniel (Ripe)

Sponsor:

#2 gfxgangsta   Members   -  Reputation: 546

Like
0Likes
Like

Posted 21 February 2012 - 07:48 PM

Are you running with the Direct3D debug version or retail version?

Open "DirectX Control Panel" program, go to Direct3D 9 tab, then make sure this one is selected:

"Use Debug Version of Direct3D 9"

Then check visual studio's output window to see if it indicates any errors on your desktop.

It's also a good idea to check the HRESULT return value of Direct3D function calls. Check which one is failing.

#3 RipeTomatoe   Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 February 2012 - 08:21 PM

I switched to the debug, and nothing is appearing that is out of the ordinary. Also all the HRESULT values are return S_OK.

-Daniel (Ripe)

#4 Hodgman   Moderators   -  Reputation: 28409

Like
0Likes
Like

Posted 21 February 2012 - 08:25 PM

You're performing rendering operations outside of a begin/end-scene pair.

#5 RipeTomatoe   Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 February 2012 - 09:31 PM

You're performing rendering operations outside of a begin/end-scene pair.


Well I moved around my begin and end scene pair, and it still works on my laptop, but not my desktop. I know that the clear command is working because the texture gets the colour. However it seems like nothing is rendered onto that texture.

#6 RipeTomatoe   Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 February 2012 - 11:32 PM

I finally got the DirectX debugger to show up (I accidently enabled the 64-bit one, instead of the 32-bit one) and it is showing me warning's about ignoring redundant SetSamplerStates, and SetRenderStates. I assume this code is actually in the d3dxmesh class, because I never call those functions in my code.

This is the only error I get now

Direct3D9: (ERROR) :Invalid flag D3DCLEAR_ZBUFFER: no zbuffer is associated with device. Clear failed.


it also doesn't like any depth stencil code.

I'm really stumped at this. It's now showing, but since it doesn't have depth everything is stacked on each other.

#7 RipeTomatoe   Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 February 2012 - 11:50 PM

OK, so it's all working now, I don't really know what I changed, but it's working, and I'm going to test it on more machines to make sure it's a good thing. Thanks for all your help guys!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS