How store a screenshot into the texture?

Started by
7 comments, last by Aqua Costa 11 years, 9 months ago
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]
Advertisement
Does anyone know how to get a screenshot on a texture?
A screenshot? Do you mean render to texture?
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);

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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


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;

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 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 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.

This topic is closed to new replies.

Advertisement