Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Crash in QGraphicsScene::drawBackground OpenGL 3.1
Qt 6.11 is out! See what's new in the release blog

Crash in QGraphicsScene::drawBackground OpenGL 3.1

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Morphine_OD
    wrote on last edited by
    #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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved