Jump to content
  • Advertisement
Sign in to follow this  
Syranide

ID3DXSprite render to texture?

This topic is 5125 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

(I'm talking ID3DXSprite and only 2D drawing now) By default (and as I've found) the only think you can do is to draw directly to the backbuffer and then present it. But if I want to "render" my own textures using other textures, how would I accomplish that, as in the old DD, instead of automatically drawing onto the backbuffer I want to be able to draw on another texture for instance. Of what I can see it is not possible, all I've found is ways to draw onto a surface instead (probably), but that doesn't work as it ain't texture. Simply, how do you draw onto a texture (which in term can be used to draw onto other textures/backbuffer) using other textures? IDirect3DDevice9::SetTexture perhaps? (But that too takes a BaseTexture...)

Share this post


Link to post
Share on other sites
Advertisement
In Direct3D, the thing you write to is called a "Render Target". Normally, this is the main framebuffer that is displayed on the screen, however, you can create your own Render Targets and then set them to be drawn to. You can then use them as textures later on.

Here's an outline, if you're still having trouble after referencing the docs, ask some more:

1) Create a texture usable as a render target - Look up CreateTexture() and D3DUSAGE_RENDERTARGET

2) Set this texture as the active render target - Look up SetRenderTarget(). Remember to save your original framebuffer render target before doing this (hint: GetRenderTarget())

3) Once the render target texture has been rendered to, you can use it as a texture source, this is where you use SetTexture().

Something to be wary of: you cannot render-to and read-from a texture at the same time! the results are undefined!

-Mezz

Share this post


Link to post
Share on other sites
Ok, great, got it all set up now... but, this was the reason why I didn't really go for RenderTarget at first... because it requires a Surface...

and Texture ain't a superclass for Surface... so it's kinda a dead end or is there some neat conversion or other trick that will do the work?

Just to make things clear

HRESULT SetRenderTarget(
DWORD RenderTargetIndex,
IDirect3DSurface9 *pRenderTarget
);

(oh, btw, RenderTargetIndex is supposed to be 0 as I don't use multiple rendertargets I guess? If you don't know straight out don't bother, it is easy to find out when it is "working")

Share this post


Link to post
Share on other sites
Yes, SetRenderTarget() needs a surface, which is why we have the following:

IDirect3DTexture9::GetSurfaceLevel()

Use the surface retrieved by that call as the parameter for SetRenderTarget().

Also, yes, RenderTargetIndex should be zero unless you're using MRTs.

-Mezz

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!