In this question the opposite is attempted of the Buffer conversion. Here I have a multi-dimensional array and would like to wrap a buffer around it. I have tried the following without any success:
import java.nio.FloatBuffer;
public class Main
{
private static final int dataSize = 500;
private static final float[][] data = new float[dataSize][dataSize];
public static void main(String[] args) {
for (int i = 0; i < 500; i++) {
for (int j = 0; j <500; j++) {
data[i][j] = i - j; /* to test negative numbers */
}
}
FloatBuffer dataBuf = FloatBuffer.allocate(dataSize * dataSize);
for(int i = 0; i< data.length; ++i){
dataBuf.put(data[i], 0, dataSize);
}
}
}
The example compiles just fine, Should that sufficiently hold the contents of the array? Is this usage sufficient to handle openGL Textures inside LibGDX?
IntBuffer numberTexture = IntBuffer.allocate(1);
dataBuf.position(0);
Gdx.gl30.glGenTextures(1, numberTexture);
Gdx.gl30.glBindTexture(GL30.GL_TEXTURE_2D, numberTexture.get());
Gdx.gl30.glTexParameteri(GL30.GL_TEXTURE_2D, GL30.GL_TEXTURE_MIN_FILTER, GL30.GL_NEAREST);
Gdx.gl30.glTexParameteri(GL30.GL_TEXTURE_2D, GL30.GL_TEXTURE_MAG_FILTER, GL30.GL_LINEAR);
Gdx.gl30.glTexImage2D(
GL30.GL_TEXTURE_2D, 0, GL30.GL_RGBA32F,
width, height, 0, GL30.GL_RGBA, GL30.GL_FLOAT, dataBuf
);
Gdx.gl30.glGenerateMipmap(GL30.GL_TEXTURE_2D);