EDIT
I have effectively rewritten this question in order to greatly improve 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);
gl.glBindVertexArray(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);
vData.put(vertexData);
vData.rewind();
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.glEnableVertexAttribArray(0);
gl.glVertexAttribPointer(0, 4, GL.GL_FLOAT, false, 0, null); // This is the line where the exception is thrown
gl.glBindVertexArray(0);
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);
iData.put(indexData);
iData.rewind();
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
gl.glBindVertexArray(vaoID[0]);
// 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
gl.glBindVertexArray(0);
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.
glVertexAttribPointerhas two modes of operation. If there’s no VBO bound, it takes a pointer to the data as the last argument. If there’s a VBO bound the last argument is instead an integer offset into the buffer. In C, you have to cast this integer into a pointer anyway, but it is not treated as a pointer if there’s a VBO bound.In JOGL, these two modes are realized with two overloads: one that takes a
Buffer(instead of a pointer) and one that takes along(instead of an offset cast into a pointer).If you use the first one with a VBO bound it throws an error because that’s the mode that only works without a VBO bound. If you unbind your VBO and pass
nullto the last parameter, you’re still calling the first overload:nullcan match aBufferparameter, but not along. JOGL seems to not have a similar validation for this case. This will probably treat it as the offset 0, but it will also store 0 as the VBO to look for the data. That is, no VBO at all.What you need to do is, using your original code, i.e., with a VBO bound, call the overload that takes an offset instead:
And there is also another issue that is not letting anything render. You’re passing
GL4.GL_POINTtoglDrawElements. That’s not a valid assembly mode. I don’t know what it is for (my OpenGL 4 knowledge fails me). The constant for the points assembly mode is namedGL_POINTS: