1

I tried to create a GLfloat buffer array with

GLfloat mat_diffuse[] = { .2f, .2f, .6f, 1f };

But java can not find class GLfloat and when I try to use a normal float array I get an error with this line

gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, mat_diffuse);

Error reads incompatible types: float[] cannot be converted to FloatBuffer

Is there a special way to create a GLfloat or is there something that I need to import from openGL to make this work?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Jake
  • 617
  • 1
  • 6
  • 21
  • Is this LWJGL? You should probably ask on their forum. I think they use `float` instead of the GL version in Java code. – markspace Mar 01 '18 at 01:00

1 Answers1

1

So the solution I found for this was to use a float array

float mat_diffuse[] = { .2f, .2f, .6f, 1f };

and then changed

gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, mat_diffuse);

to

gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, mat_diffuse, 0);

not sure why it worked, but it did.

Jake
  • 617
  • 1
  • 6
  • 21
  • A [`FloatBuffer`](https://docs.oracle.com/javase/9/docs/api/java/nio/FloatBuffer.html) is a special NIO buffer used for moving memory around quickly (ideally by not moving it, but rather allocating it in the desired areas) and accessing the values with the correct byte-endianness. You can construct a `FloatBuffer` from a `float[]`, but they are different animals. – AJNeufeld Mar 01 '18 at 02:54
  • UNfortunately it doesn't work always as intended https://stackoverflow.com/questions/67298120/loading-generated-texture-data-is-inconclusive-in-libgdx-lwjgl – Dávid Tóth Apr 28 '21 at 11:07