I want to integrate a Bullet demo into a Qt application. I am using the Bullet demo example that comes with Bullet, called App_BasicDemo.
If I execute this application without Qt, it opens a window and renders very well. So I thought, if I just put this as a QGLWidget, it should do the same thing in a Qt window. But it does not work.
In the constructor of my GLWidget, I create the BasicDemo. In initializeGL, I call myinit and initPhysics of the BasicDemo. And finally, in paintGL, I call clientMoveAndDisplay.
The first problem I had, was that clientMoveAndDisplay would crash when calling swapBuffers.
If I just comment that line, the program does not crash, but it doesn't show anything.
What am I missing?
Edit:
void GLWidget::paintGL() {
scene->clientMoveAndDisplay();
QGLWidget::swapBuffers();
}
void BasicDemo::clientMoveAndDisplay(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float ms = getDeltaTimeMicroseconds();
renderme();
glFlush();
//swapBuffers();
}
void BasicDemo::displayCallback(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderme();
//optional but useful: debug drawing to detect problems
if (m_dynamicsWorld)
m_dynamicsWorld->debugDrawWorld();
glFlush();
swapBuffers();
}
Edit 2:
Ok, I think I got the answer. When I initialize openGL, I have to reshape once the Demo, because Bullet needs the width and height of my widget. I guess this was done inside some Bullet method before, when it called glutmain...
scene->reshape(this->width,this->height);
did the trick. Now I can see my Bullet Demo. (It does not get updated as it does in the independent Bullet application, but that is another problem)
Thanks anyway Martin Beckett!