Jump to content

  • Log In with Google      Sign In   
  • Create Account


How store a screenshot into the texture?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 michaelmk86   Members   -  Reputation: 189

Like
0Likes
Like

Posted 21 June 2012 - 06:28 PM

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");
	



Sponsor:

#2 michaelmk86   Members   -  Reputation: 189

Like
0Likes
Like

Posted 23 June 2012 - 05:03 PM

Does anyone know how to get a screenshot on a texture?

#3 Fredericvo   Members   -  Reputation: 229

Like
0Likes
Like

Posted 23 June 2012 - 05:39 PM

A screenshot? Do you mean render to texture?

#4 TiagoCosta   Crossbones+   -  Reputation: 1865

Like
0Likes
Like

Posted 23 June 2012 - 05:51 PM

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, 23 June 2012 - 05:56 PM.

Tiago Costa
Aqua Engine - my DirectX 11 game "engine" - In development

#5 mhagain   Crossbones+   -  Reputation: 7431

Like
0Likes
Like

Posted 23 June 2012 - 06:19 PM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#6 michaelmk86   Members   -  Reputation: 189

Like
0Likes
Like

Posted 23 June 2012 - 06:23 PM

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;

#7 TiagoCosta   Crossbones+   -  Reputation: 1865

Like
0Likes
Like

Posted 24 June 2012 - 03:12 AM

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?
Tiago Costa
Aqua Engine - my DirectX 11 game "engine" - In development

#8 michaelmk86   Members   -  Reputation: 189

Like
0Likes
Like

Posted 24 June 2012 - 04:40 AM


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?

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)

#9 TiagoCosta   Crossbones+   -  Reputation: 1865

Like
0Likes
Like

Posted 24 June 2012 - 04:57 AM



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?

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)


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, 24 June 2012 - 05:05 AM.

Tiago Costa
Aqua Engine - my DirectX 11 game "engine" - In development




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS