Hi, I was working through some tutorials around to learn other techniques than immediate mode. Basically translating this C example into LWJGL: http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=5 (http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=5)
So I create a float[] of for the triangle data, push it into a buffer in my initArrays() method.
Then in my render() method I bind to that buffer and set up the vertex array pointer to start at zero and move in steps of 3 over the buffer (to get the 3 values to form the vertex locations I'm assuming). However, when it executes the call to glVertexAttribPointer() I get the following exception:
Exception in thread "main" org.lwjgl.opengl.OpenGLException: Cannot use Buffers when Array Buffer Object is enabled
at org.lwjgl.opengl.GLChecks.ensureArrayVBOdisabled(GLChecks.java:87)
at org.lwjgl.opengl.GL20.glVertexAttribPointer(GL20.java:835)
at com.gordonmcmahon.lwjgl.temp.OpenGL3App.render(OpenGL3App.java:79)
at com.gordonmcmahon.lwjgl.temp.OpenGL3App.<init>(OpenGL3App.java:39)
at com.gordonmcmahon.lwjgl.temp.OpenGL3App.main(OpenGL3App.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
I've googled and gone through the source to try and find out why arrayBuffer is set to 1 on the Capabilities (and therefore failing the GLCheck) but I've not come up with much. Source for the two key methods below, but I can post the whole source if you think that will help.
Thanks in advance.
[tt]private void initArrays(){
fTriangle[0] = -0.2f; fTriangle[1] = 0.1f; fTriangle[2] = 0.0f;
fTriangle[3] = 0.4f; fTriangle[4] = 0.1f; fTriangle[5] = 0.0f;
fTriangle[6] = 0.0f; fTriangle[7] = 0.7f; fTriangle[8] = 0.0f;
triangleBuffer = BufferUtils.createFloatBuffer(fTriangle.length);
triangleBuffer.put(fTriangle);
uiVBO = BufferUtils.createIntBuffer(1);
glGenBuffers(uiVBO);
glBindBuffer(GL_ARRAY_BUFFER, uiVBO.get(0));
glBufferData(GL_ARRAY_BUFFER, triangleBuffer, GL_STATIC_DRAW );
}
private void render() {
glClear(GL_COLOR_BUFFER_BIT);
glEnableVertexAttribArray(0);
// Triangle render
glBindBuffer(GL_ARRAY_BUFFER, uiVBO.get(0));
glVertexAttribPointer(0, 3, false, 0, triangleBuffer); // THIS IS WHERE THE EXCEPTION IS THROWN
glDrawArrays(GL_TRIANGLES, 0, 3);
}
Ahh...you've all played a cunning game of "leave him alone and he'll fix it himself". Well done. I've since got my code working and have a much better understanding of what I was doing wrong.
Quote from: ReddZed on June 19, 2012, 07:48:46
Ahh...you've all played a cunning game of "leave him alone and he'll fix it himself". Well done. I've since got my code working and have a much better understanding of what I was doing wrong.
Lol... :D