home · software · code · tutorials · site map

3664
Congressman warns of current GA- Russia conflict in 2002!!!
Ron Paul in an interview with Jim Lehrer says in 2002 interview that by the US adopting a preemptive first Strike Doctrine would eventually lead to Russia invading GA
3552
Girls Get the Anime Look with Extra-Wide Contact Lenses
Girls in Japanese comics, cartoon videos or anime share a common look - big eyes that, by making the rest of the face look small, add the cuteness and sex appeal prized by many Japanese men. Since no amount of cosmetic surgery will make actual human eyes larger, some girls are trying another way to up their cute quotient: extra-wide contact lenses!
1262
'Everyone Will Remember Me as Some Sort of Monster'
A troubled teenager. An assault rifle. Eight slain in a mall. It was national news for a few days. Then it was forgotten.
822
Repurpose Your Nintendo as a Lunchbox (PICS)
I had a broken NES, a rotary tool, two small hinges, some glue and Alpha Flight's Sasquatch. What I ended up with was a lunchbox that gets all kinds of funny looks.
3104
Once You Look, You Can't Look Away (Pic)



Feb
2

GM6 D3D from the Ground Up - Chapter 7

2007 @ 05:41 PM

Chapter 7 - Texture Mapping

What is a Texture?

A texture is simply any image. You apply it to a 3D polygon for a realistic rendering, much more so than basic lighting and colors can depict.

Loading Textures

The best way to organize textures in your Game Maker project is to create a Group under the Backgrounds resource tree named 'Textures.' From there, you can add each individual texture you will use in your game.
There are a few restrictions to the sizes of textures. The dimensions MUST be powers of 2. For example, 64x32, 128x64, etc.

Mapping Textures to Polygons

Now that you have your textures inside Game Maker, we must tell it how to apply the textures to our objects. We do this by specifying a texture coordinate for each vertex of the triangle. This texture coordinate, or texel is a value from 0.0 to 1.0. Texels are in two dimensions - x and y. The x texels go from 0 to 1 from left to right, while the y texels go from 0 to 1 from top to bottom.
texels
To allow a primitive to have a texture, we have to create it with that accessibility. So we now use d3d_primitive_begin_texture(kind, texture_id). kind is the same argument that was used in d3d_primitive_begin. texture_id is the ID of the texture you want to use for this primitive. To get this ID, you can use the function background_get_texture(back) where back is the name of the texture you want.
Now, when specifying a vertex for our textured primitive, we'll call d3d_vertex_texture(x,y,z,xtex,ytex) where xtex and ytex are the x and y texels of our texture map. Please note that you can also use d3d_vertex_normal_texture_color(x,y,z,nx,ny,nz,xtex,ytex,color,alpha) if you want to include all of those characteristics for that vertex.

Texture Filtering

When the texture is mapped onto the polygon, there is a loss of quality as it is stretched and shrunk to fit the vertices. To combat this, filtering is used. By default, Game Maker uses nearest pixel filtering. Nearest-pixel filtering is the simplest and fastest filtering method. However, when the texture is stretched to a large size, it is plagued by large, block pixels.
Linear filtering requires more processing power but it results in a large improvement in quality. Rather than taking a single pixel next to the texel, it averages the surrounding pixels. This results in a fuzzy look when stretched to large sizes. This fuzziness is a better looking artifact than the pixelated look of nearest-pixel filtering, however. You can set this filtering mode by calling texture_set_interpolation(true). You can go back to nearest-pixel filtering with a call to texture_set_interpolation(false).

Texturing Built-In Primitives

Each of the built in basic shapes has three arguments that I have yet to explain: texid, hrepeat, and vrepeat. texid is the ID of the texture, just as it was earlier explained. hrepeat is the amount of times the texture is repeated horizontally along each face. vrepeat is the amount of times the texture is repeated vertically along each face.

<< Previous Chapter      Next Chapter >>


 Del.icio.us  Digg  Furl  Google  Reddit  Slashdot


This article hasn't been commented yet.

CommentsWrite a comment

:

:

:

Blogtastic RSS FEED

Linktastic


TysonC's Profile Page