android opengl es texture mapping into polygons
Posted
by
kamil
on Stack Overflow
See other posts from Stack Overflow
or by kamil
Published on 2010-12-30T12:14:21Z
Indexed on
2010/12/30
14:54 UTC
Read the original article
Hit count: 231
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);
© Stack Overflow or respective owner