How to stretch surfaces?

Started by
3 comments, last by Evil Steve 17 years, 5 months ago
Hello. I'm writing the image viewing application. I was about to implement some image zoom in/out. What I want to do on zoom-in is to have to copy part of the image that is currently on the screen to back buffer. Then run Direc3D device Present(). Image copying also requires that part of image to get stretched to fit the screen. How do I implement image copying with stretching in best way?
ai-blog.org: AI is discussed here.
Advertisement
IDirect3DDevice9::StretchRect()?
If you're using D3D, it's usually a bad idea to read or write directly to the backbuffer. You'd probably be better off creating a texture with one mip level, and then drawing a single screen sized textured quad.

You could also make use of alpha blending and render to texture to do layers and transparancy and other cool stuff if you want to combine images onto one another, or make your app into an image editor.

What language / compiler / DirectX version are you using?
Quote:Original post by Evil Steve
IDirect3DDevice9::StretchRect()?
If you're using D3D, it's usually a bad idea to read or write directly to the backbuffer. You'd probably be better off creating a texture with one mip level, and then drawing a single screen sized textured quad.

You could also make use of alpha blending and render to texture to do layers and transparancy and other cool stuff if you want to combine images onto one another, or make your app into an image editor.

What language / compiler / DirectX version are you using?


Thanks, Steve. I'm using MSVC 2005, DirectX 9. I'm now trying to use textures with one mip map level and it works great.

One more question about textures. I use
D3DXCreateTextureFromFileEx()
function to create textures. I have noticed that this might be performance effective to create textures whenever I want to open a new image: e.g. image 1280x960 image will be placed into 2048x1024 texture. So 2048x1024 texture is created every time. Why there are no D3DXLoadTextureFromFileEx function available or else?:( Or maybe iimage can be loaded into texture in some other way? How do you think? Thanks.
ai-blog.org: AI is discussed here.
Some hardware requires that texture dimensions be a power of two, in which case D3DXCreateTextureFromFileEx will create the smallest power of 2 sized texture that the image will fit into, then put the image in the top left corner.

There are a couple of flags in the D3DCAPS9 relating to this. This from the DXSDK documentation:

Quote:
D3DPTEXTURECAPS_NONPOW2CONDITIONAL
Conditionally supports the use of 2-D textures with dimensions that are not powers of two. A device that exposes this capability can use such a texture if all of the following requirements are met.
The texture addressing mode for the texture stage is set to D3DTADDRESS_CLAMP.
Texture wrapping for the texture stage is disabled (D3DRS_WRAPn set to 0).
Mipmapping is not in use (use magnification filter only).
Texture formats must not be DXT1-5.
A texture that is not a power of two cannot be set at a stage that will be read based on a shader computation (such as the bem, beml, or texm3x3 instructions in pixel shaders versions 1_0 to 1_3). For example, these textures can be used to store bumps that will be fed into texture reads, but not the environment maps that are used in texbem, texbeml, or texm3x3spec. This means that a texture with dimensions that are not powers of two cannot be addressed or sampled using texture coordinates computed within the shader. This type of operation is known as a dependent read and cannot be performed on these types of textures.

D3DPTEXTURECAPS_POW2
All textures must have widths and heights specified as powers of two. This requirement does not apply to either cube textures or volume textures.


If these hardware requirements are in place then any way you try to create a texture without power of two dimensions will either override you or fail.
Quote:Original post by cpp forever
Why there are no D3DXLoadTextureFromFileEx function available or else?:( Or maybe iimage can be loaded into texture in some other way? How do you think? Thanks.
You can create a texture (with one mip level, again) using IDirect3DDevice9::CreateTexture(), and then use IDirect3DTexture9::GetSurfaceLevel() to get the top level surface of that texture, then use D3DXLoadSurfaceFromFile to load the image into the top level surface of the texture. Just don't forget to Release() the surface once you've loaded into it.

This topic is closed to new replies.

Advertisement