我正在尝试绘制带有纹理的圆形,它应该在所有顶点上拉伸。
问题是我得到的结果如下:
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);
答案 0 :(得分:-1)
所以找到解决方案(:1,非常非常重要的事情,我错过了/或openGL错过了。
纹理坐标只能在0到1的范围内。
所以这是技巧/解决方案:
//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;
}
这是res:
http://s2.postimg.org/tno4jr4y1/image.png
别忘了忘记翻转纹理顶点(: