Direct3d texture usage

Source: Internet
Author: User
About texture usage
1. Texture Creation
2. Texture addressing
3. texture filtering


1. Texture Creation
<1> d3dxcreatetexture Function
Create an empty texture.
Hresult d3dxcreatetexture (
_ In lpdirect3ddevice9 pdevice,
_ In uint width,
_ In uint height,
_ In uint miplevels,
_ In DWORD usage,
_ In d3dformat format,
_ In d3dpool,
_ Out lpdirect3dtexture9 * pptexture
);
<2> d3dxcreatetexturefromfile Function
Create a texture from a file and support various formats of BMP,. Dds,. Dib,. HDR,. jpg,. PFM,. PNG,. ppm,. TGA
Hresult d3dxcreatetexturefromfile (
_ In lpdirect3ddevice9 pdevice,
_ In lpctstr psrcfile,
_ Out lpdirect3dtexture9 * pptexture
);
<3> d3dxcreatetexturefromfileex Function
This is a powerful texture creation function that integrates the d3dxcreatetexture and d3dxcreatetexturefromfile functions.
Hresult d3dxcreatetexturefromfileex (
_ In lpdirect3ddevice9 pdevice,
_ In lpctstr psrcfile,
_ In uint width,
_ In uint height,
_ In uint miplevels,
_ In DWORD usage,
_ In d3dformat format,
_ In d3dpool,
_ In DWORD filter,
_ In DWORD mipfilter,
_ In d3dcolor colorkey,
_ Inout d3dximage_info * psrcinfo,
_ Out paletteentry * ppalette,
_ Out lpdirect3dtexture9 * pptexture
);
After creating a texture, you must use the settexture function to start the texture.
Hresult settexture (
[In] DWORD sampler,
[In] idirect3dbasetexture9 * ptexture
);
Parameter sampler: Specifies the texture layers. sampler specifies the sampling Status values, such as filtering mode and addressing mode.
Parameter ptexture: Specifies the texture pointer to be loaded.


2. Texture addressing
The addressing mode of textures. Common features include repeated addressing mode, image addressing mode, clip addressing mode, border addressing mode, and one-time image addressing. The addressing function is as follows:
Hresult setsamplerstate (
[In] DWORD sampler,
[In] d3dsamplerstatetype type,
[In] DWORD Value
);
Sampler: sampler number
D3dsamplerstatetype: sampler status type
Value: the value of the specified state of the sampler.
From the enumeration type d3dsamplerstatetype, we can find that the three enumeration variables about addressing mode settings are:
D3dsamp_addressu = 1,
D3dsamp_addressv = 2,
D3dsamp_addressw = 3,
The value of the corresponding value should be from the enumerated variable value d3dtextureaddress
Typedef Enum d3dtextureaddress {
D3dtaddress_wrap = 1,
D3dtaddress_mirror = 2,
D3dtaddress_clamp = 3,
D3dtaddress_border = 4,
D3dtaddress_mirroronce = 5,
D3dtaddress_force_dword = 0x7fffffff
} D3dtextureaddress, * lpd3dtextureaddress;
<1> d3dtaddress_wrap

Repeated addressing


<2> D3DTADDRESS_MIRROR

Image addressing


<3> d3dtaddress_clamp

Access addressing


<4> D3DTADDRESS_BORDER

Border color addressing


<5>D3dtaddress_mirroronce

This is a combination of image addressing and clip addressing. It obtains the absolute value of texture coordinates, from 0 to the image addressing, and from the maximum position to the addressing.


It is to use 0 as the boundary to mirror the negative and positive coordinates. Therefore, the image is created in [-], and the image is clipped out of this range. In addition, if there is no negative coordinate value in the texture coordinate, the effect will be exactly the same as that in the clip addressing mode.

<6> Texture wrapping

When the system draws a polygon, the texture coordinate values of the vertices are interpolated to determine the texture coordinate values of each pixel in the polygon. In general, the system regards the texture as a 2D plane. When interpolation is performed through the shortest route between vertices, it will be a line segment under the 2D plane.

Texture packaging means that when the fingerprint processing is interpolation, it is no longer a 2D plane. For example, packaging in the U direction is to enclose the texture into a cylindrical surface, in this case, the shortest distance between two vertices is the shortest distance on the cylindrical surface, instead of the shortest distance on the plane. As shown in:


The minimum distance between A and B is not a line segment between two points on the image plane. When UV is wrapped in both directions, it can be imagined as a bread.

3. texture filtering

Texture filtering is also set through the setsamplerstate function. Now let's continue.D3DSAMPLERSTATETYPEAll types of the enumerated types are as follows:

typedef enum D3DSAMPLERSTATETYPE {
  D3DSAMP_ADDRESSU        = 1,
  D3DSAMP_ADDRESSV        = 2,
  D3DSAMP_ADDRESSW        = 3,
D3dsamp_bordercolor = 4, // set the texture boundary color
D3dsamp_magfilter = 5, // amplified Filter
D3dsamp_minfilter = 6, // narrow down the filter
D3dsamp_mipfilter = 7, // MIP Filter
D3dsamp_mipmaplodbias = 8, // offset value of multi-level texture ing
D3dsamp_maxmiplevel = 9, // maximum texture filtering level
D3dsamp_maxanisotropy = 10, // set the maximum value of the opposite sex. The larger the value, the better.
  D3DSAMP_SRGBTEXTURE     = 11,//
  D3DSAMP_ELEMENTINDEX    = 12,//
  D3DSAMP_DMAPOFFSET      = 13,//
  D3DSAMP_FORCE_DWORD     = 0x7fffffff 
} D3DSAMPLERSTATETYPE, *LPD3DSAMPLERSTATETYPE;

The specific filtered values are of the enumeration type.D3DTEXTUREFILTERTYPE

typedef enum D3DTEXTUREFILTERTYPE {
  D3DTEXF_NONE              = 0,
  D3DTEXF_POINT             = 1,
  D3DTEXF_LINEAR            = 2,
  D3DTEXF_ANISOTROPIC       = 3,
  D3DTEXF_PYRAMIDALQUAD     = 6,
  D3DTEXF_GAUSSIANQUAD      = 7,
  D3DTEXF_CONVOLUTIONMONO   = 8,
  D3DTEXF_FORCE_DWORD       = 0x7fffffff 
} D3DTEXTUREFILTERTYPE, *LPD3DTEXTUREFILTERTYPE;

 

<1> D3DTEXF_POINT

Last point sampling

Device->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_POINT)

Device->SetSamplerState(0,D3DSAMP_MINFILTER,D3DTEXF_POINT);

<2>D3DTEXF_LINEAR

Linear Texture Filtering

Device->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR)

Device->SetSamplerState(0,D3DSAMP_MINFILTER,D3DTEXF_LINEAR);

 

<3>D3DTEXF_ANISOTROPIC

Before filtering various heterosexual textures, you must set d3dsamp_maxanisotropic. This value determines the level of heterosexual filtering. The larger the value, the better the effect.

Device->SetSamplerState(0,D3DSAMP_MAXANISOTROPIC,4);

Device->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_ANISOTROPIC)

Device->SetSamplerState(0,D3DSAMP_MINFILTER,D3DTEXF_ANISOTROPIC);

 

D3dtexf_none

When usingWhen d3dsamp_mipfilter is used, multi-level progressive texture filtering is prohibited.

<4> progressive multi-level texture

This cannot be used with other texture filtering methods. Use the setsamplerstate function. The second parameter is d3dsamp_mipfilter, and the third parameter is selected.

  D3DTEXF_NONE             
  D3DTEXF_POINT            

  D3DTEXF_LINEAR

D3dtexf_none indicates that multi-level texture filtering is disabled.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.