java.net: Wiki

The Source for Java Technology Collaboration


 <<O>>  Difference Topic VertexArrays (1 - 22 Mar 2004 - Main.orangytang)
Line: 1 to 1
Added:
>
>
META TOPICPARENT name="OpenGL"
Vertex Arrays let you render whole chunks of geometry in one batch. They typically offer substancialy faster rendering than ImmediateMode, even more so in java because the JNI overhead is reduced.

Vertex arrays use data in continuous data chunks, which in C is just a regular array. In java this means using IntBuffer? / FloatBuffer? etc. Jogl will let you use regular java arrays, but this needs copying before being sent to OpenGL and so is not an optimal method.

Specify vertex data with:

  • glVertexPointer(size, type, stride, data)
  • glColorPointer
  • glNormalPointer
  • glTexCoordPointer

NB These do not copy or use any data directly, they simply set a pointer to your data (in a byte buffer) for later use. Also, remember to call glEnableClientState with GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_NORMAL_ARRAY and GL_TEXTURE_COORD_ARRAY with whichever arrays you're using.

The Stride parameter is the separation between elements. If you vertex data looks like: { x, y, z, x, y, z, x, y, z } your stride is 0. If you are using interleaved vertex/colour/normal data in a single array, remember that the stride is in bytes, not ints or floats.

Note that vertex, colour and texture coord data needs a 'size' parameter, (x, y) (x, y, z) (r, g, b) (r, g, b, a) etc. Normal pointer is the exception because normals always have 3 components.

LWJGL note: 'type' is usually GL_SHORT GL_INT GL_FLOAT, but LWJGL omits this and instead uses whatever type of buffer you passed in (ie GL_FLOAT if a FloatBuffer? is used).


Draw from the arrays using glDrawArrays Usage is simple, it accepts a type of primative to render, a starting index and a total number of indices to render with. NB the final 'count' is number of indices not primatives. You'll need to calculate this yourself.

Todo: Explain glDrawElements for indexed rendering. These are great, they use on-GPU vertex cache for better performance! w00t!

-- Main.orangytang - 22 Mar 2004


Topic VertexArrays . { View | Diffs r1 | More }
 XML java.net RSS