Rendering QT widgets in Ogre

Problems building or running the engine, queries about how to use features etc.
Marseyeah
Gnoblar
Posts: 8
Joined: Sat Jul 25, 2009 10:05 pm
Location: Oslo, Norway

Re: Rendering QT widgets in Ogre

Post by Marseyeah »

Try this in resizeGL() :

Code: Select all

void QOgreGLWidget::resizeGL(int width, int height)
{
	makeOgreCurrent();
	if(_ogreRenderWindow)
	{
		_ogreRenderWindow->resize(w, h);
		_ogreRenderWindow->windowMovedOrResized();
	}
	if(_camera)
	{
		Ogre::Real aspectRatio = Ogre::Real(width) / Ogre::Real(height);
		_camera->setAspectRatio(aspectRatio);
	}
	glViewport(0,0,width, height);
   makeCurrent(); 
	QGLWidget::resizeGL(width, height);
}
dermont
Bugbear
Posts: 812
Joined: Thu Dec 09, 2004 2:51 am
x 42

Re: Rendering QT widgets in Ogre

Post by dermont »

machado wrote:Hi!

Thanks Marseyeah, after calling updateGL() the ogre scene appears, but small.
So I subclassed QGraphicsView resize event:

Code: Select all

void QOgreGraphicsView::resizeEvent( QResizeEvent *event )
{
	QOgreGLWidget* qOgreGL = (QOgreGLWidget*)viewport();
	QSize size = event->size();
	qOgreGL->resizeGL( size.width(), size.height() );
}
The result was a black window :( .
@machado

Here's an example I used some time back to test the original thread regarding switching contexts. I've only tested this on Linux 1.6/1.7 so it may need some modifications to run on windows. Anyway it may be of some use to you.
Ralith
Gnoblar
Posts: 11
Joined: Sun Mar 18, 2007 7:06 am

Re: Rendering QT widgets in Ogre

Post by Ralith »

I've successfully implemented this on Linux, only to discover that the performance is abysmal; calling glXMakeCurrent (or, presumably, wglMakeCurrent) eats up an immense amount of CPU time. I'm told it probably functions by copying the entire state between system and video memory. Anyone have any idea how to work around this?
machado
Gnoblar
Posts: 7
Joined: Mon Mar 02, 2009 4:46 pm
Location: Coimbra, Portugal

Re: Rendering QT widgets in Ogre

Post by machado »

It's working! :D

With the resizeGL function from Marseyeah that problem was solved, but it wasn't showing the graphic items, so i used the paintGL function from dermont and it's now shows everything.

I leave my test code (windows only) as another example:
QOgreGLWidget.zip
(3.95 KiB) Downloaded 374 times

Thanks Marseyeah and dermont for the help.
____________
Nuno Machado
machado
Gnoblar
Posts: 7
Joined: Mon Mar 02, 2009 4:46 pm
Location: Coimbra, Portugal

Re: Rendering QT widgets in Ogre

Post by machado »

Hi!

I'm trying to use the previous code (QOgreGLWidget.zip) in mac, with no success, I need help...

I opened a new post for this: http://www.ogre3d.org/forums/viewtopic. ... 25#p355125

Any help will be appreciated.
Thanks.
____________
Nuno Machado
BruceL
Gnoblar
Posts: 5
Joined: Sat Oct 24, 2009 5:11 am

Re: Rendering QT widgets in Ogre

Post by BruceL »

Hi all,
After much research, I've decided that I am going to try to get QT widgets to work in Ogre. First I'll try the new QPrintEngine that prints to an openGL surface. If that doesn't work, I may try to create my own QPrintEngine (if I can get help).

Either way, if anyone has any info that could save me time, let me know, and I'll keep anyone interested posted here.

Bruce
Meledith
Gnoblar
Posts: 11
Joined: Thu Apr 15, 2010 7:54 am

Re: Rendering QT widgets in Ogre

Post by Meledith »

Hi everyone,

I'm digging up this topic because I have some interest for rendering Qt Widgets in Ogre.
I was using QWidget for rendering my mesh, but for some quality considerations, I decided to now use QGLWidget.

I used an example posted here by dermont, but I have some troubles in refresh the scene. On a mouse event, I try to rotate the camera around the entity. This is working with a simple QWidget, but not in a subclass of QGLWidget, so I guess it's an error with the switching contexts: I'm doing the same thing for rotating the camera, so, no reason for failure, expect the refresh, in fact.

I have a poor experience of GlContext, so if someone could take a look on my paintGL(), it would be very usefull.
Of course, the function is correctly call when the mouse is moving.

Code: Select all

  void QOgreGLWidget::paintGL()
  {
  	makeOgreCurrent();

  	mRoot->_fireFrameStarted();
  	mRenderWindow->update( mSwapBuffers ); //update( false )

	if ( mouseLeftPressed )
	{
		camHorNode->yaw( Ogre::Degree( angleX * mMove ), Ogre::Node::TS_WORLD ) ;

		mYaw += Ogre::Degree( angleY * 0.001 ) ;

		camVerNode->setOrientation( Ogre::Quaternion( mYaw, Ogre::Vector3::NEGATIVE_UNIT_Z ) * Ogre::Quaternion( Ogre::Degree( 0 ), Ogre::Vector3::UNIT_X ) ) ;
	}
  	mRoot->_fireFrameEnded();

  	makeCurrent();
  	QGLWidget::paintGL();
  }
With a QWidget, I do the same manipulation between mRoot->_fireFrameStarted() and mRoot->_fireFrameEnded() (expect render update ), and rotation works. When I tried to change the material on the mesh, same thing, the mesh is never updated.

I call in the mouseMoveEvent for an update with updateWidget():

Code: Select all

void  QOgreGLWidget::updateWidget()
  {
  	update();
  	swapBuffers();
  }
So, I'm hoping someone have already seen similar thing and could help me solve it.

Thanks in advance
dermont
Bugbear
Posts: 812
Joined: Thu Dec 09, 2004 2:51 am
x 42

Re: Rendering QT widgets in Ogre

Post by dermont »

You are probably better using Qt's mouse*Events for handling the above. There are examples on the forum such as:

http://www.ogre3d.org/forums/viewtopic. ... ew#p374015

QtOgre Application Framework
http://www.ogre3d.org/forums/viewtopic. ... OgreWidget

It's been a while since I looked at this but I think the problem may be that
since the GLWidget is used as a background for the QGraphicsView then you need
to handle the mouse events from QGraphicsView (see attachment) e.g:

Code: Select all

QOgreGLGraphicsView

  protected:
    ..
    void mousePressEvent( QMouseEvent *e )
    {
        getOgreWidget()->mousePressEvent( e );
    }
    void mouseReleaseEvent( QMouseEvent *e )
    {
        getOgreWidget()->mouseReleaseEvent( e );
    }
    void mouseMoveEvent( QMouseEvent *e )
    {
        getOgreWidget()->mouseMoveEvent( e );
    }

void QOgreGLWidget::mousePressEvent( QMouseEvent *e )
{
   // do something
}
void QOgreGLWidget::mouseReleaseEvent( QMouseEvent * )
{
   // do something
}
void QOgreGLWidget::mouseMoveEvent( QMouseEvent *e )
{
   // do something
}
The switching of contexts was a hack to overcome the problems of the QWidgets not being shown. Someone posted code using an alternative method, you should maybe search the forums for that.
Meledith
Gnoblar
Posts: 11
Joined: Thu Apr 15, 2010 7:54 am

Re: Rendering QT widgets in Ogre

Post by Meledith »

Okay I get it.

I didn't really understand the link between GLWidget and QGraphicsView. Now everything works perfectly and I just added a switching context for modify the mesh's color on a mouse event.

Thank you =)
Neva Awaken
Gnoblar
Posts: 5
Joined: Thu Apr 15, 2010 5:45 am

Re: Rendering QT widgets in Ogre

Post by Neva Awaken »

Hi there, I got QOgreGLWidget.zip and tryed to run it here. I got some problems in the beggining, but I got it running.

What was expect to do? I'm getting only this:
Image
(click to enlarge if needed)

I'm uploading all the project, so it might help (for assistance and for newbies like me, who will not have to do the same work I did).

Was that right?? I'm not seeing the ninja, and the text is horrible. Can anyone help me? This is my first Ogre+QT running project.

Thanks!
Attachments
QOgreGLWidget_2.rar
Same as QOgreGLWidget, but including the Qt project and changed some things to compile with Qt 4.6.2
(228.62 KiB) Downloaded 197 times
pmax
Gnoblar
Posts: 16
Joined: Sun Aug 17, 2008 8:29 pm

Re: Rendering QT widgets in Ogre

Post by pmax »

While people seem to have found a way to do this already, there seems to be official interest from Qt as well:
http://labs.qt.nokia.com/2011/05/31/qml ... in-master/

Most notably, this video:
[youtube]b_3xfFuwGOQ[/youtube]

We only have to wait until Qt5 is released. :)
advancingu
Gnoblar
Posts: 11
Joined: Thu Nov 11, 2010 2:06 am
x 3

Re: Rendering QT widgets in Ogre

Post by advancingu »

For those interested, I published an updated version of QmlOgre at https://github.com/advancingu/QmlOgre . The update fixes a few issues and works with Qt 5.0.1.
Post Reply