Skip to main content
gamedev.net
🔒 Locked

Render to texture

Started by zxlop Oct 18, 2010 at 10:10 AM 2 replies 750+ views
Original Post
zxlop
zxlop
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?
Evil Steve
Evil Steve
What do you mean it's "wrong"? Can we get a screenshot?

What size is your backbuffer in your D3DPRESENT_PARAMETERS?
belfegor
belfegor
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(...);
belfegor
belfegor
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.