Jump to content
  • Advertisement
Sign in to follow this  
technology

render to texture

This topic is 4898 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

hi I am looking for some examples of how to render to a texture,i have seen some codes but they seem to swap the rendertarget. i need a clear examaple btw i am using this to render backbuffer image to a mesh,this is waht we call offscreen rendering?? backbuffer->texture->texture for a mesh thanks

Share this post


Link to post
Share on other sites
Advertisement
Render To Target... NVidia has by far the best example. When they switch targets its called MRT( Multiple Render Target ). The reasont hey do that is for deferred shading or lighting. They need 3 or 4 targets because each pixel requires more space than just the color.

If you take the example from nvidia or whatever examples you have, just use exactly what they do for one, and dont do the other switches. for instance, create a back buffer surface and create another surface and a texture for that surface. Then when ya render just do a render to target on the new surface, then test it by outputing the texture to bitmap. then if its outputing correctly, go ahead and just set that texture to the current texture and set the render target to the back buffer. and render like normal. It is just 2 steps, one more than your normal RenderToTarget(backbuffer). If ya need actual code and more examples just post back, I gotta get back to work for right now.

What you will want to lookup as well:
GetBackBuffer(...)
GetDepthStencilSurface(...)
CreateTexture(...)
GetSurfaceLevel(...)
SetRenderTarget(...)
SetDepthStencilSurface(...)


You will be using all of these pretty much.

Share this post


Link to post
Share on other sites
As i said it does'nt work by setting rendertarget ,what i get is garbage texture

here is the code


LPDIRECT3DSURFACE8 m_pOldRenderSurface;
LPDIRECT3DSURFACE8 m_pDepthStencilSurface;
LPDIRECT3DSURFACE8 m_pNewRenderSurface;
LPDIRECT3DTEXTURE8 m_pScreenTexture;
D3DSURFACE_DESC pDesc;

//init
m_pIDirect3DDevice8->GetRenderTarget( &m_pOldRenderSurface );
m_pOldRenderSurface->GetDesc(&pDesc);
m_pIDirect3DDevice8->GetDepthStencilSurface( &m_pDepthStencilSurface );
m_pIDirect3DDevice8->CreateTexture(512,512,1,pDesc.Usage,pDesc.Format,D3DPOOL_DEFAULT,&m_pScreenTexture);
m_pScreenTexture->GetSurfaceLevel( 0, &m_pNewRenderSurface );

//beginscene()
m_pIDirect3DDevice8->SetRenderTarget( m_pNewRenderSurface,m_pDepthStencilSurface );

//before endscene()

m_pIDirect3DDevice8->SetRenderTarget( m_pOldRenderSurface,m_pDepthStencilSurface );

//now m_pScreenTexture should have the texture but not

Share this post


Link to post
Share on other sites
The texture you're rendering to is 512 x 512. You use the same stencil buffer as your back buffer, which I'm guessing is something like 640 x 480, or 800 x 600. Try making your texture size match your back buffer size and see if that works.

Share this post


Link to post
Share on other sites
Ok, I take it your're rendering the stuff in between the 2 render surfaces? Are you using shaders? Also, clear the surface each render ->Clear(...). Are you outputing yer texture with D3DXSaveTextureToFile(...)? put it in there if ya dont just to be sure its the texture thats in trouble. And what Battagline said is definitly true. I believe it has to be the same size. Also check the caps on your card, it might not support non POW2.

Share this post


Link to post
Share on other sites
Trying to perform render to texture I had found two nice ways.
One is like Technology illustrate: using RenderTargets and calling SetRenderTarget, the other is using ID3DXRenderToSurface and BeginScene(...)-EndScene(...).

By experience which you consider to be faster?
I heard that RenderTarger is not supported in old cards but D3DXRenderToSurface is widely supported; is that right?

Share this post


Link to post
Share on other sites
Quote:
Original post by fpuig
Trying to perform render to texture I had found two nice ways.
One is like Technology illustrate: using RenderTargets and calling SetRenderTarget, the other is using ID3DXRenderToSurface and BeginScene(...)-EndScene(...).

By experience which you consider to be faster?
I heard that RenderTarger is not supported in old cards but D3DXRenderToSurface is widely supported; is that right?


That's interesting... I have never seen D3DXRenderToSurface. I'll have to look it up.

Share this post


Link to post
Share on other sites
I had searched a bit deeper and both methods (RenderTargets and RenderToSurface) seems to work the same, both need a surface(texture) and using different interfaces allow to rendering to the texture.

However, now I have doubt: When SetRenderTarget or RenderToSurface->BeginScene(...) what is setted is the back buffer (the color buffer), but what about the depth buffer. In my aplication I need to render to a texture but using a different zbuffer so the actual zbuffer doesn't be modified. How that can be accomplish?

Share this post


Link to post
Share on other sites
You can use a 512*512 render target texture (RTT) with a 640x480 zbuffer. You dont need to create a texture/surface with the same dimensions than your zbuffer. The same ZBuffer is used for the new rendertarget. You should worry if your RTT is greater than your zbuffer (say a 1024*1024 RTT).

If the zbuffer has already been used for rendring in the same frame then you should clear the zbuffer. You can set another z/stencil buffer using D3DDEVICE9::SetDepthStencilSurface() if you wish to keep the original zbuffer but you still have to clear it.

Finally, dont try to do a BeginScene/EndScene inside another BeginScene/EndScene or it will fail.

Luck!
Guimo

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!