Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

RipeTomatoe

Member Since 25 Feb 2010
Offline Last Active Feb 29 2012 11:24 PM
-----

Topics I've Started

[C++ DirectX9] Render to Texture

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)

PARTNERS