It’s one thing to copy and paste the source code from examples, but I’m looking some answers to why the examples are the way they are.
One question I can’t answer is why the ByteBuffer for a triangle requires four bytes per coordinate.
In the example presented by Google a ByteBuffer is instantiated with four bytes per triangle coordinate.
// initialize vertex byte buffer for shape coordinates
// (number of coordinate values * 4 bytes per float)
ByteBuffer bb = ByteBuffer.allocateDirect(triangleCoords.length * 4);
// use the device hardware's native byte order
bb.order(ByteOrder.nativeOrder());
- Why is it four bytes per coordinate rather than 2 or 8?
- What is the purpose of the nativeOrder() call?
A float is represented by 32 bits, which equals four bytes.
The call to native order rearranges the bytes in the buffer to whatever the native system’s order is, big endian, little endian, etc.