Vertex, Normal, Color, etc...arrays in JoGL

Could someone please post a working example on how to implement them in JoGL?
I tried it myself, but I got an error saying something along the lines: the function takes bla bla bla and nioBuffer or something like that, instead of whatever I thought it would take based on a look at the C++ code.
…/me feels dumb for some reason :-X

From my buffer code:

      private FloatBuffer vertexData;
      private FloatBuffer colourData;
      private FloatBuffer texCoords;
...
            GL gl = canvas.getGL();
            
            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
            gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertexData);
            
            
            if (coloursEnabled)
            {
                  gl.glEnableClientState(GL.GL_COLOR_ARRAY);
                  gl.glColorPointer(4, GL.GL_FLOAT, 0, colourData);
            }
            else
                  gl.glDisableClientState(GL.GL_COLOR_ARRAY);

etc.

Remember you may need a helper method to create the buffers in the correct byte ordering:

      public static FloatBuffer createFloatBuffer(int size)
      {
            ByteBuffer temp = ByteBuffer.allocateDirect(4*size);
            
            temp.order(ByteOrder.nativeOrder());
            
            return temp.asFloatBuffer();
      }

Either that or i’ve missed the point totally, and you’re going to have to give a better description :stuck_out_tongue:

Orangy Tang dom Dee dom dee dom ;D
Yup that’s exactly what I wanted to see, thanks :stuck_out_tongue:
PS: Looking at your code, the colorArray has 4 channels per color, correct?
Is that alright if I stick with a triple channel per color array given the following modification?
gl.glColorPointer(3, GL.GL_FLOAT, 0, colourData);
One more thing, having never touched FlotBuffers in my life, how do I change the entries?
is there like a funtion .element(index) that access individual element for potential modifications?

Yup, that first number in the gl*Pointer calls is the components, so switch it to 3 if you’re using RGB and not RGBA.

To modify, buffers have all sorts of methods depending on whether you want absolute or relative inserts. Theres .put() methods for either single primative or arrays, and these can either be relative to the current position or absolute (in which case they take an index to add at).

The only thing you’ve got to be careful with is .rewind()'ing a buffer if you want to start from the beginning again and fill it up with new data. Other than that it can be seen just as a fancy array :slight_smile:

Jogl already contains a class for creating buffers that sets the byte order to the native byte order. I think it’s called BufferUtils. So no need to duplicate this…