Hi guys!
Yet again opengl is giving me a lot of attitude and I can’t figure out why…
I am trying to draw a rectangle using 2 triangles drawn with glDrawElements.
No textures just color.
I am in the same program drawing a lot of rectangles with texturing and that is still working but a simple rectangle does not work…
When I use the code below I get the error below the code, saying that “element array buffer object is disabled”.
If I try to use glDrawElements with a shortbuffer directly I get the exact opposite error: “Element array buffer object is enabled”.
I have made sure that all the vbo-IDs are not -1. So they are there…
Also it worked when I used glDrawArrays, but it stopped working when I converted to glDrawElements.
This truly confuse me so i hope that someone else can spot the problem
public void render()
{
//If there is nothing to render return
if(numberOfVerticies == 0)
return;
glUseProgram(shaderProgramID);
//Send the data to the vertex-vbo
buffer.flip();
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, buffer, GL_DYNAMIC_DRAW);
//Send the indecies to the index-vbo
indexBuffer.flip();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ivboID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBuffer, GL_DYNAMIC_DRAW);
//Bind the vao
glBindVertexArray(vaoID);
//Draw the triangles
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
//Reset the batcher
buffer.clear();
indexBuffer.clear();
numberOfVerticies = 0;
}
org.lwjgl.opengl.OpenGLException: Cannot use offsets when Element Array Buffer Object is disabled
at org.lwjgl.opengl.GLChecks.ensureElementVBOenabled(GLChecks.java:105)
at org.lwjgl.opengl.GL11.glDrawElements(GL11.java:1117)
at graphics.ShapeBatcher.render(ShapeBatcher.java:325)
at graphics.SpriteBatcher.checkMode(SpriteBatcher.java:471)
at graphics.SpriteBatcher.render(SpriteBatcher.java:428)
at startMenu.StartMenu.render(StartMenu.java:106)
at stateBasedGame.StateBasedGame.start(StateBasedGame.java:49)
at Main.main(Main.java:53)