Hello Guest

Java FloatBuffer in C++ (i know that is a dumb question)

  • 5 Replies
  • 9314 Views
*

Offline Electronics Boy

  • *
  • 11
  • I'm a prgrammer :)
    • Electronics Boy
ok, so i used LWJGL3 in Java, but now, i want want to code in C++ using GLFW, and for rendering, i want to use VAOs and VBOs as it is the new rendering way, but, i dony know how to do it, can home one help me? plz?


Code (Java(i Need it in C++)):
private FloatBuffer storeDataInFloatBuffer(float[] data) {
   FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
   buffer.put(data);
   buffer.flip();
   return buffer;
}

*

Offline Electronics Boy

  • *
  • 11
  • I'm a prgrammer :)
    • Electronics Boy
Re: Java FloatBuffer in C++ (i know that is a dumb question)
« Reply #1 on: April 16, 2021, 09:59:10 »
Can someone replay?

*

Offline KaiHH

  • ****
  • 334
Re: Java FloatBuffer in C++ (i know that is a dumb question)
« Reply #2 on: April 16, 2021, 11:49:19 »
The C++ equivalent of:
Code: [Select]
float[] data = {1.0f, 2.0f, 3.0f};
FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
buffer.put(data);
buffer.flip();

is (drumm-roll):
Code: [Select]
float data[] = {1.0f, 2.0f, 3.0f};

You are basically asking "Please, teach me C++".
You should look elsewhere.

If you use OpenGL and search for a good OpenGL tutorial using C++ and GLFW, then: https://learnopengl.com/
The "Hello Triangle" section also has the code for uploading a float array into an OpenGL buffer object: https://learnopengl.com/Getting-started/Hello-Triangle
« Last Edit: April 16, 2021, 11:52:52 by KaiHH »

*

Offline Electronics Boy

  • *
  • 11
  • I'm a prgrammer :)
    • Electronics Boy
Re: Java FloatBuffer in C++ (i know that is a dumb question)
« Reply #3 on: April 16, 2021, 11:52:47 »
Oh ok, thx, i actually know C++, but, i did not know that you can use a float[] isted of a FloatBuffer, thx btw  :)

*

Offline KaiHH

  • ****
  • 334
Re: Java FloatBuffer in C++ (i know that is a dumb question)
« Reply #4 on: April 16, 2021, 11:58:00 »
If you knew C++, then you'd also know that there is no such thing as a FloatBuffer.
And you'd also know the C signature of e.g. glBufferData:
Code: [Select]
void glBufferData( GLenum target,
  GLsizeiptr size,
  const void * data,
  GLenum usage);
and know that you are supposed to pass your data directly as the (const void*) argument.

*

Offline Electronics Boy

  • *
  • 11
  • I'm a prgrammer :)
    • Electronics Boy
Re: Java FloatBuffer in C++ (i know that is a dumb question)
« Reply #5 on: May 03, 2021, 06:32:31 »
Hey,

I'm actually new to OpenGL in C/C++. And i know that there is nothing as a FloatBuffer, so i did not know how OpenGL will take it, os i posted it here, BTW sorry for the late responce, i did not see that you posted a replay here.

Regrads,
Electronics Boy(Nikunj)