i'm trying to learn LWJGL (OpenGL) and i have to say i'm having a hard time.
I was trying to draw a triangle and a quad on the window and i finally managed to do it.
But i still have a question.
Sorry in advance if the question sounds stupid to you but i haven't been able to find a very detailed tutorial on the web so it's hard to understand since it's the first time i use OpenGL.
That being said, this is the relevant part of code:
public void init() {
vertexCount = indices.length;
vaoId = GL30.glGenVertexArrays();
GL30.glBindVertexArray(vaoId);
vboId = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, coords, GL15.GL_STATIC_DRAW);
GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
idxVboId = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, idxVboId);
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW);
GL30.glBindVertexArray(0);
}
public void render() {
GL30.glBindVertexArray(vaoId);
GL20.glEnableVertexAttribArray(0);
GL11.glDrawElements(GL11.GL_TRIANGLES, vertexCount, GL11.GL_UNSIGNED_INT, 0);
GL20.glDisableVertexAttribArray(0);
GL30.glBindVertexArray(0);
}
Let's say that the program is running at 60 fps.
This means that the render method is being called by the game loop 60 times every second.
The render method steps are:
glBindVertexArray(vaoId)
glEnableVertexAttribArray(0)
- Draw the quad
glDisableVertexAttribArray(0)
glBindVertexArray(0)
My question is: Is it necessary to call steps 1, 2, 4 and 5 every time? If yes why?
And the same question applies to the last line of the init()
method (glBindVertexArray(0)
).
Sorry for my english, it's not my mother tongue.
Thanks in advance.