Sharsnik
March 22nd, 2008, 04:06 AM
I spent the last few hours trying desperately and to no avail to figure out how the heck to work with SetRenderTarget(). :)
I want to render to a texture, so I can use that texture with a frame RECT, effectively creating a mask.
Can anyone run me through how SetRenderTarget works, when it needs to be called, etc?
I was trying to create a new texture with D3DXCreateTexture, and then grab the surface of that texture, and pass to the Device with SetRenderTarget. However, I'm doing this operation in the middle of a Scene, and I'm not sure when the actually rendering of the Draw() command gets done.
Here's an example of some of the things I've tried...
IDirect3DSurface9* newRT;
IDirect3DSurface9* oldRT;
texture->getTexture()->GetSurfaceLevel(0, &newRT); //Set newRT to the surface of the texture I want to write to (needed so I can find newRT later)
game->getDevice()->CreateRenderTarget(pos.right - pos.left, pos.bottom - pos.top, D3DFMT_UNKNOWN, D3DMULTISAMPLE_NONE, 0, 0, &newRT, NULL); //turn the texture into a render target
game->getDevice()->GetRenderTarget(0, &oldRT); //get old render targe
game->getDevice()->SetRenderTarget(0, newRT); //set the render target to the texture
for (int i = 0; i < childern.size(); i++) //draw the childern
childern[i]->draw(g_ppSprite);
game->getDevice()->SetRenderTarget(0, oldRT); //set render target back
This produces no results at all. It renders as if I never switched targets.
I want to render to a texture, so I can use that texture with a frame RECT, effectively creating a mask.
Can anyone run me through how SetRenderTarget works, when it needs to be called, etc?
I was trying to create a new texture with D3DXCreateTexture, and then grab the surface of that texture, and pass to the Device with SetRenderTarget. However, I'm doing this operation in the middle of a Scene, and I'm not sure when the actually rendering of the Draw() command gets done.
Here's an example of some of the things I've tried...
IDirect3DSurface9* newRT;
IDirect3DSurface9* oldRT;
texture->getTexture()->GetSurfaceLevel(0, &newRT); //Set newRT to the surface of the texture I want to write to (needed so I can find newRT later)
game->getDevice()->CreateRenderTarget(pos.right - pos.left, pos.bottom - pos.top, D3DFMT_UNKNOWN, D3DMULTISAMPLE_NONE, 0, 0, &newRT, NULL); //turn the texture into a render target
game->getDevice()->GetRenderTarget(0, &oldRT); //get old render targe
game->getDevice()->SetRenderTarget(0, newRT); //set the render target to the texture
for (int i = 0; i < childern.size(); i++) //draw the childern
childern[i]->draw(g_ppSprite);
game->getDevice()->SetRenderTarget(0, oldRT); //set render target back
This produces no results at all. It renders as if I never switched targets.