在Qt中集成一个Bullet简单演示 [英] Integrate a Bullet simple demo in Qt

查看:1018
本文介绍了在Qt中集成一个Bullet简单演示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个Bullet演示集成到Qt应用程序中。我使用Bullet附带的Bullet演示示例,称为App_BasicDemo。



如果我执行这个应用程序没有Qt,它打开一个窗口,呈现得非常好。所以我想,如果我把它作为一个QGLWidget,它应该在Qt窗口做同样的事情。但它不工作。



在我的GLWidget的构造函数中,我创建了BasicDemo。在initializeGL中,我调用BasicDemo的myinit和initPhysics。最后,在paintGL中,我调用clientMoveAndDisplay。



我遇到的第一个问题是,clientMoveAndDisplay在调用swapBuffers时会崩溃。



如果我只是评论那行,程序不会崩溃,但它不显示任何东西。



我缺少什么?



编辑:

  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();

//可选但有用:调试图形以检测问题
if(m_dynamicsWorld)
m_dynamicsWorld-> debugDrawWorld();

glFlush();
swapBuffers();
}

编辑2:



Ok,我想我得到了答案。当我初始化openGL,我必须重塑一次演示,因为Bullet需要我的部件的宽度和高度。我想这是在一些Bullet方法之前,当它称为glutmain ...



scene-> reshape(this-> width,this-> height) / p>

做到了。
现在我可以看到我的项目符号演示。 (它不像在独立Bullet应用程序中那样更新,但是这是另一个问题)



谢谢你,Martin Beckett!


<没有代码是很难知道什么问题是 - 它听起来像你正试图更新一个屏幕以外的更新/重绘方法的小部件



我将从QWidget或QGlWidget中绘制的Qt示例开始,取决于您是否使用OpenGL。



如果你是新来的Gui编程,有点奇怪,你只能在屏幕上绘制在一个地方,但它会有意义(最终)和Qt一个非常好的学习地点!


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!

解决方案

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!

这篇关于在Qt中集成一个Bullet简单演示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆