Android OpenGL 圆形纹理加倍

Android OpenGL Circle Texture Doubled

我正在尝试绘制带有纹理的圆,应该在所有顶点上进行拉伸。

问题是我得到的结果是这样的:

http://s14.postimg.org/3wyb74469/image.png

我尝试按需要绘制三角形扇形,第一个坐标为 0,0,0 并根据需要休息:

http://escience.anu.edu.au/lecture/cg/surfaceModeling/image/surfaceModeling015.png

这里也有同样的问题,我无法从中得到我的问题的答案:

OpenGL ES, add texture to circle

加载圆顶点坐标函数:

private final int mVerticesDataSize = 3;    
private final int mNumberOfVertices = 180;
private final int mBytesPerFloat = 4;   
private float[] vertices;
private  FloatBuffer mVerticesBuff;

public void loadCircleVerticesBuff(Context mActivityContext){

       mVerticesBuff = ByteBuffer.allocateDirect(mNumberOfVertices * mVerticesDataSize * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();                            
       vertices = new float[mNumberOfVertices * mVerticesDataSize];
       float theta = 0;


       for (int i = 0; i < (mNumberOfVertices * mVerticesDataSize); i += 3) {   
       vertices[i] = (float) (((float) 5*Math.cos(theta)));
       vertices[i + 1] = (float) ((float) 5*Math.sin(theta));
       vertices[i + 2] = 0;
       theta += Math.PI / 90;
       }

       mVerticesBuff.put(vertices);
       mVerticesBuff.position(0);          
}

加载圆纹理坐标函数:

private final int mTextureCoordinateDataSize = 3;
public void loadCircleTextureBuff(){
    mCircleTextureCoordinatesBuff = ByteBuffer.allocateDirect(mNumberOfVertices * mTextureCoordinateDataSize * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();                          
    mCircleTextureCoordinatesBuff.put(vertices);
    mCircleTextureCoordinatesBuff.position(0);
}

用于绘制的opengl函数为:

 GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, mNumberOfVertices);  

所以找到了解决方案(:我错过了 1 件非常非常重要的事情/或者 openGL 错过了。

纹理坐标只能在0到1之间。

所以这里是 trick/solution :

//Build vertices :
vertices[i] = (float) (((float) raduis*Math.cos(theta)))+raduis;
vertices[i + 1] = (float) ((float) raduis*Math.sin(theta))+raduis;

// Build texture :
 for (int i = 0; i < (mNumberOfVertices * mVerticesDataSize); i += 3) {   
           vertices[i] = (vertices[i])/(raduis*2);
           vertices[i + 1] = (vertices[i+1])/(raduis*2);
           vertices[i + 2] = 0;
  }

这是资源:

http://s2.postimg.org/tno4jr4y1/image.png

不要忘记翻转纹理顶点,因为我忘记了(: