Results 1 to 2 of 2

Thread: I can't get a simple indexed array rendered properly

  1. #1
    Member Contributor
    Join Date
    Dec 2011

    I can't get a simple indexed array rendered properly

    I am porting this sample (site) to jogl but I noticed something wasn't perfect in the image, some artefacts on the floor and shapes not exactly squared, as you can see (dont care about color, is varying), also the floor doesnt look good:



    Therefore I tried to render only the floor first (if you wanna try, pretty easy, swith SQRT_BUILDING_COUNT from 100 -> 0) and there I have already the first problems, it is supposed to be a square based on two triangles, but I see only one of them.


    My vertex structure

    Code :
        public float[] position = new float[3];
        public byte[] color = new byte[4];
        public float[] attrib0 = new float[4];
        public float[] attrib1 = new float[4];
        public float[] attrib2 = new float[4];
        public float[] attrib3 = new float[4];
        public float[] attrib4 = new float[4];
        public float[] attrib5 = new float[4];
        public float[] attrib6 = new float[4];

    attrib0-6 are unused at the moment

    My VS inputs:
    // Input attributes
    layout(location=0) in vec4 iPos;
    layout(location=1) in vec4 iColor;
    layout(location=2) in PerMeshUniforms* bindlessPerMeshUniformsPtr;
    layout(location=3) in vec4 iAttrib3;
    layout(location=4) in vec4 iAttrib4;
    layout(location=5) in vec4 iAttrib5;
    layout(location=6) in vec4 iAttrib6;
    layout(location=7) in vec4 iAttrib7;
    I am declaring iPos as vec3, so I guess it will padded as vec4(iPos, 1) in the VS

    I transfer data to gpu
    Code :
            gl4.glNamedBufferData(vertexBuffer[0], Vertex.size() * vertices.size(),
                    GLBuffers.newDirectFloatBuffer(verticesArray), GL4.GL_STATIC_DRAW);
            gl4.glNamedBufferData(indexBuffer[0], GLBuffers.SIZEOF_SHORT * indices.size(),
                    GLBuffers.newDirectShortBuffer(indicesArray), GL4.GL_STATIC_DRAW);

    Then before I render I call:

    Code :
                gl4.glEnableVertexArrayAttrib(0, 0);
                gl4.glEnableVertexArrayAttrib(0, 1);

    Then render, original code is:
    Code :
            // Set up attribute 0 for the position (3 floats)
            glVertexArrayVertexAttribOffsetEXT(0, m_vertexBuffer, 0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::PositionOffset);
            // Set up attribute 1 for the color (4 unsigned bytes)
            glVertexArrayVertexAttribOffsetEXT(0, m_vertexBuffer, 1, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), Vertex::ColorOffset);

    I substituted it with:
    Code :
                // Set up attribute 0 for the position (3 floats)
                gl4.glVertexArrayVertexBuffer(0, 0, vertexBuffer[0], Vertex.positionOffset,
                gl4.glVertexArrayAttribFormat(0, 0, 3, GL4.GL_FLOAT, false, Vertex.size());
                // Set up attribute 1 for the color (4 unsigned bytes)
                gl4.glVertexArrayVertexBuffer(0, 1, vertexBuffer[0], Vertex.colorOffset,
                gl4.glVertexArrayAttribFormat(0, 1, 4, GL4.GL_UNSIGNED_BYTE, true, Vertex.size());

    And then I finish the render:
    Code :
                // Reset state
                gl4.glDisableVertexArrayAttrib(0, 0);
                gl4.glDisableVertexArrayAttrib(0, 1);

    I admit I never used dsa before, I always used GL3 with the normal vbo, vao and ibo, binding and unbinding..

    What's wrong then?

  2. #2
    Member Contributor
    Join Date
    Dec 2011
    Solved, the problem was I didnt implement properly dsa

    glEnableVertexAttribArray(vao, 0);
    glEnableVertexAttribArray(vao, 1);

    // Setup the formats
    glVertexArrayAttribFormat(vao, 0, 3, GL_FLOAT, GL_FALSE, 0);
    glVertexArrayAttribFormat(vao, 1, 2, GL_FLOAT, GL_FALSE, 0);

    // Setup the buffer sources
    glVertexArrayVertexBuffer(vao, 0, buffers[0], 0, 0); // Note the 2nd argument here is a 'binding index', not the attribute index
    glVertexArrayVertexBuffer(vao, 1, buffers[1], 0, 0);

    // Link them up
    glVertexArrayAttribBinding(vao, 0, 0); // Associate attrib 0 (first 0) with binding 0 (second 0).
    glVertexArrayAttribBinding(vao, 1, 1);

    plus glVertexArrayElementBuffer if you have indexed rendering

Similar Threads

  1. Object not rendered properly on different angle
    By vincent911001 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-26-2015, 07:13 PM
  2. Is indexed array not use for texturing?
    By standy in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 02-09-2011, 07:40 PM
  3. Triangle strips not rendered properly. OpenGL driver problem?
    By surgptr in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 04-07-2003, 02:43 AM
  4. Indexed array question
    By dabeav in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-26-2002, 06:23 PM
  5. indexed array for normals ...
    By imported_T2k in forum OpenGL: General
    Replies: 2
    Last Post: 06-27-2001, 12:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean