Question

I am trying to draw two simple quads with shaders and VBO. But as output I get only one quad.

Where I am missing something?

Initialization code (shaders and matrices initialization code is skipped):

  gl.GenBuffers((int) VAO_IDs.NumVAOs, VAOs);
            gl.BindVertexArray(VAOs[(int) VAO_IDs.Guads]);

            float[] vertices =
            {
               -0.095f, 0.095f, 0.695f, //first quad 
               -0.095f, 0.0475f, 0.695f,
               -0.095f, 0.00475f, 0.7455f,
               -0.095f, 0.095f,  0.7455f,

               -0.095f, 0.0475f, 0.695f, //second quad 
               -0.095f, 0f, 0.695f,
               -0.095f, 0f, 0.7455f,
               -0.095f, 0.0475f, 0.7455f
            };

            gl.GenBuffers((int) Buffer_IDs.NumBuffers, Buffers);
            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, Buffers[(int) Buffer_IDs.ArrayBuffer]);
  unsafe
            {
                fixed (float* verts = vertices)
                {
                    var prt = new IntPtr(verts);

                    gl.BufferData(OpenGL.GL_ARRAY_BUFFER, vertices.Length*sizeof (float), prt, OpenGL.GL_STATIC_DRAW);
                }
            }


            gl.VertexAttribPointer((uint)Attrib_IDs.vPosition, 3, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));
            gl.EnableVertexAttribArray((uint)Attrib_IDs.vPosition);

Displaying code:

 gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

 shaderProgram.Bind(gl);
 shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
 shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
 shaderProgram.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());


    gl.BindVertexArray(VAOs[(int)VAO_IDs.Guads]);

    gl.DrawArrays(OpenGL.GL_QUADS, 0, 8);

    shaderProgram.Unbind(gl);
    gl.Flush();
Was it helpful?

Solution

At the risk of pointing out the obvious: The coordinates of your two quads are set so that they are adjacent to each other. If you draw two quads right next to each other, you get... a bigger quad. Try using coordinates that leave a gap between the two quads, and see if they show up separately.

There appears to be a minor typo in your coordinates here:

           -0.095f, 0.0475f, 0.695f,
           -0.095f, 0.00475f, 0.7455f,

You probably meant to use the same value for the two y-coordinates. But this just makes the two quads overlap partly, they still form a single quad together.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top