android opengl 纹理贴图顶点索引和纹理坐标的关系,有几个面贴不上图
最近在做一个魔方(27个立方体),想着要给贴图,突然发现绘制魔方时依赖的顶点索引和纹理的坐标有很大的关系,
参考了neheopengl的 android版的课程6;可是还是不行,下面我给我 我的顶点坐标;
//bottom
07-21 20:38:55.835: I/System.out(22790): putIndices Triangles index:==0,4,1
07-21 20:38:55.835: I/System.out(22790): putIndices Triangles index:==4,5,1
//front
07-21 20:38:55.835: I/System.out(22790): putIndices Triangles index:==4,6,5
07-21 20:38:55.835: I/System.out(22790): putIndices Triangles index:==6,7,5
//left
07-21 20:38:55.835: I/System.out(22790): putIndices Triangles index:==0,2,4
07-21 20:38:55.835: I/System.out(22790): putIndices Triangles index:==2,6,4
//right
07-21 20:38:55.835: I/System.out(22790): putIndices Triangles index:==5,7,1
07-21 20:38:55.835: I/System.out(22790): putIndices Triangles index:==7,3,1
//back
07-21 20:38:55.835: I/System.out(22790): putIndices Triangles index:==1,3,0
07-21 20:38:55.835: I/System.out(22790): putIndices Triangles index:==3,2,0
//top
07-21 20:38:55.835: I/System.out(22790): putIndices Triangles index:==6,2,7
07-21 20:38:55.835: I/System.out(22790): putIndices Triangles index:==2,3,7
下面给出 顶点的大致图形: 上半面的4个顶点
2 /----------/3
/ /
6/-------- -/7
下半面的4个顶点:
0 /----------/1
/ /
4/-------- -/5
4,5 ,6,7的面是前面 front;0,1,2,3的面是后面
再给大家看 纹理坐标:
private static float[][] texCoords = {
//bottom
{0,1, 0,0,1,1,1,0},//不是我不想用下面注释的那个数组,一旦用了别的面就花了
/*{0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,},*/
// front
{0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,},
// left
{0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,},
// right
{0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,},
// back
{0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,},
//top
{0,1, 0,0,1,1,1,0}//不是我不想用下面注释的那个数组,一旦用了别的面就花了
/*{0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,}*/
};
这个数组在画的时候也是按照从bottom 到front 和顶点索引一样的面的顺序;所以 此处不会有索引的数组和我定义的面的顺序不对的情况
但是最后顶面(top)和底面(bottom)都贴不上图:
就像这样:
我觉得我绘制的也没有问题:
public void draw(GL10 gl,int[] texture){
mIndexBuffer.position(0);
mVertexBuffer.position(0);
mColorBuffer.position(0);
mTextureBuffer.position(0);
gl.glFrontFace(GL10.GL_CW);
gl.glShadeModel(GL10.GL_FLAT);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer);
for(int i = 0 ;i < 27 ;i++){
for(int j =0 ;j <6 ;j++){
gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[j]);
GLCubeFace face = mWorldCubeList.get(i).mCubeFaceList.get(j);
face.mIndexBuffer.position(0);
gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_SHORT, face.mIndexBuffer);
// mWorldCubeList.get(i).mCubeFaceList.get(j).draw(gl, texture[j]);
}
}
//gl.glDrawElements(GL10.GL_TRIANGLES, mIndexCount, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
}
唉...我查了好多天了 总是没办法让6个面都有贴图...
望有大神能够帮上忙
Android OpenGL 纹理贴图
补充:移动开发 , Android