0
votes

i'm working on OpenGL ES 2.0 shaders on android...

i have a float array with position of vertices along with other attributes of vertices. position and other attributes may change over time.

how can i pass this modified array to glVertexAttribPointer, so that i can draw the scene with updated values

when i tried to pass it, i got

The method glVertexAttribPointer(int, int, int, boolean, int, Buffer) in the type GLES20 is not applicable for the arguments (int, int, int, boolean, int, float[])

2
The error is telling you that you need to take that array of float vertexes you have and somehow convert it into a buffer object. I'm no openGL expert, so thats as far as I can answer this.Eric
thanx Eric, but i cant modify the buffer... so want to use arrays inteadsravan

2 Answers

2
votes
FloatBuffer yourFloatBuffer;
float[] yourFloatArray;    

FloatBuffer byteBuf = ByteBuffer.allocateDirect(yourFloatArray.length * 4);
    byteBuf.order(ByteOrder.nativeOrder());
    yourFloatBuffer = byteBuf.asFloatBuffer();
    yourFloatBuffer.put(yourFloatArray);
    yourFloatBuffer.position(0);

This should work.

0
votes

Is it java.nio.Buffer? Because it seems you need

java.nio.FloatBuffer

and call floatBuffer.array()

to get the float[] array out of it.

But, obviously it is final in FloatBuffer.java:

final float[] hb;   

So it seems that you'll need to... maybe extend FloatBuffer and make the array non-final.