create Float Buffer from float array - Android java.nio

Android examples for java.nio:FloatBuffer

Description

create Float Buffer from float array

Demo Code


//package com.java2s;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

public class Main {
    public static FloatBuffer createFloatBuffer(float[] triangleCoords) {
        FloatBuffer vertexbuffer;
        ByteBuffer bb = ByteBuffer
                .allocateDirect(triangleCoords.length * 4);// 9*4
        bb.order(ByteOrder.nativeOrder());
        vertexbuffer = bb.asFloatBuffer();
        vertexbuffer.put(triangleCoords);
        vertexbuffer.position(0);//from   w w w. ja  v  a  2 s .  c o  m
        return vertexbuffer;
    }
}

Related Tutorials