I’m giving modern OpenGL a go, but I’m curious why I wasn’t able to add another VBO (more positional data) to my VAO. Based off the Wiki, I followed the same process to create the first VBO (vbo0) and put it on index 0. The second one (vbo1) at a different position isn’t being rendered, even though I put it in index 1. They should be 2 quads at different positions.
INITIALIZATION
public void setupQuad() {
//vbo0
float[] vertices = {
// Left bottom triangle
-0.5f, 0.5f, 0f,
-0.5f, -0.5f, 0f,
0.5f, -0.5f, 0f,
// Right top triangle
0.5f, -0.5f, 0f,
0.5f, 0.5f, 0f,
-0.5f, 0.5f, 0f
};
FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length);
verticesBuffer.put(vertices);
verticesBuffer.flip();
///////vbo1
float[] vertices1 = {
// Left bottom triangle
-0.8f, 0.8f, 0f,
-0.8f, -0.8f, 0f,
-0.6f, -0.8f, 0f,
// Right top triangle
-0.8f, 0.8f, 0f,
-0.6f, -0.8f, 0f,
-0.6f, 0.8f, 0f
};
FloatBuffer verticesBuffer1 = BufferUtils.createFloatBuffer(vertices1.length);
verticesBuffer1.put(vertices1);
verticesBuffer1.flip();
vaoId = GL30.glGenVertexArrays();
GL30.glBindVertexArray(vaoId);
//vbo0
vboId = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);
GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);//index 0
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
//vbo 1
vboId1 = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId1);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer1, GL15.GL_STATIC_DRAW);
GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, 0, 0);//index 1
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL30.glBindVertexArray(0);
}
Rendering
public void loopCycle() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL30.glBindVertexArray(vaoId);
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
// Draw the vertices
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertexCount);
GL20.glDisableVertexAttribArray(0);
GL20.glDisableVertexAttribArray(1);
GL30.glBindVertexArray(0);
}
Also, how can I get coordinates based on screen size without using an Orthographic projection? It wont let me call
glOrtho
, so I’d asume it’s deprecated.