• Advertisement
Sign in to follow this  

Render to texture

This topic is 2654 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 use
if(FAILED(g_pd3dDevice->CreateTexture(512 , 512 , 1 , D3DUSAGE_RENDERTARGET , D3DFMT_A8R8G8B8 , D3DPOOL_DEFAULT , &g_pRenderTexture , 0)))
to create a texture, then render the scene to it.
windows is:
HWND hWnd = CreateWindow("Render to Texture" , "Render to Texture"
, WS_OVERLAPPEDWINDOW , 0 , 0 , 640 ,480 , GetDesktopWindow()
, 0 , wndClass.hInstance , 0);

But the result is wrong.The scene is not rendered right.

But if I change the texture's width and hight to 256,256,
or increase window's width and hight more than 512 ,for example 1024,560,

the result is right.

How to explain this?

Share this post


Link to post
Share on other sites
Advertisement
What do you mean it's "wrong"? Can we get a screenshot?

What size is your backbuffer in your D3DPRESENT_PARAMETERS?

Share this post


Link to post
Share on other sites
your depth buffer surface has to be same size (or larger) as your render target!
i bet that you are using default depth buffer:

PresentParams.EnableAutoDepthStencil = TRUE;

witch creates default depth buffer with size: 640x480
create another depth buffer surface and use it along with your rt:

dev->SetRenderTarget(0, yourRT);
dev->SetDepthStencilSurface(yourNewDepthBuffer);
dev->Clear(...);

Share this post


Link to post
Share on other sites
when testing your projects always enable d3d debugging:

#define D3D_DEBUG_INFO // define at top
...
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9d.lib")


and use dx control panel.

Share this post


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

  • Advertisement