For allocating ByteBuffer
memory for vertices, colors, lighting, etc everytime I need to do the following.
ByteBuffer bBuff=ByteBuffer.allocateDirect(vertices.length*4);
bBuff.order(ByteOrder.nativeOrder());
vertBuff=bBuff.asFloatBuffer();
vertBuff.put(vertices);
vertBuff.position(0);
ByteBuffer bColorBuff=ByteBuffer.allocateDirect(colorVals.length*4);
bColorBuff.order(ByteOrder.nativeOrder());
colorBuff=bColorBuff.asFloatBuffer();
colorBuff.put(colorVals);
colorBuff.position(0);
.......
So I tried making a helper function something like this.
private void fBFromFA(float array[], int size, FloatBuffer theBuff){
ByteBuffer bBuff=ByteBuffer.allocateDirect(array.length*size);
bBuff.order(ByteOrder.nativeOrder());
theBuff=bBuff.asFloatBuffer();
theBuff.put(array);
theBuff.position(0);
}
But it didnt work. it gave me a java.lang.NullPointerException
pointing the source at
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertBuff);
inside the void draw(GL10 gl)
method.