glPrimitiveRestartIndex doesn't work as it should in Xcode

  • Hi,

    I have trouble porting my Qt code from Visual Studio to Xcode. I use glPrimitiveRestartIndex to draw many triangle strips with one draw call, and it works nice in Visual Studio, but doesn't work in Xcode. I wrote little function:

    void drawStrip(QOpenGLShaderProgram* program) {
    vector<QVector3D> vertices;

    size_t numVertices = 6;
    size_t numTriangles = 2;
    GLushort indices[] = {0,1,2,3, 0xFFFF, 1,4,3,5};
    size_t numIndices = 8;
    arrayBuf.allocate(&vertices[0], numVertices*sizeof(QVector3D));
    indexBuf.allocate(indices, numIndices*sizeof(GLushort));
    quintptr offset = 0;
    int vertexLocation = program->attributeLocation("a_position");
    program->setAttributeBuffer(vertexLocation, GL_FLOAT, offset, 3, sizeof(QVector3D));
    glDrawElements(GL_TRIANGLE_STRIP, numIndices, GL_UNSIGNED_SHORT, 0);


    Which should draw two quads one on top of another. It works in VS, as I said, but in Xcode it gives strange result, like it's not restarting indices correctly , 4th triangle is not even drawn and 3th and 4th triangles are flipped.

    Maybe, it's a version of OpenGL that cause troubles - in windows is 4.3, and on Mac is 4.1. I tried including QtOpenGLFunctions_4_1_core.h in Xcode, but that won't even compile - it's gives few BAD ACCESS errors. When I include just QtOpenGLFunctions.h, the result is what I described above.

    What can be problem here? Why does QtOpenGLFunctions_4_1_core gives that errors in Xcode?

  • Ok, I found that glEnable doesn't even enabled GL_PRIMITIVE_RESTART .

  • Ok, actually I found out that glEnable doesn't work (not just for GL_PRIMITIVE_RESTART, but for all enums). I tried to use glEnable directly in GLWidget class, but it doesn't work. What can be problem?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.