android opengl es texture mapping into polygons
- by kamil
I wrote opengl es code for android to map textures on a square but i want to draw texture on polygons. When user moved the image, texture will be mapped on polygons have more vertexes. I tried the arrays combination below for pentagon but i could not find the correct triangle combination in indices array.
public float vertices[] = {
// -1.0f, 1.0f, 0.0f, //Top Left
// -1.0f, -1.0f, 0.0f, //Bottom Left
// 1.0f, -1.0f, 0.0f, //Bottom Right
// 1.0f, 1.0f, 0.0f //Top Right
-1.0f, 1.0f, 0.0f, //Top Left
-1.0f, -1.0f, 0.0f, //Bottom Left
1.0f, -1.0f, 0.0f, //Bottom Right
1.0f, 1.0f, 0.0f, //Top Right
0.4f, 1.4f, 0.0f
};
/** Our texture pointer */
private int[] textures = new int[1];
/** The initial texture coordinates (u, v) */
private float texture[] = {
//Mapping coordinates for the vertices
// 1.0f, 0.0f,
// 1.0f, 1.0f,
// 0.0f, 1.0f,
// 0.0f, 0.0f,
// 0.0f, 1.0f,
// 0.0f, 0.0f,
// 1.0f, 0.0f,
// 1.0f, 1.0f,
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f,
1.0f, 0.7f,
};
/** The initial indices definition */
private byte indices[] = {
//2 triangles
// 0,1,2, 2,3,0,
0,1,2, 2,3,4, 3,4,0, //triangles for five vertexes
};
i draw with the code below
gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer);