3

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!

Sara
  • 833
  • 2
  • 9
  • 21
  • There is a resizeGL method in QGLWidget that should get called automatically before the first draw, you can put stuff in there. Sometimes you need to manually call it if your engine needs to allocate space but it's very cheap to do a resizeGL – Martin Beckett Mar 30 '12 at 16:53

1 Answers1

0

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!

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
  • I call the function of bullet demo which draws in the widget method called paintGL. I've done this with other OpenGL programs, and it worked. Since Bullet also uses Opengl, I thought it should work the same way. – Sara Mar 30 '12 at 15:53
  • QGlWidget has auto bufferswap on by default are you swapping them twice? – Martin Beckett Mar 30 '12 at 15:55
  • @sara click edit and paste it in, then there is an icon like {} to format it, or just leave a comment and I can format it for you. Try and cut it down to just stuff that is relevent. – Martin Beckett Mar 30 '12 at 16:00
  • Ive tried commenting swapBuffers, but still the same problem :( – Sara Mar 30 '12 at 16:05
  • It's not clear where the drawing is being done - there is no code for renderme() but swapbuffers is being called by several layers of functions in the widget and bullet layers. Try to removing all of them. – Martin Beckett Mar 30 '12 at 16:13