Skip to main content
gamedev.net
🔒 Locked

Problem rendering to texture

Started by Adion Jun 12, 2009 at 6:30 PM 1 replies 450+ views
Original Post
Adion
Adion
I've been searching a lot on how to do this, and it seems like it should be really easy, however it looks like all I'm getting is a black texture. The only thing I can think of that I'm doing different from the tutorials I've found is that I want to draw to the texture between rendering to the backbuffer. Therefore I first call EndScene(), then change targets, clear, and call BeginScene() for the new target.
res = dst->d3ddev->EndScene();
res = dst->d3ddev->SetRenderTarget(0, intermediateSurfaceA);
res = dst->d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);

res = dst->d3ddev->BeginScene();
res = dst->d3ddev->EndScene();

res = dst->d3ddev->SetRenderTarget(0, oldRenderTarget);
res = dst->d3ddev->BeginScene();
As a test I've tried above code, which should at least make my texture white, right? But when I try to draw it, it still appears black.
Jason Z
Jason Z
You don't need to call Begin/End for every rendering sequence - you just need to set the render target and depth buffer, the do your rendering. A single Begin/End sequence for all of your rendering for an entire frame would be sufficient - so call Begin at the very beginning and call End right before presenting the backbuffer. That is a likely the cause of your calls not seeming to work.
Jason Zink :: DirectX MVP   Direct3D 11 engine on CodePlex: Hieroglyph 3 Direct3D Books: 
Adion
Adion
Actually I had first tried without the end/begin scene commands, but tried to add them because I couldn't get it to work.

Update:
I added D3DXSaveSurfaceToFile after rendering to my texture, and the resulting file contains the expected result.
So it looks like the problem is either in drawing the texture, or another step is required to update the texture from the surface (although I would expect the surface to be the actual texture data that is written to?)

Update2:
Ok, there was actually nothing wrong with the code I posted, but I somehow used the wrong texture pointer when trying to draw the new texture into my scene, which is why I only got a black texture.

[Edited by - Adion on June 13, 2009 6:12:47 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.