Solved Sometimes Qt's paintGL does not draw OpenGL edge of Bullet's Physics colliders
-
It works 50 by 50%:
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 frombtIDebugDraw
. I override thedrawLine
method to transform the 1x1x1 cube to make a segment to draw. I draw the segment by callingm_pColliderEdge->draw(m_projViewMatrix);
in thedrawLine
method. -
Usually, this implies some sort of pointer problem.
@newQOpenGLWidget thank you! You set a direction for me. I forgot to get the
uMvpMatrix
location in theColliderEdge
class. I will publish a simple example in the next time when I ask a question.Note. This answer is from StackOverflow
-
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); }
-
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(); }
-
Usually, this implies some sort of pointer problem.
@newQOpenGLWidget thank you! You set a direction for me. I forgot to get the
uMvpMatrix
location in theColliderEdge
class. I will publish a simple example in the next time when I ask a question.Note. This answer is from StackOverflow