Login  Register

Re: Multiple VAO and VBO with JOGL

Posted by Chen norris on Apr 20, 2018; 1:53pm
URL: https://forum.jogamp.org/Multiple-VAO-and-VBO-with-JOGL-tp4038824p4038834.html

Hi John, thanks a lot for your code.

I managed to change the import so that it uses the JOGL librairies and it works like a charm (pink background with 2 grey triangles).
Then I tried to change a bit the way it works so that it would run with 2 differents VAOs. The changes I made are the following :
private static final float[] first_triangle = new float[]{
    -1.0f, -1.0f, 0.1f,
    1.0f, 1.0f, 0.1f,
    0.0f, 1.0f, 0.1f
};
private static final float[] second_triangle = new float[]{
    1.0f, -1.0f, 0.7f,
    0.0f, 1.0f, 0.7f,
    -1.0f, 1.0f, 0.7f
};
Two triangles to render = two calls to createBuffer like this :
// Create the mesh
createBuffer(gl, shaderPosition, first_triangle, 3, 0);
createBuffer(gl, shaderPosition, second_triangle, 3, 1);
The final parameter I added to the createBuffer method is used to know what VAO must be binded :
public void createBuffer(final GL4 gl, final int shaderAttribute, float[] values, final int valuesPerVertex, int n) {
    if (!vasSet) {
        gl.glGenVertexArrays(this.vas.length, this.vas, 0);
        vasSet = true;
    }
    gl.glBindVertexArray(this.vas[n]);
    // ... and so on
A last modification is made in the display method, to render not anymore 1 but 2 VAOs :
gl.glUseProgram(this.flatColorShaderProgram);
gl.glBindVertexArray(this.vas[0]);
gl.glEnableVertexAttribArray(this.shaderPosition);
gl.glDrawArrays(GL4.GL_TRIANGLES, 0, 3);

gl.glBindVertexArray(this.vas[1]);
gl.glEnableVertexAttribArray(this.shaderPosition);
gl.glDrawArrays(GL4.GL_TRIANGLES, 0, 3);

So now, I think I have a good example on which I can rely on to understand why I couldn't render properly multiple VAOs.
Thank you so much, that thing was starting to drive me crazy...

Nice copyright, by the way ^^