I'm experimenting render-to-texture under dx9 (2005 update).
In my initialization routine (I work in windowed mode) I've written something like:
//D3DPresentParam.BackBufferFormat = D3DFMT_UNKNOWN;
Direct3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, CurrentWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &D3DPresentParam, &Direct3DDevice)))
//create vertex buffer, declaration, shader (1.1) etc. no error here
Direct3DDevice->CreateTexture(WindowClientRect.right - WindowClientRect.left, WindowClientRect.bottom - WindowClientRect.top, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &RenderTexture, NULL);
//no error, D3DFMT_X8R8G8B8 is like the back buffer
//I take the first layer
RenderTexture->GetSurfaceLevel(0, &RenderSurface);
//obviously
Direct3DDevice->GetRenderTarget(0, &BackBuffer);
//after this ->SetVertexDeclaration, ->SetVertexShader, ->SetStreamSource etc...
no error here so I continue and the render pass is:
//note this code is for testing
Direct3DDevice->SetRenderTarget(0, RenderSurface);
Direct3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);
Direct3DDevice->BeginScene()))
Direct3DDevice->EndScene();
Direct3DDevice->SetRenderTarget(0, BackBuffer);
Direct3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0);
Direct3DDevice->BeginScene();
Direct3DDevice->SetTexture(0, RenderTexture);
Direct3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2)))
Direct3DDevice->EndScene();
nothing wrong I think (I've omitted a lot of code in order to keep this post short. The shader used is quite simple:
vs_1_1
dcl_position v0
dcl_texcoord v1
mov oPos, v0
mov oT0.xyzw, v1
but when I render in the central quad (that I render associated with the texture cleared with D3DCOLOR_XRGB(0, 255, 0) I got garbage:
as you can see background is D3DCOLOR_XRGB(0,0,255) but the texture seems to not have been clear at all. That is very strange. If I'd use D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER (a commond mistake) this will be a normal error but now I'm a little confused
[Edited by - bjogio on August 6, 2005 9:24:27 AM]