LWJGL Forum

Programming => OpenGL => Topic started by: Electronics Boy on April 16, 2021, 05:10:43

Title: Java FloatBuffer in C++ (i know that is a dumb question)
Post by: Electronics Boy on April 16, 2021, 05:10:43
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;
}
Title: Re: Java FloatBuffer in C++ (i know that is a dumb question)
Post by: Electronics Boy on April 16, 2021, 09:59:10
Can someone replay?
Title: Re: Java FloatBuffer in C++ (i know that is a dumb question)
Post by: KaiHH on April 16, 2021, 11:49:19
The C++ equivalent of:

float[] data = {1.0f, 2.0f, 3.0f};
FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
buffer.put(data);
buffer.flip();


is (drumm-roll):

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
Title: Re: Java FloatBuffer in C++ (i know that is a dumb question)
Post by: Electronics Boy 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  :)
Title: Re: Java FloatBuffer in C++ (i know that is a dumb question)
Post by: KaiHH 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:

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.
Title: Re: Java FloatBuffer in C++ (i know that is a dumb question)
Post by: Electronics Boy 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)