读书人

再问下纹理坐标映射的小疑点。

发布时间: 2012-02-10 21:27:42 作者: rapoo

再问下纹理坐标映射的小问题。。

我要映射的是第2个按钮,
核心代码:

C/C++ code
float x = 0, y = 0;float width = 64, height = 96;// 纹理图片中要映射的那部分纹理坐标// 这个纹理坐标我用PS精准的检验了下,没问题float left    = 0;float top    = 24;float right    = 59;float bottom    = 43;CustomVertex objData[] ={    {             x,               y, 0, 1, col,  left/width,    top/height },    { right-left+x,               y, 0, 1, col,  right/width,    top/height },    { right-left+x, bottom-top+y, 0, 1, col,  right/width,    bottom/height },    { right-left+x, bottom-top+y, 0, 1, col,  right /width,    bottom/height },    {             x, bottom-top+y, 0, 1, col,  left/width,    bottom/height },    {             x,               y, 0, 1, col,  left/width,    top/height }};    // 移半个像    for (int i=0; i<6; i++)    {        objData[i].tu += (0.5/64.0f);        objData[i].tv += (0.5/96.0f);    }


现在这个写法,我已经很明白透彻了。但是为什么结果却出乎我的意料,宽高又少映射了一个像素??
代码有问题???

[解决办法]
对阿, right和bottom都+个1阿,
[解决办法]
这不怪你,要怪就怪D3D
[解决办法]
纹理的浮点范围是 0~1, 那么比如256个像素,共有0/256,1/256,...256/256共257种取法。

读书人网 >网络游戏

热点推荐