Jump to content
  • Advertisement
Sign in to follow this  
smek2

FrontBuffer to texture = garbage

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

Hi, I try to "capture" the screen at any given moment. I already found numerous sourcodes and explanation how to take a screenshot, but that's not what i want to do. I want to grab the content of the FrontBuffer, save it to a surface and later copy this surfaces content to a texture resource. Then i want to draw a texture quad using this texture. So far i came up with this:
LPDIRECT3DTEXTURE9 pRenderTexture = NULL;
LPDIRECT3DSURFACE9 pTextureSurf=NULL,pFrontBuffer = NULL;
   m_pD3dDev->CreateTexture(256,256,1,D3DUSAGE_RENDERTARGET,D3DFMT_R5G6B5,D3DPOOL_DEFAULT,&pRenderTexture,NULL);
m_pD3dDev->CreateOffscreenPlainSurface(GetWidth(), GetHeight(), D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pFrontBuffer, NULL);
m_pD3dDev->GetFrontBufferData(0, pFrontBuffer);

RECT rSource;
rSource.top=0;
rSource.bottom=255;
rSource.left=0;
rSource.right=255;

pRenderTexture->GetSurfaceLevel(0,&pTextureSurf);
m_pD3dDev->UpdateSurface(pFrontBuffer,&rSource,pTextureSurf,NULL);

But if i try to draw a quad using the texture "pRenderTexture", garbage is filling my screen. Any suggestions? My App runs in Fullscreen, using "D3DSWAPEFFECT_FLIP" as swap effect.

Share this post


Link to post
Share on other sites
Advertisement
ur texture has a different color format than your front buffer, but I don´t know if that could be the reason or if it´s just converted or anything like that.

Share this post


Link to post
Share on other sites
Yes, stupid me. But changing that didnt work either.
Well, at least i get a white texture now, no more garbage.
I'm quiet sure it must be something small and rather simple, it usually is.
Stupid me.

Share this post


Link to post
Share on other sites
I don't know if it will works but after all drawings operations done try to capture back buffer instead of front with g_pd3dDevice->GetBackBuffer().

Share this post


Link to post
Share on other sites
Nope doesnt work either.
I'm getting the backbuffer after the call to D3DDevice->Present.
Still i am getting a white texture.
Maybe something is wrong with "m_pD3dDev->UpdateSurface(pFrontBuffer,&rSource,pTextureSurf,NULL);"?

Maybe, i should explain what i try to do.
Basically i want to grab the current screen whenever the user is pressing ESC, so i can use it as a background texture for my menu. Like in some games, you open a menu, and the background, the game scene, will blur a bit. Or become all grayscale. I think it's not a good idea to draw the whole scene and then paint the menu over it. I'd rather would like to grab the actual frontbuffer content then copy to a texture. Then i'd like to fill the whole screen with a texture quad using this texture, so i can paint my menu over it.
Hope my not-so-perfect english isnt that confusing. ;)

Share this post


Link to post
Share on other sites
Ok, i got it now. As ususal, the real problem was me not reading the the whole manual.
Of course i had to use GetBackBuffer(), after presenting my scene.
Using GetFronBufferdata, i would had to render the whole scene to a texture, which is definately not necessary.
So, just for the record (and in case someone might ask the same question) here's how i'm doing it now:



LPDIRECT3DTEXTURE9 pRenderTexture = NULL;
LPDIRECT3DSURFACE9 pTextureSurf=NULL,pBackBuffer = NULL;
m_pD3dDev->CreateTexture(256,256,1,D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&pRenderTexture,NULL);
m_pD3dDev->CreateOffscreenPlainSurface(GetWidth(), GetHeight(), D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pBackBuffer, NULL);
m_pD3dDev->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);

pRenderTexture->GetSurfaceLevel(0,&pTextureSurf);
m_pD3dDev->StretchRect(pBackBuffer,NULL,pTextureSurf,NULL,D3DTEXF_LINEAR);

pBackBuffer->Release();
pBackBuffer=NULL;

return pRenderTexture;


Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!