Original Post
Hi! I'm trying to render to a texture so i can play with shaders but all I'm getting is a black screen, and I get no errors :'( this is the first time I've done this so I cant tell whats wrong so here's the relevant code: width and height are 800 and 600, they are fine, I've looked:
D3DXCreateTexture(D3DDevice, width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &renderTexture);
renderTexture->GetSurfaceLevel(0, &renderSurface);
//save original render target
IDirect3DSurface9* originalRT;
D3DDevice->GetRenderTarget(0,&originalRT);
//set new render target - the texture
D3DDevice->SetRenderTarget(0,renderSurface);
D3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
D3DDevice->BeginScene();
//render stuff
D3DDevice->EndScene();
D3DXMATRIX World;
D3DXMatrixTranslation(&World, 0.0f, 0.0f, 0.5f);
//set original render target, the back buffer
D3DDevice->SetRenderTarget(0,originalRT);
D3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
D3DDevice->BeginScene();
D3DDevice->SetTransform(D3DTS_WORLD, &World);
mat = *m_pMaterial->NoMaterial();
D3DDevice->SetMaterial(&mat); //clear any set material
D3DDevice->SetTexture(0,renderTexture);
SAQuad->DrawSubset(0);
D3DDevice->EndScene();
D3DDevice->Present(0, 0, 0, 0);
SAQuad is supposed to be a screen aligned quad, here's the code I use to try and make it:
ID3DXMesh* CMesh::CreateScreenAlignedQuad(IDirect3DDevice9* m_pDevice, int width, int height)
{
ID3DXMesh* Mesh = 0;
HRESULT hr = 0;
hr = D3DXCreateMeshFVF(
2, //Number of faces
4, //Number of vertices
D3DXMESH_MANAGED, //Options - Mesh will be placed the Managed memory pool
Vertex::FVF, //The FVF of the vertices of this mesh
m_pDevice, //D3D Device
&Mesh); //[OUT] created mesh
if(FAILED(hr)){
::MessageBox(0, "D3DXCreateMeshFVF() - FAILED", 0, 0);
return 0;
}
// Fill in vertices of our tile
Vertex* v = 0;
Mesh->LockVertexBuffer(0, (void**)&v);
// fill in the top face vertex data
// x y z
v[0] = Vertex( 0.0f, height, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f ); //BL
v[1] = Vertex( 0.0f, 0.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f ); //TL
v[2] = Vertex( width, 0.0f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f ); //TR
v[3] = Vertex( width, height, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f ); //BR
Mesh->UnlockVertexBuffer();
// Define the triangles of the box
WORD* i = 0;
Mesh->LockIndexBuffer(0, (void**)&i);
// fill in the top face index data
i[0] = 0; i[1] = 1; i[2] = 2;
i[3] = 0; i[4] = 2; i[5] = 3;
Mesh->UnlockIndexBuffer();
// Specify the subset each triangle belongs to
// There is just one subset
DWORD* attributeBuffer = 0;
Mesh->LockAttributeBuffer(0, &attributeBuffer);
for(int a = 0; a < 2; a++)
attributeBuffer[a] = 0;
Mesh->UnlockAttributeBuffer();
// Optimize the mesh to generate an attribute table.
std::vector<DWORD> adjacencyBuffer(Mesh->GetNumFaces() * 3);
Mesh->GenerateAdjacency(0.0f, &adjacencyBuffer[0]);
hr = Mesh->OptimizeInplace(
D3DXMESHOPT_ATTRSORT | //flag
D3DXMESHOPT_COMPACT | //flag
D3DXMESHOPT_VERTEXCACHE, //flag
&adjacencyBuffer[0], //pointer to adjacency array of non optimized array
0, 0, 0); //not needed, so zero
if(FAILED(hr))
{
::MessageBox(0, "OptimizeInplace() - FAILED", 0, 0);
return false;
}
return Mesh;
}
I've no idea what's wrong, I'm getting no errors or warnings, even when I put DirectX into Debug mode. Any and all help will be gratefully received!! It's got to be something to do with my SAQuad, I tried rendering to the terrain and got this result, so it must be working... http://img256.imageshack.us/img256/3076/weird.jpg