Jump to content

  • Log In with Google      Sign In   
  • Create Account

DirectX 9 SetRenderTarget


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
10 replies to this topic

#1 onetwothreegone   Members   -  Reputation: 230

Like
0Likes
Like

Posted 11 May 2014 - 05:57 PM

I got my code to be able to render to a surface with device->SetRenderTarget, but I was wondering how to set it back to rendering to a window. Also is there a better way of rendering to a texture then with SetRenderTarget?

 

I have been looking around the web for a while but can't find any examples on how to set the render target back to the window.

 

Thanks,

Philip



#2 L. Spiro   Crossbones+   -  Reputation: 23975

Like
0Likes
Like

Posted 11 May 2014 - 07:18 PM

After you create the back buffers and they are applied, save them via IDirect3DDevice9::GetRenderTarget().  Restore them when necessary.


L. Spiro



#3 Hodgman   Moderators   -  Reputation: 47829

Like
0Likes
Like

Posted 11 May 2014 - 07:31 PM

Right after you create your device, use use code like this to get a pointer to the "screen" (the default colour target and default depth target).

IDirect3DSurface9* defaultColorBuffer = 0;
IDirect3DSurface9* defaultDepthBuffer = 0;
device->GetRenderTarget( 0, &defaultColorBuffer );
device->GetDepthStencilSurface( &defaultDepthBuffer );

After rendering to a texture, you can use device->SetRenderTarget(defaultColorBuffer) to go back to rendering to the screen.

Yes, SetRenderTarget is the correct way to render to textures wink.png

 

[edit] ninja'ed by LS ph34r.png


Edited by Hodgman, 11 May 2014 - 07:31 PM.


#4 Tispe   Members   -  Reputation: 1410

Like
3Likes
Like

Posted 11 May 2014 - 11:52 PM

Right after you create your device, use use code like this to get a pointer to the "screen" (the default colour target and default depth target).

IDirect3DSurface9* defaultColorBuffer = 0;
IDirect3DSurface9* defaultDepthBuffer = 0;
device->GetRenderTarget( 0, &defaultColorBuffer );
device->GetDepthStencilSurface( &defaultDepthBuffer );

After rendering to a texture, you can use device->SetRenderTarget(defaultColorBuffer) to go back to rendering to the screen.

Yes, SetRenderTarget is the correct way to render to textures wink.png

 

[edit] ninja'ed by LS ph34r.png

 

And those surfaces has to be Released at the end of the program, and also released and reaquired when changing display settings?



#5 Hodgman   Moderators   -  Reputation: 47829

Like
0Likes
Like

Posted 11 May 2014 - 11:56 PM

And those surfaces has to be Released at the end of the program, and also released and reaquired when changing display settings?

Yep!



#6 L. Spiro   Crossbones+   -  Reputation: 23975

Like
1Likes
Like

Posted 12 May 2014 - 01:09 AM

And those surfaces has to be Released at the end of the program, and also released and reaquired when changing display settings?

Yep!


L. Spiro


[edit]Ninja’d by Hodgman. ph34r.png [/edit]


Edited by L. Spiro, 12 May 2014 - 01:09 AM.


#7 mhagain   Crossbones+   -  Reputation: 11332

Like
0Likes
Like

Posted 12 May 2014 - 04:10 AM

Also is there a better way of rendering to a texture then with SetRenderTarget?

 

Since the other answers didn't deal with this part, can you say what's wrong for you about SetRenderTarget that you need a better way?  SetRenderTarget is the best way in D3D9 to accomplish render-to-texture.

 

There is however another way, but it's going to be less flexible and more bandwidth-intensive; that's to create a texture with D3DUSAGE_RENDERTARGET as before, then StretchRect from the backbuffer to it, then draw it as a fullscreen quad.


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.


#8 onetwothreegone   Members   -  Reputation: 230

Like
0Likes
Like

Posted 12 May 2014 - 09:26 AM

Thank you all, I got it now. One last thing, how much longer will graphics cards be able to run DirectX 9 apps?

 

EDIT:

It appears to not be working right, looking at my code it seems I am not correctly setting the target back to the window. But it could also be that the target is not being properly set to the texture. The result is the texture is blank except for what I draw onto it. The draw area is only the size of the texture, even after I set the render target back to the window.

 

Code:

	if (t == nullptr) // Passing a nullptr means we need to render to the window.
	{
		if (renderTarget != NULL)
			renderTarget->Release();

		renderTarget = NULL;
		targetId = -1;

		device3d->SetRenderTarget(1, windowTarget);
	}
	else
	{
		if (renderTarget != NULL)
		{
			renderTarget->Release();
			renderTarget = NULL;
		}

		gameTextures[t->ID]->Texture->GetSurfaceLevel(0, &renderTarget); // Create                a surface out of the texture.

		targetId = t->ID;

		device3d->SetRenderTarget(1, renderTarget);

This is all wrapped up in a function.


Edited by onetwothreegone, 12 May 2014 - 05:01 PM.


#9 L. Spiro   Crossbones+   -  Reputation: 23975

Like
0Likes
Like

Posted 12 May 2014 - 05:06 PM

9 years, 3 months, 13 days, 2 hours, 48 minutes, 1 second, and 890 milliseconds.

Approximately.

 

 

L. Spiro ph34r.png


Edited by Hodgman, 12 May 2014 - 05:08 PM.
added a ninja


#10 mhagain   Crossbones+   -  Reputation: 11332

Like
0Likes
Like

Posted 12 May 2014 - 06:08 PM

9 years, 3 months, 13 days, 2 hours, 48 minutes, 1 second, and 890 milliseconds.

Approximately.

 

 

L. Spiro ph34r.png

 

Off by about an hour actually.

 

Honest answer: nowadays D3D9 is emulated via D3D10+.  Even modern versions of Windows can still run ancient D3D3 programs, and although that's not a definite indicator for the future, it should serve to give you an idea.

 

Basically there's so much software out there, particularly from the last console generation, still using D3D9 that if MS stopped supporting it in a new version of Windows, that new version would be rejected by customers.  Eventually it will die for sure, but you can confidently rely on it still being around for the foreseeable future.


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.


#11 milaoshu1982   Members   -  Reputation: 130

Like
0Likes
Like

Posted 12 May 2014 - 06:54 PM

save the back surface first,






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