Hello Guest

Data type of OpenGL

  • 4 Replies
  • 4873 Views
Data type of OpenGL
« on: June 13, 2011, 18:39:34 »
How the data type of OpenGL is handled in LWJGL?

like, in the following C++ code
glVertexPointer(3, GL_FLOAT, 0, vertices);

what should be written, instead GL_FLOAT while using LWJGL?


*

Offline princec

  • *****
  • 1933
    • Puppygames
Re: Data type of OpenGL
« Reply #1 on: June 13, 2011, 20:21:07 »
If you're using a FloatBuffer, you don't need to specify type at all, as it is implicit from the buffer:

glVertexPointer(size, stride, floatBuffer);

Cas :)

Re: Data type of OpenGL
« Reply #2 on: June 13, 2011, 21:07:24 »
according to documentations
glVertexPointer(3, GL_FLOAT, 0, vertices);

here, GL_FLOAT is the data type, which is similar to C / C++ 's float data type.

isn't the final argument should be the array of vertex data, in glVertexPointer?

Sorry, I dont understand what you mean by float buffer.

I am following a tutorial from here,
http://www.songho.ca/opengl/gl_vertexarray.html

what is stride?

*

Offline princec

  • *****
  • 1933
    • Puppygames
Re: Data type of OpenGL
« Reply #3 on: June 13, 2011, 22:54:11 »
That's the C API documentation. The Java APIs are slightly different to account for the fact that Java does not have pointers.
In C you'd pass in a pointer to a float "array" and tell OpenGL you're using floats by passing GL_FLOAT in.
In Java, you'd use a FloatBuffer, the data type of which is explicitly GL_FLOAT. So in LWJGL, we don't ask you for the type parameter as it is already implied by the type of the buffer you pass in.

Stride is either zero (tightly packed vertex data), or the number of bytes between each vertex if they are not tightly packed and need some padding. The value is the total distance between the start of one vertex and the next, not the size of the required padding.

Cas :)

Re: Data type of OpenGL
« Reply #4 on: June 14, 2011, 00:21:26 »
thanks.

So, usually what i should do when it comes to GLuint, GLfloat type data?(when converting C / C++ code to Java)