I have effectivley re-wrote this question in order to greatly imrpove its quality - see revision logs if you must

I have narrowed down my problem to the initialisation phase of my program, when I am trying to create my vertex buffer. The code that I am currently using is...

vaoID = new int[1];
gl.glGenVertexArrays(1, vaoID, 0);
vboID = new int[1];
gl.glGenBuffers(1, vboID, 0);
gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, vboID[0]);
FloatBuffer vData = FloatBuffer.allocate(vertexData.length);
gl.glBufferData(GL4.GL_ARRAY_BUFFER, vData.capacity() * (Float.SIZE / 8), vData, GL4.GL_STATIC_DRAW);
gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, 0); // With out this line my code throws the exception
gl.glVertexAttribPointer(0, 4, GL.GL_FLOAT, false, 0, null); // This is the line where the exception is thrown

So yes, at present my code is able to run with out crashing, but it must have a mistake some where as I am not able to get this to render. For the buffering the index data, I use this code, which does complete successfully when it runs

gl.glGenBuffers(1, bufferIDs, 0);
gl.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, bufferIDs[0]);
ShortBuffer iData = ShortBuffer.allocate(indexData.length);
indexCount = iData.capacity();
gl.glBufferData(GL4.GL_ELEMENT_ARRAY_BUFFER, indexCount * (Short.SIZE / 8), iData, GL4.GL_STATIC_DRAW);
gl.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, 0);

Then when it comes to drawing, I perform the following steps, and I don't think this really matters, as I am sure I am still not buffer correctly in the first place

// first I bind my VAO
// then bind, draw, unbind the index buffer
gl.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, bufferIDs[0]);
gl.glDrawElements(GL4.GL_POINT, indexCount, GL4.GL_UNSIGNED_SHORT, 0);
gl.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, 0);
// finally I unbind the VAO

I am fairly sure that this is the correct process for rendering buffered geometry. I have confirmed that my shader code is correct and valid by use of some immediate drawing commands, so I do I have full pipeline, it just seems I am not feeding data into it. As a point of interest, I also tried editing my vertex shader to set all points to (0,0,0,1) so that if any points where being passed in, I should see them, but this did not work, which I took to mean that I am not passing data into my shader in the first place.

Thanks for all the help so far.

  • \$\begingroup\$ bufferID and bufferIDs? That is surely confusing... As for redundant code pasting, just put it on pastie.org, and if it becomes relevant to the question, you can inline it in your original post. \$\endgroup\$ Commented Dec 5, 2011 at 18:24
  • \$\begingroup\$ well, I have made a few changes to the code... so I will work on updating the question. \$\endgroup\$
    – thecoshman
    Commented Dec 6, 2011 at 9:48
  • \$\begingroup\$ You only need to set up the vertex attributes once, and when the VAO is bound. The draw step should only consist of binding the VAO, and calling glDrawElements with the indices count (no other bindings). \$\endgroup\$ Commented Dec 6, 2011 at 20:11
  • 1
    \$\begingroup\$ GL_ELEMENT_ARRAY_BUFFER is part of the VAO. You should your element array in the VAO setup code, not in your rendering code. The VAO contains everything you need (vertex data-wise) to render with. \$\endgroup\$ Commented Feb 5, 2012 at 16:54
  • \$\begingroup\$ VAO's are kinda living their own life in terms of what buffers get bound: stackoverflow.com/questions/8973690/… \$\endgroup\$
    – arul
    Commented Feb 6, 2012 at 3:12

3 Answers 3


Your first problem is here:

gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, 0); // With out this line my code throws the exception

That's unbinding your buffer object before the glVertexAttribPointer call. You need to have a buffer bound in order for that to be a reasonable call. It's the combination of having a buffer bound to GL_ARRAY_BUFFER and calling glVertexAttribPointer that sets up an association between a buffer object and a vertex attribute.

Once you've called glVertexAttribPointer, then you can unbind the buffer. But not until then.

Your other problem is this your element buffer setup code.

gl.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, bufferIDs[0]);

GL_ELEMENT_ARRAY_BUFFER is part of the VAO's state (unlike GL_ARRAY_BUFFER). So you need to do it while your VAO is still bound to the context, not after.


Are you using a vertex buffer somewhere else in the code? Or using a third-party library that does?

I would try calling gl.glDisableClientState(GL2.GL_VERTEX_ARRAY); at each frame, just before gl.glEnableVertexAttribArray(0);.

  • \$\begingroup\$ I have tried disabling GL_VERTEX_ARRAY but it makes no difference \$\endgroup\$
    – thecoshman
    Commented Dec 7, 2011 at 8:37

I am facing the same problem with VBO myself, so cannot help you much with it but I have one basic suggestion

    gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, 0); 
    // With out this line my code throws the exception

The above line is de-allocating your buffer so you are right. No data is being copied to the vbo. The drawing process needs to be bracketed within the calls

    //TODO Drawing Commands

If someone can shade some more light on this issue it will be very helpful as it is very difficult for java users to get clear answers on VBO issues.

  • 2
    \$\begingroup\$ -1: Welcome to GameDev.SE. This is not a discussion forum. The "Post Your Answer" button is used for answers, not commentary on the question. Your answer isn't really an answer, but a request for more information. Also, "The above line is de-allocating your buffer" No it isn't. It is merely unbinding the buffer object. Oh, and "The drawing process needs to be bracketed within the calls" No it does not. That's when you're using old glVertexPointer arrays; he's using generic vertex attributes. \$\endgroup\$ Commented Jan 28, 2013 at 7:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .