Integrate a Bullet simple demo in Qt

放肆的年华 提交于 2020-01-23 11:32:18

问题


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!


回答1:


Without code is very difficult to know what the problem is - it sounds like you are attempting to update a screen outside the update/redraw method of the widget

I would start with looking at the Qt examples for drawing in a QWidget or QGlWidget depending if you are using OpenGL or not.

If you are new to Gui programming it is a bit odd that you can only draw on the screen in a single place but it will make sense (eventually) and Qt is a very good place to learn!



来源:https://stackoverflow.com/questions/9945856/integrate-a-bullet-simple-demo-in-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!