Panda3D Manual: Texture Wrap ModesAs described earlier, the (u, v) texture coordinates that you assign to your vertices are what determines how the texture fits on your geometry. Often, you will use texture coordinates that always fall within the range [0, 1], which is the complete range of the pixels of your texture image. However, it is also legal to use texture coordinates that go outside this range; you can have negative values, for instance, or numbers higher than 1. So if the texture image is only defined over the range [0, 1], what does the texture look like outside this range? You can specify this with the texture wrap mode. texture->set_wrap_u(wrap_mode); The wrap_mode parameter is specified separately for the u and
v directions (there is also a
The default wrap mode is Consider the following simple texture image:
We will apply this texture in the center of a large polygon whose texture coordinates range considerably farther than [0, 1] in both directions. WM_repeattexture->set_wrap_u(Texture::WM_repeat);
WM_clamptexture->set_wrap_u(Texture::WM_clamp);
WM_border_colortexture->set_wrap_u(Texture::WM_border_color);
The above blue color was chosen for illustration purposes; you can use any color you like for the border color. Normally, you would use the background color of the texture as the border color, like this: texture->set_wrap_u(Texture::WM_border_color);
Some very old graphics drivers don't support
WM_mirrortexture->set_wrap_u(Texture::WM_mirror);
Many older graphics drivers do not support WM_mirror_oncetexture->set_wrap_u(Texture::WM_mirror_once);
Few graphics drivers support Setting different wrap modesIt is possible to set different wrap modes in the u and v directions: texture->set_wrap_u(Texture::WM_repeat);
One caution about a common wrap mode errorWhen you apply a texture that is intended to exactly fill a polygon--that is, the texture coordinates range from 0 to 1, but no further--you should usually set its wrap mode to clamp. This is because if you let it keep the default value of repeat, the color may bleed in from the opposite edge, producing a thin line along the edge of your polygon, like this:
This is a particularly common error with a texture that is painted as
an alpha cutout, where there is an image with a fully transparent
background: you will often see an thin, barely-visible edge floating
along the top (for instance) of the polygon. This edge is actually
the bottom edge of the texture bleeding onto the top, because the
designer specified © Carnegie Mellon University 2010 |