Direct3D Use Texture

Source: Internet
Author: User

About using Textures
1 Creating textures
2 Texture addressing Mode
3 Texture Filtering


1 Creating textures
<1> d3dxcreatetexture functions
Creates 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 Pool,
__out Lpdirect3dtexture9 *pptexture
);
<2> D3DXCreateTextureFromFile functions
Creates a texture from a file. supports a variety of formats BMP,. DDS,. Dib,. HDR,. jpg,. PFM,. png,. ppm,. TGA
HRESULT D3DXCreateTextureFromFile (
__in Lpdirect3ddevice9 pdevice,
__in LPCTSTR Psrcfile,
__out Lpdirect3dtexture9 *pptexture
);
<3> D3DXCreateTextureFromFileEx functions
This is a powerful texture creation function that combines the functions of 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 Pool,
__in DWORD Filter,
__in DWORD Mipfilter,
__in D3dcolor ColorKey,
__inout D3dximage_info *psrcinfo,
__out PaletteEntry *ppalette,
__out Lpdirect3dtexture9 *pptexture
);
After the texture creation is complete. To start the texture, use the function SetTexture.
HRESULT SetTexture (
[In] DWORD Sampler,
[In] Idirect3dbasetexture9 *ptexture
);
Reference Sampler: The first texture layer is specified, and the sampler (sample) specifies the state value of the sample, such as filter mode and addressing method.
Parameter ptexture: Specifies the texture pointer to load.


2 How textures are addressed
The way the textures are addressed, there is a common pattern of repeated addressing. Mirrored addressing mode, clip addressing mode, border addressing mode. One mirroring address. The functions that set the addressing method are:
HRESULT Setsamplerstate (
[In] DWORD Sampler,
[In] D3dsamplerstatetype Type,
[In] DWORD Value
);
Sampler: Number of Sample picker
D3dsamplerstatetype: Sample State type
Value: The values of the specified state of the sample picker
The three enumeration variables that can be found about the addressing mode setting from the enumeration type D3dsamplerstatetype are:
D3dsamp_addressu = 1,
D3DSAMP_ADDRESSV = 2,
D3DSAMP_ADDRESSW = 3,
The value of the corresponding value is to be taken from the enumeration variable 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 method


<2> D3DTADDRESS_MIRROR

镜像寻址方式


<3> D3dtaddress_clamp

Clip Addressing method


<4> D3DTADDRESS_BORDER

边框颜色寻址方式


<5>D3dtaddress_mirroronce

This is a combination of mirror addressing and clip addressing, taking the absolute value of the texture coordinates. Addresses are addressed from 0 mirroring and are clamped at the maximum.


is to use 0 as the boundary. Mirror the negative coordinates and the positive coordinates. So is [ -1,1] inside is to do mirror, this range is clamped.

Also assume that the texture coordinates are assumed to have no negative coordinate values. The effect is exactly the same as the clip-addressing mode.

<6> Texture Wrapping

When the system draws a polygon, the texture coordinate values of each pixel in the polygon are determined by interpolating the texture coordinate values of the vertices in sequence. Under normal circumstances, the system will treat the texture as a 2D plane. Interpolation is interpolated by the shortest route between vertices. Then under the 2D plane. It's going to be a line segment.

Texture packaging refers to the texture in the interpolation of the time, is no longer a 2D plane, such as in the U direction of packaging, is the texture around a cylindrical surface, this time the shortest distance between two vertices is the shortest distance on the cylinder surface and no longer the shortest distance on the plane. For example, as seen in:


The minimum distance between A and B is not a line segment between two points on a plane.

When a package is taken in two directions at the same time, it can be imagined as a doughnut form

3 How textures are filtered

Texture filtering is also set by the function Setsamplerstate. Now keep looking.D3DSAMPLERSTATETYPE的枚举类型的中全部的类型。例如以下所看到的:

typedef enum D3DSAMPLERSTATETYPE {
  D3DSAMP_ADDRESSU        = 1,
  D3DSAMP_ADDRESSV        = 2,
  D3DSAMP_ADDRESSW        = 3,
  D3DSAMP_BORDERCOLOR     = 4, //设置纹理边界颜色
  D3DSAMP_MAGFILTER       = 5, //放大滤波
  D3DSAMP_MINFILTER       = 6, //缩小滤波
  D3DSAMP_MIPFILTER       = 7, //MIP滤波
  D3DSAMP_MIPMAPLODBIAS   = 8, //多级纹理映射的偏移值
  D3DSAMP_MAXMIPLEVEL     = 9, //最大纹理过滤级数
  D3DSAMP_MAXANISOTROPY   = 10,//设置各项异性最大值,越大越好
  D3DSAMP_SRGBTEXTURE     = 11,//
  D3DSAMP_ELEMENTINDEX    = 12,//
  D3DSAMP_DMAPOFFSET      = 13,//
} D3DSAMPLERSTATETYPE, *LPD3DSAMPLERSTATETYPE;

The value of the detailed filter from the enumeration typeD3DTEXTUREFILTERTYPE

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

<1> D3DTEXF_POINT

近期点採样

Device->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_POINT)

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

<2>D3DTEXF_LINEAR

线性纹理过滤

Device->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_LINEAR)

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

<3>D3DTEXF_ANISOTROPIC

各项异性纹理过滤。使用之前必须设置D3DSAMP_MAXANISOTROPIC,该值决定各项异性过滤的水平,值越大效果越好

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

Device->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_ANISOTROPIC)

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

D3dtexf_none

Multi-level progressive texture filtering is prohibited when using D3dsamp_mipfilter

<4> multi-level texture progression

This must not be used in conjunction with other texture filtering methods, using the Setsamplerstate function, the second parameter is D3dsamp_mipfilter, the third parameter is selected

  D3DTEXF_LINEAR

当中D3DTEXF_NONE表示禁用多级纹理过滤。




Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Direct3D Use Texture

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.