title: Using a single ByteBuffer with multiple arrays in OpenGL
body: <p>In my application, I'm having to draw multiple elements with OpenGL, some are Triangles and others are Line Strips. I'm putting my vertices into multiple <code>float[]</code> and my indices into multiple <code>short[]</code> whenever I am to draw a new shape. I also have to create a new <code>FloatBuffer</code>, <code>ShortBuffer</code> and <code>ByteBuffer</code> for each new array in order to make it work.<br/><br/>How could I more efficiently draw the multiple elements? I was thinking of putting all of the vertices into a single <code>float[]</code> and creating a new <code>short[]</code> for each element to remove excess arrays, but is it possible to use one <code>FloatBuffer</code>, <code>ShortBuffer</code> and put all of the arrays into a single <code>ByteBuffer</code> such as this:</p>
  
  <pre><code>float[] vertices = { -3, -3, -3, 2, 3, 0, 2, -1, 0, 0, 5, 2, 3, 1 };
  short[] indItemA = { 0, 1, 2, 0, 2, 3 };
  short[] indItemB = { 4, 5, 6 };
  
  FloatBuffer fBuff;
  ShortBuffer sBuff;
  
  ByteBuffer bBuff = ByteBuffer.allocateDirect(vertices.length * 4);
  fbBuff.order(ByteOrder.nativeOrder());
  
  fBuff = bBuff.asFloatBuffer();
  fBuff.put(vertices);
  fBuff.position(0);
  
  sBuff = bBuff.asShortBuffer();
  sBuff.put(indItemA);
  sBuff.position(0);
  
  sBuff.put(indItemB);
  sBuff.position(0);
  </code></pre>