Home > Software engineering >  Sometimes Qt's paintGL does not draw an OpenGL edge of Bullet's Physics colliders
Sometimes Qt's paintGL does not draw an OpenGL edge of Bullet's Physics colliders

Time:08-17

It works 50 by 50%:

enter image description here enter image description here

I use a timer for redrawing:

void Widget::animationLoop()
{
    m_deltaTime = m_elapsedTimer.elapsed() / 1000.f;
    m_elapsedTimer.restart();
    m_pWorld->stepSimulation(m_deltaTime, 8);
    update();
}

I call collider's drawing (m_pWorld->debugDrawWorld();) like this:

void Widget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    m_pWorld->debugDrawWorld();

    m_projViewMatrix = m_projMatrix * m_viewMatrix;
    m_pPlayer->position = m_pPlayerCollider->getPosition();
    m_pPlayer->rotation = m_pPlayerCollider->getRotation();
    m_pPlayer->draw(m_projViewMatrix);
    m_pGround->draw(m_projViewMatrix);
    m_pPlatforms->draw(m_projViewMatrix);
}

I have the DebugDrawer class that I inherit from btIDebugDraw. I override the drawLine method to transform the 1x1x1 cube to make a segment to draw. I draw the segment by calling m_pColliderEdge->draw(m_projViewMatrix); in the drawLine method.

I tried to send a pointer to the QOpenGLWidget object to the DebugDrawer constructor:

DebugDrawer(QOpenGLWidget *widget, btDynamicsWorld *pWorld, ColliderEdge *pColliderEdge);

to keep it for makeCurrent but this did not help:

void DebugDrawer::drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &color)
{
    /* ... */
    m_pWidget->makeCurrent();
    m_projViewMatrix = projMatrix * viewMatrix;
    m_pColliderEdge->draw(m_projViewMatrix);
}

CodePudding user response:

I forgot to get the uMvpMatrix location in the ColliderEdge class:

ColliderEdge::ColliderEdge(QOpenGLShaderProgram *program,
                           const VertexBuffersData &vertexBuffers)
    : m_pProgram(program)
{
    m_vertPosBuffer = vertexBuffers.vertPosBuffer;
    m_amountOfVertices = vertexBuffers.amountOfVertices;

    m_pProgram->bind();
    m_aPositionLocation = m_pProgram->attributeLocation("aPosition");
    m_uMvpMatrixLocation = m_pProgram->uniformLocation("uMvpMatrix");
}

Sorry, guys. I will publish simple examples in the next time when I ask questions.

enter image description here

  • Related