I have a problem I haven’t been able to figure out, and can’t seem to find a solution with google either.
In the first method I retrieve some floating point values from a FloatBuffer and place them into an array, which I pass to the method which it then places back into a direct byte buffer with the native byte ordering.
This works but seems horribly inefficient so after looking at the JCanyon demo, and a little bit of coding, I create method two.
Method two takes the float buffer that I would other wise be reading the values from and passes it straight to glTexImage2D, but for some reason unknown to me this creates a garbled texture. It seems like it should work, but there’s definitely something I’m missing.
//depending on available extensions
//float_texture_format = GL.GL_LUMINANCE_FLOAT16_ATI || GL.GL_LUMINANCE16F_ARB
public void method_1(int[] texture_id, float[] texture_data, int id_index, int dimx, int dimy, GLDrawable drawable)
{
ByteBuffer b = ByteBuffer.allocateDirect(texture_data.length * 4);
b.order(ByteOrder.nativeOrder());
FloatBuffer fbTex = b.asFloatBuffer();
fbTex.put(texture_data);
gl.glBindTexture(GL.GL_TEXTURE_2D, texture_id[id_index]);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, float_texture_format, dimx, dimy, 0, GL.GL_LUMINANCE, GL.GL_FLOAT, fbTex);
}
that works…
…but this doesn’t work
//depending on available extensions
//float_texture_format = GL.GL_LUMINANCE_FLOAT16_ATI || GL.GL_LUMINANCE16F_ARB
public void method_2(int[] texture_id, FloatBuffer texture_data, int id_index, int dimx, int dimy, GLDrawable drawable)
{
GL gl = drawable.getGL();
gl.glBindTexture(GL.GL_TEXTURE_2D, texture_id[id_index]);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, float_texture_format, dimx, dimy, 0, GL.GL_LUMINANCE, GL.GL_FLOAT, texture_data);
}
If anyone could please help me out I’d really appreciate it.
Thank you in advance.