我在加载纹理到圆面临的问题。 我的圈子与三角形风扇产生。 它提供了一个糟糕的输出。
原始图像:
结果 :
我的代码:
public class MyOpenGLCircle {
private int points=360;
private float vertices[]={0.0f,0.0f,0.0f};
private FloatBuffer vertBuff, textureBuffer;
float texData[] = null;
float theta = 0;
int[] textures = new int[1];
int R=1;
float textCoordArray[] =
{
-R, (float) (R * (Math.sqrt(2) + 1)),
-R, -R,
(float) (R * (Math.sqrt(2) + 1)), -R
};
public MyOpenGLCircle(){
vertices = new float[(points+1)*3];
for(int i=0;i<(points)*3;i+=3)
{
//radius is 1/3
vertices[i]=(float) ( Math.cos(theta))/3;
vertices[i+1]=(float) (Math.sin(theta))/3;
vertices[i+2]=0;
theta += Math.PI / 90;
}
ByteBuffer bBuff=ByteBuffer.allocateDirect(vertices.length*4);
bBuff.order(ByteOrder.nativeOrder());
vertBuff=bBuff.asFloatBuffer();
vertBuff.put(vertices);
vertBuff.position(0);
ByteBuffer bBuff2=ByteBuffer.allocateDirect(textCoordArray.length * 4 * 360);
bBuff2.order(ByteOrder.nativeOrder());
textureBuffer=bBuff2.asFloatBuffer();
textureBuffer.put(textCoordArray);
textureBuffer.position(0);
}
public void draw(GL10 gl){
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertBuff);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); //4
gl.glTexCoordPointer(2, GL10.GL_FLOAT,0, textureBuffer); //5
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, points/2);
}
public void loadBallTexture(GL10 gl, Context context, int resource){
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resource);
gl.glGenTextures(1, textures, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
}
}
请帮我通过这个