Crash in QGraphicsScene::drawBackground OpenGL 3.1



  • I'm trying to use OGL 3.1 functions only and shaders are coded on CG. So here's the code:

    My drawBackground function:

    @void Scene::drawBackground(QPainter *painter, const QRectF &rect)
    {
    drawLoop();
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
    }@

    That's how I allocate buffers:

    @void Scene::allocModelBuffers(Model3d* model)
    {
    glGenVertexArrays(1, &model->arrayNumber);
    glBindVertexArray(model->arrayNumber);
    glGenBuffers(1, &model->bufferNumber);
    glBindBuffer(GL_ARRAY_BUFFER, model->bufferNumber);
    glBufferData(GL_ARRAY_BUFFER,
    model->vertices->size() * 3 * sizeof(double),
    &model->vertices->first(),
    GL_STATIC_DRAW);

    glGenBuffers(1, &model->indexNumber);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, model->indexNumber);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER,
                 model->indices->size()*sizeof(uint),
                 &model->indices->first(),
                 GL_STATIC_DRAW);
    
    glVertexAttribPointer((GLuint)0, 3, GL_DOUBLE, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(0);
    

    }@

    And this is how I draw.
    @void Scene::draw(Model3d* model)
    {
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
    glPointSize(model->size);
    glBindVertexArray(model->arrayNumber);

    cgGLSetParameter4f(color,
                       model->color[0]/255.0f,
                       model->color[1]/255.0f,
                       model->color[2]/255.0f,
                       model->color[3]/255.0f);
    

    //Here goes the CRASH
    glDrawElements(model->mode,
    model->indices->size(),
    GL_UNSIGNED_INT, (GLvoid*)0);
    }@

    The weird thing is that the code works when processed in paintGL() or paintEvent() methods in QGLWidget.
    The crash occurs on glDrawElements. Any help would be appreciated


Log in to reply
 

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