Advertisement Jump to content
Sign in to follow this  

RenderTarget - Texture?

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

Hey guys I can't seem to get this right. I'm trying to draw my scene to a texture, and then plaster that texture as a billboard. (Trying to debug some culling stuff.) Anyway, here's the snippets: Here, I'm specifying that I want to set my render target to a surface.
		                   hRes = m_d3dDevice->CreateTexture(window->GetWidth(), window->GetHeight(), 0, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pRenderTexture, NULL);
				hRes = pRenderTexture->GetSurfaceLevel(0,&pRenderSurface);
				const WCHAR* err = DXGetErrorString9(hRes);
				hRes = m_d3dDevice->SetRenderTarget(0,pRenderSurface);
				err = DXGetErrorString9(hRes);

... Draw my scene here. ... And here, I'm trying to fill out a texture stored in window.
                                D3DSURFACE_DESC desc;
				hRes = pRenderSurface->GetDesc(&desc);
				IDirect3DTexture9* pTempTexture = NULL;
				hRes = m_d3dDevice->CreateTexture(desc.Width,desc.Height,0,D3DUSAGE_DYNAMIC,desc.Format,D3DPOOL_SYSTEMMEM,&pTempTexture,NULL);
				IDirect3DSurface9* pTempSurface = NULL;
				hRes = pTempTexture->GetSurfaceLevel(0,&pTempSurface);
				hRes = m_d3dDevice->GetRenderTargetData(pRenderSurface, pTempSurface);

				D3DLOCKED_RECT rect;
				hRes = pTempTexture->LockRect(0, &rect, NULL, 0);
				memcpy(window->GetRenderTarget(), rect.pBits, window->GetWidth() * window->GetHeight() * sizeof(char) * 4);
				hRes = pTempSurface->UnlockRect();



window->GetRenderTarget was allocated properly: new char[width * height * sizeof(char) * 4]; There is no dx debugging error output. Technically everything here seems to be "correct" with incorrect results. Now, the frustrating part is that D3DXSaveTextureToFile saves out my image correctly. However, when I try to render my texture in DX, I get a 2/3 green square, with the last 1/3 as black. So I'm slightly confused. The texture I'm displaying gets created as follows:
           case ITexture::Ax8Rx8Gx8Bx8:
		szType = sizeof(char);
		hRes = m_d3dDevice->CreateTexture(texture->GetWidth(), texture->GetHeight(), 0, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &d3dTexture, NULL);

So if anyone knows what I'm doing wrong... Thanks, David

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!