Click to See Complete Forum and Search --> : DirectX Masks?


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.

Sharsnik
March 23rd, 2008, 06:46 PM
Looks like I figured it out. The issue was that I wasn't rendering to the texture's relative coordinates.... coupled with the fact that I didn't know what I was doing... that was a lot more painful that it needed to be :p