1

我正在尝试将纹理附加到立方体。目前,纹理正在拉伸。

我知道这是我的纹理坐标的问题,但我不知道是什么。

对于所有顶点位置(x,y,z),我制作了纹理坐标(x,y)。

float [] texCoords = new float [2*allPoints.size()];
int index= 0;
for(int i = 0; index< allPoints.size()-1; i=i+2){
           texCoords[i] = (float)allPoints.get(index).getX();
           texCoords[i+1] = (float)allPoints.get(index).getY();
           index++;
}

glTex 参数:

gl2.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,GL.GL_NEAREST);
gl2.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,GL.GL_NEAREST);
gl2.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_WRAP_S,GL.GL_REPEAT);
gl2.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_WRAP_T,GL.GL_REPEAT);

电流输出:

在此处输入图像描述

4

1 回答 1

0

Texture coordinates in OpenGL are scaled 0-1, if you go past that boundary, according to your parameter of GL_REPEAT for GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T.

I don't know about the organization of your allPoints list, but for a cube, you're going to have multiple unique texture coordinates per vertex, so you're going to need to duplicate your vertices. If you draw it out by hand or think about it, a texture coordinate of 1 on a vertex also has to be 0 for an adjacent face.

Each face should have the following texture coordinates:

(0, 1)--(1, 1)
|            |
|            |
|            |
(0, 0)--(1, 0)

Now think about the faces on a cube, the (1, 1) point is the (0, 1) point of the adjacent face. Duplicate your vertices to fix that issue.

于 2012-11-05T02:43:08.497 回答