I want to draw something using vbo and indices but my code doesn’t work - I get a black screen. What’s wrong ?
Creating vbo’s:
vboVertices = new float[]{3.0f, 3.0f, 3.0f, 1.0f,
-3.0f, 3.0f, 3.0f, 1.0f,
-3.0f, -3.0f, 3.0f, 1.0f,
3.0f, -3.0f, 3.0f, 1.0f,
-3.0f, 3.0f, -3.0f, 1.0f,
3.0f, 3.0f, -3.0f, 1.0f,
3.0f, -3.0f, -3.0f, 1.0f,
-3.0f, -3.0f, -3.0f, 1.0f};
vboIndices = new byte[]{0,1, 0,3, 0,5,
1,4, 1,2, 2,7,
2,3, 3,6, 4,7,
4,5, 5,6, 6,7};
int buffer[] = new int[2];
gl.glGenBuffers(2, IntBuffer.wrap(buffer));
vbo[0] = buffer[0];
vbo[1] = buffer[1];
gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo[0]);
gl.glBufferData(GL3.GL_ARRAY_BUFFER, vboVertices.length * Sizeof.FLOAT, FloatBuffer.wrap(vboVertices), GL3.GL_DYNAMIC_DRAW);
gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo[1]);
gl.glBufferData(GL3.GL_ELEMENT_ARRAY_BUFFER, vboIndices.length * Sizeof.BYTE, ByteBuffer.wrap(vboIndices), GL3.GL_DYNAMIC_DRAW);
gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
Rendering
gl.glUseProgram(shaderProgramID);
projectionMatrixUniform = gl.glGetUniformLocation(shaderProgramID, "pMatrix");
gl.glUniformMatrix4fv(projectionMatrixUniform, 1, false, projectionMatrix, 0);
modelViewMatrixUniform = gl.glGetUniformLocation(shaderProgramID, "mMatrix");
gl.glUniformMatrix4fv(modelViewMatrixUniform, 1, false, modelViewMatrix, 0);
colorUniform = gl.glGetUniformLocation(shaderProgramID, "color");
gl.glUniform4f(colorUniform, 1.0f, 1.0f, 1.0f, 1.0f);
gl.glEnableVertexAttribArray(0);
gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo[0]);
gl.glVertexAttribPointer(0, 4, GL3.GL_FLOAT, false, 0, 0);
gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, vbo[1]);
gl.glDrawElements(GL3.GL_LINES, 12, GL3.GL_BYTE, 0);
gl.glDisableVertexAttribArray(0);
gl.glUseProgram(0);