• Advertisement
Sign in to follow this  

How store a screenshot into the texture?

This topic is 2038 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 need to save the ShadowMap screen into a texture (IDirect3DBaseTexture9 or IDirect3DTexture9) like a screenshot, so I can use the data in this texture during my ShadowedScene.

what I have done so far is not working (I get an error: Unhandled exception at 0x67638d9e in Project.exe: 0xC0000005: Access violation reading location 0x00000080.)



IDirect3DBaseTexture9* ShadowMapTex;
IDirect3DSurface9* RenderTarget;

render("ShadowMap");

Device->GetRenderTarget(0, &RenderTarget);
ShadowMapTex = (IDirect3DBaseTexture9*)RenderTarget;
lightingFX.fx->SetTexture("xShadowMap", ShadowMapTex);
Device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0L);

render("ShadowedScene");


[/quote]

Share this post


Link to post
Share on other sites
Advertisement
I'm not really familiar with DirectX 9, but you have to create a ID3DXRenderToSurface* object using D3DXCreateRenderToSurface() function, then create a IDirect3DTexture9* and use

IDirect3DTexture9* pTexture;

//Create texture here


IDirect3DSurface9* pSurface;
pTexture->GetSurfaceLevel(0, &pSurface);

to get the surface.

To use the texture as a render target use the ID3DXRenderToSurface function BeginScene() and EndScene() function and pass the surface as an argument:

ID3DXRenderToSurface* pRenderToSurf;

//Create Render to Surface here

pRenderToSurf->BeginScene(pSurface, &viewPort);

//draw the scene


pRenderToSurf->EndScene(D3DX_FILTER_NONE);

Edited by TiagoCosta

Share this post


Link to post
Share on other sites
In general you won't take a screenshot and save it to a texture - that's going to involve a round-trip from the GPU to system memory and back and will be very very slow indeed. As advised, you need a proper render-to-texture setup instead.

Share this post


Link to post
Share on other sites

I'm not really familiar with DirectX 9, but you have to create a ID3DXRenderToSurface* object using D3DXCreateRenderToSurface() function, then create a IDirect3DTexture9* and use

IDirect3DTexture9* pTexture;

//Create texture here


IDirect3DSurface9* pSurface;
pTexture->GetSurfaceLevel(0, &pSurface);

to get the surface.

To use the texture as a render target use the ID3DXRenderToSurface function BeginScene() and EndScene() function and pass the surface as an argument:

ID3DXRenderToSurface* pRenderToSurf;

//Create Render to Surface here

pRenderToSurf->BeginScene(pSurface, &viewPort);

//draw the scene


pRenderToSurf->EndScene(D3DX_FILTER_NONE);




I'm not really familiar with DirectX 9, but you have to create a ID3DXRenderToSurface* object using D3DXCreateRenderToSurface() function, then create a IDirect3DTexture9* and use

IDirect3DTexture9* pTexture;

//Create texture here


IDirect3DSurface9* pSurface;
pTexture->GetSurfaceLevel(0, &pSurface);

to get the surface.

To use the texture as a render target use the ID3DXRenderToSurface function BeginScene() and EndScene() function and pass the surface as an argument:

ID3DXRenderToSurface* pRenderToSurf;

//Create Render to Surface here

pRenderToSurf->BeginScene(pSurface, &viewPort);

//draw the scene


pRenderToSurf->EndScene(D3DX_FILTER_NONE);




I just need to get a screenshot and store it into a texture (IDirect3DTexture9*).

samething like that:
IDirect3DTexture9* myTexture;
myTexture = screenshot;

Share this post


Link to post
Share on other sites

I just need to get a screenshot and store it into a texture (IDirect3DTexture9*).

samething like that:
IDirect3DTexture9* myTexture;
myTexture = screenshot;


Whats the type of screenshot variable in your example?

Share this post


Link to post
Share on other sites

[quote name='michaelmk86' timestamp='1340497402' post='4952152']
I just need to get a screenshot and store it into a texture (IDirect3DTexture9*).

samething like that:
IDirect3DTexture9* myTexture;
myTexture = screenshot;


Whats the type of screenshot variable in your example?
[/quote]
what do you mean type of screenshot?

IDirect3DTexture9* myTexture;
myTexture = GetScreenshot; (I mean get every pixel of the screen and store it into a texture)

Share this post


Link to post
Share on other sites

[quote name='TiagoCosta' timestamp='1340529168' post='4952264']
[quote name='michaelmk86' timestamp='1340497402' post='4952152']
I just need to get a screenshot and store it into a texture (IDirect3DTexture9*).

samething like that:
IDirect3DTexture9* myTexture;
myTexture = screenshot;


Whats the type of screenshot variable in your example?
[/quote]
what do you mean type of screenshot?

IDirect3DTexture9* myTexture;
myTexture = GetScreenshot; (I mean get every pixel of the screen and store it into a texture)
[/quote]

Basically when you get a surface from a texture and use it in the SetRenderTarget() function (or as an argument of the ID3DXRenderToSurface->BeginScene() ) the draw calls will actually be drawn in the texture, so it's like a screenshot.

Check this article for more complete source code. Edited by TiagoCosta

Share this post


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

  • Advertisement