Presentation is loading. Please wait.

Presentation is loading. Please wait.

GAM666 – Introduction To Game Programming ● Textures are simply 2D images which are spread over the triangles of a 3D shape ● Each vertex has texture coordinates.

Similar presentations


Presentation on theme: "GAM666 – Introduction To Game Programming ● Textures are simply 2D images which are spread over the triangles of a 3D shape ● Each vertex has texture coordinates."— Presentation transcript:

1 GAM666 – Introduction To Game Programming ● Textures are simply 2D images which are spread over the triangles of a 3D shape ● Each vertex has texture coordinates associated with it, giving 2D coordinates of the point on the image to be pinned to that vertex ● Regardless of the size of the image, (0,0) is the top left corner and (1,1) is the bottom right ● Typically, texture coordinates are called (u,v) so they don't get confused with the x, y and z of the 3D world itself, and the pixels of the image are called texels so they don't get confused with pixels on the screen Texturing 3D Shapes

2 GAM666 – Introduction To Game Programming ● If coordinates outside the range 0.0 to 1.0 are given, most hardware is capable of wrapping the texture around ● Many video cards have restrictions on the size of the images involved ● The most typical limitation is that each dimension must be a power of 2, e.g. 128X512 ● For this reason, texture artists almost always create textures that have dimensions which are a power of 2, and often are square Texturing 3D Shapes

3 GAM666 – Introduction To Game Programming To include a set of texture coordinates in the vertex structure, ● in the SetFVF call specify the bits: ● D3DFVF_TEX1, to say there will be one set of texture coordinates, and ● D3DFVF_TEXCOORDSIZE2(0) to say that the first (0) set of texture coordinates has 2 elements per pixel ● Include two floats (for the u and v coordinates) in the appropriate place in the vertex structure ● Other settings allow for multitexturing and more sophisticated texturing operations Texturing 3D Shapes

4 GAM666 – Introduction To Game Programming ● LPDIRECT3DTEXTURE9 points to a texture ● The function D3DXCreateTextureFromFile() will load a texture from file, and understands many popular file formats ● To rasterize a 3D shape using the texture, call the Direct3D device function SetTexture() before drawing the primitive (Call SetTexture() with a null pointer to stop texturing) ● The color for each pixel is a combination of the material, lighting and texel colours Texturing 3D Shapes

5 GAM666 – Introduction To Game Programming The Direct3D device function SetSamplerState() lets you control various aspects of how the texture is applied. For example, ● D3DSAMP_ADDRESSU and D3DSAMP_ADDRESSV let you change how texture wrapping is done along each texture dimension ● D3DSAMP_MINFILTER and D3DSAMP_MAGFILTER let you change how the texture is shrunk and magnified Texturing 3D Shapes

6 GAM666 – Introduction To Game Programming ● The default minification and magnification filters are D3DTEXF_POINT, which uses the nearest texel to determine the colour of a pixel, but can look blocky (point filtering) ● D3DTEXF_LINEAR averages the nearest 2x2 block of texels, and will look smoother, though also fuzzy (bilinear filtering) ● D3DTEXF_ANISOTROPIC is similar, but also compensates for the angle of the texture relative to the screen, at a performance penalty (anisotropic filtering) Texturing 3D Shapes


Download ppt "GAM666 – Introduction To Game Programming ● Textures are simply 2D images which are spread over the triangles of a 3D shape ● Each vertex has texture coordinates."

Similar presentations


Ads by Google