-
Hi, data class UV(val x: Float, val y: Float)
fun ByteBuffer.putUv(v: UV): ByteBuffer {
putFloat(v.x)
putFloat(v.y)
return this
}
val vertexUv = ByteBuffer.allocate(6*2*8)
// It is important to respect the native byte order
//Order in my Indice buffer was 0,1,2,0,2,3
.order(ByteOrder.nativeOrder())
.putUv(UV(0f,0f))
.putUv(UV(0f,1f))
.putUv(UV(1f,1f))
.putUv(UV(0f,0f))
.putUv(UV(1f,1f))
.putUv(UV(1f,0f))
// Make sure the cursor is pointing in the right place in the byte buffer
.flip()
// Declare the layout of our mesh
vertexBuffer = VertexBuffer.Builder()
.bufferCount(2)
.vertexCount(6)
// Because we interleave position and color data we must specify offset and stride
// We could use de-interleaved data by declaring two buffers and giving each
// attribute a different buffer index
.attribute(
VertexBuffer.VertexAttribute.POSITION,
0,
VertexBuffer.AttributeType.FLOAT3,
0,
12
)
.attribute(
VertexBuffer.VertexAttribute.COLOR,
1,
VertexBuffer.AttributeType.UBYTE4,
0,
4
)
.attribute(VertexBuffer.VertexAttribute.UV0, 2, VertexBuffer.AttributeType.FLOAT2, 0, 16)
.build(mEngine)
vertexBuffer.setBufferAt(mEngine, 0, vertexData)
vertexBuffer.setBufferAt(mEngine, 1, vertexColor)
vertexBuffer.setBufferAt(mEngine, 2, vertextUv)
|
Beta Was this translation helpful? Give feedback.
Answered by
romainguy
Jun 22, 2021
Replies: 1 comment 1 reply
-
You declared a vertex buffers with 3 sub-buffers ( |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
inveders
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You declared a vertex buffers with 3 sub-buffers (
.bufferCount(2)
) but you are trying to use 3.