Scaling Surfaces?

Started by
5 comments, last by Dov Sherman 21 years, 2 months ago
I need to copy the image from my IDirect3DSurface8 primary buffer to another surface but I want the new copy to be a scaled down so the usual CopyRects() won''t work. How can I scale the image data from a surface? I''m trying to save scaled down screenshots of my program.
Advertisement
There are people here more qualified than I to answer, but I do believe the Blt() function auomatically scales images if the source and destination rects are different. I''m not sure exactly how to do it in DX8, but it should be similar to previous DirectX''s. Do a search for the Blt() function.


"There are only three types of people in this world: those who can count, and those who can''t."

Just3D
Justin Nordin
J Squared Productions
www.jsquaredproductions.com
"There are only three types of people in this world: those who can count, and those who can't."Just3DJustin NordinJ Squared Productionswww.jsquaredproductions.com
Hi - have you considered creating a surface that can serve as a render target and then using Direct3DDevice8.SetRenderTarget to render to this surface instead of your primary buffer? DX8 should scale the output to fit the target. You could then use the d3dx8.SaveSurfaceToFile to save your render target surface to a file.

There are two tutorials on www.mvps.org that might be of help. While neither tells you how to do the above completely, their info might be combined...

1) Rendering to multiple windows
http://www.mvps.org/directx/articles/rendering_to_multiple_windows.htm

This explains the basics or using SetRenderTarget to redirect rendering output to a different window -- here you could simply redirect it to a render-target-enabled surface.

2) Saving a Screen Shot in DirectX Graphics
http://www.mvps.org/directx/articles/screengrab.htm
This explains how to use d3dx8.SaveSurfaceToFile -- it''s aimed at full-size screenshots, though.

Hope all of this helps-

BM
quote:Original post by bmoberly
Hi - have you considered creating a surface that can serve as a render target and then using Direct3DDevice8.SetRenderTarget to render to this surface instead of your primary buffer? DX8 should scale the output to fit the target. You could then use the d3dx8.SaveSurfaceToFile to save your render target surface to a file.


That''s a good idea! But SetRenderTarget() won''t work with a standard IDirect3DSurface8 created with CreateImageSurface(). According to the SetRenderTarget() docs: "The new render target surface must have at least D3DUSAGE_RENDERTARGET specified."

How do I enable a simple image surface to have D3DUSAGE_RENDERTARGET specified?
The easiest way is to use CreateRenderTarget() instead of CreateImageSurface(). You can still use the surface for whatever else you need, it just lets DirectGraphics know that its a special surface.
Ah! That works perfectly! Thank you, Sages.
oops - Sages is right - use createrendertarget. You can also create a texture with the rendertarget usage flag set and then render to that texture''s surface -- this is what I was thinking of. BUT Sages'' suggestion is much more efficient.

Good luck!

-BM

This topic is closed to new replies.

Advertisement