Java tutorial
//package com.java2s; import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { public static Buffer fillBuffer(float[] array) { // Convert to floats because OpenGL doesnt work on doubles, and manually // casting each input value would take too much time. ByteBuffer bb = ByteBuffer.allocateDirect(4 * array.length); // each // float // takes 4 // bytes bb.order(ByteOrder.LITTLE_ENDIAN); for (float d : array) bb.putFloat(d); bb.rewind(); return bb; } public static Buffer fillBuffer(double[] array) { // Convert to floats because OpenGL doesnt work on doubles, and manually // casting each input value would take too much time. ByteBuffer bb = ByteBuffer.allocateDirect(4 * array.length); // each // float // takes 4 // bytes bb.order(ByteOrder.LITTLE_ENDIAN); for (double d : array) bb.putFloat((float) d); bb.rewind(); return bb; } }