OGRE in Qt?

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
Timothy May
Kobold
Posts: 30
Joined: Wed Jul 27, 2005 6:17 am

OGRE in Qt?

Post by Timothy May »

Has anyone had direct experience using ORGRE in the TrollTech Qt environment?

Thanks
Tim May
User avatar
monster
OGRE Community Helper
OGRE Community Helper
Posts: 1098
Joined: Mon Sep 22, 2003 2:40 am
Location: Melbourne, Australia
Contact:

Post by monster »

The search functionality doesn't really like "Qt" as a search term (I think it's too short). Nevertheless, I managed to use it successfully;

http://www.ogre3d.org/phpBB2/viewtopic.php?t=11803
http://www.ogre3d.org/phpBB2/viewtopic.php?t=5346
http://www.ogre3d.org/phpBB2/viewtopic.php?t=8421
Timothy May
Kobold
Posts: 30
Joined: Wed Jul 27, 2005 6:17 am

Post by Timothy May »

Thanks. The links are helpful.

BTW, How did you get the search to work?
Tim May
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

Use Google, perhaps:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

It dug up a thread, with a link to this:
http://sourceforge.net/projects/billygoat/ :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
ibrown
Gremlin
Posts: 164
Joined: Wed Aug 18, 2004 6:41 pm
Location: London
Contact:

Post by ibrown »

jacmoe wrote:It dug up a thread, with a link to this:
http://sourceforge.net/projects/billygoat/ :wink:
Yep - it's not changed for a while (been busy with lots of weddings this summer - 4 in two months and all in different countries) but it should work and show you how to embed an ogre window in a QT project. Although there is no download, the source is available in the CVS. I've just been too lazy to zip it up and upload it. Just use CVS to check it out.

Ian
Timothy May
Kobold
Posts: 30
Joined: Wed Jul 27, 2005 6:17 am

Post by Timothy May »

Ian,
I checked out and got the billygoat project working - it is interesting. I had done pretty much the same thing on my own but its always nice to do a sanity check.

BTW, I noticed that resize causes the image to "sqaush" etc. Here is a fix:
In OgreView:Resize

Change:

Code: Select all

m_camera->setAspectRatio(Ogre::Real(width()) / Ogre::Real(height()));
To:

Code: Select all

m_camera->setAspectRatio(Ogre::Real(m_vp->getActualWidth()) / Ogre::Real(m_vp->getActualHeight()));
I am not yet up to speed on Ogre so I'm not sure why you need to get the viewport width and height instead of the Qt window width and height - but there it is. BTW, this is the way they adjust for resize in the Ogre example application as well.

Thanks
Tim May
Timothy May
Kobold
Posts: 30
Joined: Wed Jul 27, 2005 6:17 am

Post by Timothy May »

Ian,
Opps. The "fix" needs a fix. As I played with this a bit more I realized that the real problem is that the viewport itself is not resizing. This became apparent when I added a few lines of code to allow me to use the keyboard to zoom in on the targeted node. The object was quickly big enough to exceed the boundaries of the viewport and get clipped. Basically, the viewport is where it always was. This also explains why the object does not recenter in the new, larger, window.

I've messed around a bit more in the code looking for the real issue. It's giving me a chance to get into the guts of the OGRE code. I'll let you know what I find!

Of course, being new at this codebase, I could be completely misguided - news at 11:00.
Tim May
Timothy May
Kobold
Posts: 30
Joined: Wed Jul 27, 2005 6:17 am

Post by Timothy May »

Ian,
Well, I found a "patch" to the OGRE code that fixes the problem. I'm not sure its the best fix - I'd have to leave that to the OGRE gurus. In the OgreWin32Window.cpp file we find the following code:

Code: Select all

	void Win32Window::resize(unsigned int width, unsigned int height)
	{
		if (mHWnd && !mIsFullScreen)
		{
			RECT rc = { 0, 0, width, height };
			AdjustWindowRect(&rc, GetWindowLong(mHWnd, GWL_STYLE), false);
			width = rc.right - rc.left;
			height = rc.bottom - rc.top;
			SetWindowPos(mHWnd, 0, 0, 0, width, height,
				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
			windowMovedOrResized(); //TM
		}
	}
Please note the windowMovedOrResized() call that I have added ie: //TM

This fixed the probelm for resizing our Qt window because windowMovedOrResized() does the following:

Code: Select all

	void Win32Window::windowMovedOrResized()
	{
		if (!isVisible())
			return;

		RECT rc;
		// top and left represent outer window position
		GetWindowRect(mHWnd, &rc);
		mTop = rc.top;
		mLeft = rc.left;
		// width and height represent drawable area only
		GetClientRect(mHWnd, &rc);

		if (mWidth == rc.right && mHeight == rc.bottom)
			return;

		mWidth = rc.right;
		mHeight = rc.bottom;

		// Notify viewports of resize
		ViewportList::iterator it, itend;
		itend = mViewportList.end();
		for( it = mViewportList.begin(); it != itend; ++it )
			(*it).second->_updateDimensions();
	}
I'm not sure if windowMovedOrResized() was supposed to get called from somewhere else but this little hack makes sure it gets called when it needs to be.
Tim May
Timothy May
Kobold
Posts: 30
Joined: Wed Jul 27, 2005 6:17 am

Post by Timothy May »

Ian,
It turns out that windowMovedOrResized is a member function of RenderWindow as well. This means we don't need the hack at all. Just
call m_render_window->windowMovedOrResized() in the resize member function in your application layer.

Duh - Anyway, reading the code was fun.

Regards,
Tim May
ibrown
Gremlin
Posts: 164
Joined: Wed Aug 18, 2004 6:41 pm
Location: London
Contact:

Post by ibrown »

Hi Tim, thanks for the feedback. I'll make that change as soon as I get some free time. I remember at the time I developed it, it took me a long time to get the window resizing working correctly. I think I had it so that it was ok under win32 and SDL/Linux but did not work correctly under glx / linux. From what you say Ogre has changed in the mean time (from 1.0.0).
I'll make your suggested change and give it a go on the 3 platforms. It will be great if it all works properly.

Ian
tisba
Kobold
Posts: 37
Joined: Sun Jan 26, 2003 1:17 am
Location: France (Paris)

Post by tisba »

I just posted a patch to the project to port it to Qt 4.

Qt 4 is available on all platform for free for GPL development.

The Qt/Win free project (http://sourceforge.net/projects/qtwin) provides a patch to compile Qt 4 Open Source Edition with Visual Studio and Borland C++.

Baptiste.
ibrown
Gremlin
Posts: 164
Joined: Wed Aug 18, 2004 6:41 pm
Location: London
Contact:

Post by ibrown »

tisba wrote:I just posted a patch to the project to port it to Qt 4.
Baptiste.
Hi tisba, thanks for the patch. At the moment I am really busy (dealing with a company take-over amongst other things) so I don't have much time for hobbies :)
If you like, I can give you cvs write privilages to this project and you can apply the patch yourself...

Ian
tisba
Kobold
Posts: 37
Joined: Sun Jan 26, 2003 1:17 am
Location: France (Paris)

Post by tisba »

Notes that the applying the patch will drop support for Qt3.

If this is not an issue for you, then I'm willing to integrate the patch. It would also be nice to release a tarball of the current source for Qt3 to make it more accessible (the anonymous sourceforge CVS was again having problem and I had to use a cvsview based client to get the source:-( ).

Baptiste.
gaboo
Gnoblar
Posts: 6
Joined: Mon Jun 12, 2006 3:12 pm
Contact:

Post by gaboo »

I'm starting a QT4 & hopefully OGRE based project.

Could you post the code needed to create an OGRE QGLWidget ?

Thank you ! :)

edit : ok, I've just found the sourgeforge project and the patch ! :)
I'll try this evenning. Thanks again!
Post Reply