Napravim aplikaciju, sve podesim. Napravim klasu triangle za crtanje trougla, ali imeni trebaju kvadrati na koje cu ucitavati texturu iz png fajlova (neso kao sprite), a to ne radi, opet crta trougao.
Evo ga kod, ne znam gde gresim:
package some.some.projectname;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import javax.microedition.khronos.opengles.GL10;
public class Rectangle
{
private FloatBuffer vertexBuffer = null;
private ShortBuffer indicesBuffer = null;
private FloatBuffer colorBuffer = null;
private int numOfIndices = 0;
private float vertexList[] =
{
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f
};
private short indexList[] =
{
0, 1, 2, 0, 2, 3
};
private float colorList[] =
{
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f
};
public Rectangle()
{
// Set vertex buffer
ByteBuffer vbb = ByteBuffer.allocateDirect(vertexList.length * 4);
vbb.order(ByteOrder.nativeOrder());
vertexBuffer = vbb.asFloatBuffer();
vertexBuffer.put(vertexList);
vertexBuffer.position(0);
// Set indices buffer
numOfIndices = indexList.length;
ByteBuffer tbibb = ByteBuffer.allocateDirect(numOfIndices * 2);
tbibb.order(ByteOrder.nativeOrder());
indicesBuffer = tbibb.asShortBuffer();
indicesBuffer.put(indexList);
indicesBuffer.position(0);
// Set color buffer
ByteBuffer cbb = ByteBuffer.allocateDirect(colorList.length * 4);
cbb.order(ByteOrder.nativeOrder());
colorBuffer = cbb.asFloatBuffer();
colorBuffer.put(colorList);
colorBuffer.position(0);
}
public void draw(GL10 gl)
{
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glColorPointer(4, GL10.GL_FLOAT, 0, this.colorBuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, this.vertexBuffer);
// Draw the Rectangle
gl.glDrawElements(GL10.GL_TRIANGLES, this.numOfIndices,
GL10.GL_UNSIGNED_SHORT, this.indicesBuffer);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
}
}
Hvala unapred na pomoci.
[Ovu poruku je menjao nekicneko99 dana 28.03.2015. u 00:08 GMT+1]
[Ovu poruku je menjao nekicneko99 dana 28.03.2015. u 00:08 GMT+1]