QtOgre on Mac OS X?
-
- Gnoblar
- Posts: 18
- Joined: Thu Nov 30, 2006 3:32 am
QtOgre on Mac OS X?
Hi all,
Has anyone succeeded in embedding Ogre in a Qt window on the mac?
I have modified the QtOgre simple project, and it seems to want to compile except for this line:
params["externalWindowHandle"] = Ogre::StringConverter::toString((size_t)(HWND)winId());
What is the correct way to write that on OS X 10.4? HWND is Win32 dependent.
Thanks in advance! Regards,
-joshua
joshua@spacescience.com
Has anyone succeeded in embedding Ogre in a Qt window on the mac?
I have modified the QtOgre simple project, and it seems to want to compile except for this line:
params["externalWindowHandle"] = Ogre::StringConverter::toString((size_t)(HWND)winId());
What is the correct way to write that on OS X 10.4? HWND is Win32 dependent.
Thanks in advance! Regards,
-joshua
joshua@spacescience.com
- Game_Ender
- Ogre Magi
- Posts: 1269
- Joined: Wed May 25, 2005 2:31 am
- Location: Rockville, MD, USA
What version of Ogre are you using? Dagon 1.2 with the SDL, Dagon 1.2 with the Cocoa backends (Will's Framework), or are you using the 1.3 CVS version? To the best of my knowledge none of those version support the external/parent window handle methods. I am sure patches against head would be welcome. I might be wrong about the SDL ones, but I think SDL doesn't like to play nicely with others and many people have trouble using embedding Ogre using the SDL backend.
-
- Gnoblar
- Posts: 18
- Joined: Thu Nov 30, 2006 3:32 am
Hey,
Thanks for the follow-up.
I'm using Dagon, downloaded from the Ogre site, and the:
Dagon_Mac_Dependencies_10.4_Universal_v4
So it's impossible to do this with OS X for now? That's a *real* bummer.
Thanks again,
-joshua
joshua@spacescience.com
Thanks for the follow-up.
I'm using Dagon, downloaded from the Ogre site, and the:
Dagon_Mac_Dependencies_10.4_Universal_v4
So it's impossible to do this with OS X for now? That's a *real* bummer.
Thanks again,
-joshua
joshua@spacescience.com
-
- Gnoblar
- Posts: 18
- Joined: Thu Nov 30, 2006 3:32 am
Hi again,
I just spoke with Justin on Freenode, and he points out:
"...QT is carbon based, so this should be possible thanks to the carbon back end that is in development."
Does anyone have anything to add to this?
Thanks again! Best,
-joshua
joshua@spacescience.com
I just spoke with Justin on Freenode, and he points out:
"...QT is carbon based, so this should be possible thanks to the carbon back end that is in development."
Does anyone have anything to add to this?
Thanks again! Best,
-joshua
joshua@spacescience.com
-
- Gnoblar
- Posts: 24
- Joined: Wed Mar 28, 2007 10:47 am
I'm working with Ogre 1.4, and I can't manage to create a QT (4.2.3) widget embedding Ogre.
I've tried loads of combinations like :
params["externalWindowHandle"] = Ogre::StringConverter::toString((size_t)winId());
or, with Carbon :
params["externalWindowHandle"] = Ogre::StringConverter::toString(HIViewGetWindow(HIViewRef(winId()));
But none of them is working : the QT widget is always empty...
Has anyone been able to do something like that ??
I've tried loads of combinations like :
params["externalWindowHandle"] = Ogre::StringConverter::toString((size_t)winId());
or, with Carbon :
params["externalWindowHandle"] = Ogre::StringConverter::toString(HIViewGetWindow(HIViewRef(winId()));
But none of them is working : the QT widget is always empty...
Has anyone been able to do something like that ??
- JustinWalsh
- OGRE Retired Team Member
- Posts: 209
- Joined: Mon Sep 05, 2005 8:11 pm
- Location: Phoenix, AZ
- Contact:
The reason the Qt widget is empty is because Qt is taking over the context and hiding it. I had some discussion with the Qt folks and the response was to take a look at the QVTKWidget. This widget has some custom case code for the mac to allow the context to be displayed properly.
If you get something working please let me know, I haven't had the time to create the custom widget as of yet, but it is on my TODO list.
If you get something working please let me know, I haven't had the time to create the custom widget as of yet, but it is on my TODO list.
The blog: http://blog.trickyfly.com/
-
- Gnoblar
- Posts: 24
- Joined: Wed Mar 28, 2007 10:47 am
I didn't have time to post here before, but I managed to make my program work last week. I didn't use the QVTKWidget (as I haven't seen your post by then), and I had to modify Ogre Source to make it work.
In fact, if I use the following code to create the renderWindow :
params["externalWindowHandle"] = Ogre::StringConverter::toString((size_t)winId());
a_ogreRenderWindow = a_ogreRoot->createRenderWindow("View", width(), height(), true, ¶ms);
some very strange things happen : the QT widget is not empty, it loads the ogre display but only a part of it. And if I resize the widget, I notice that the Ogre display resizes as well, but inverted on the y axis.
Therefore, I had to modify the Ogre code so the resize goes well.
I did the following modification in OgreOSXCarbonWindow.cpp :
void OSXCarbonWindow::windowMovedOrResized()
{
// External windows will call this method.
if(mView != NULL)
{
//update our drawing region
::Rect ctrlBounds;
GetControlBounds(mView, &ctrlBounds);
//////////////////////////// working with all kind of windows including brushed metal window ////////////////////////
// compensate y inverted axis
HIRect viewBounds, winBounds;
HIViewGetBounds(mView, &viewBounds);
HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView));
HIViewRef content_root;
HIViewFindByID(root, kHIViewWindowContentID, &content_root);
HIViewGetBounds(content_root, &winBounds);
HIViewConvertRect(&viewBounds, mView, content_root);
GLint bufferRect[4] = { GLint(viewBounds.origin.x),
GLint((winBounds.size.height) - (viewBounds.origin.y + viewBounds.size.height)),
GLint(viewBounds.size.width),
GLint(viewBounds.size.height) };
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect);
aglEnable (mAGLContext, AGL_BUFFER_RECT);
swapBuffers(true);
mWidth = ctrlBounds.right - ctrlBounds.left;
mHeight = ctrlBounds.bottom - ctrlBounds.top;
mLeft = ctrlBounds.left;
mTop = ctrlBounds.top;
}
for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
{
(*it).second->_updateDimensions();
}
}
I found the code on the internet, and now my program works fine on OSX. It is not a proper solution, but at least it's working... If you have any idea why I get this strange behaviour, and a better way to solve it, please tell me !
In fact, if I use the following code to create the renderWindow :
params["externalWindowHandle"] = Ogre::StringConverter::toString((size_t)winId());
a_ogreRenderWindow = a_ogreRoot->createRenderWindow("View", width(), height(), true, ¶ms);
some very strange things happen : the QT widget is not empty, it loads the ogre display but only a part of it. And if I resize the widget, I notice that the Ogre display resizes as well, but inverted on the y axis.
Therefore, I had to modify the Ogre code so the resize goes well.
I did the following modification in OgreOSXCarbonWindow.cpp :
void OSXCarbonWindow::windowMovedOrResized()
{
// External windows will call this method.
if(mView != NULL)
{
//update our drawing region
::Rect ctrlBounds;
GetControlBounds(mView, &ctrlBounds);
//////////////////////////// working with all kind of windows including brushed metal window ////////////////////////
// compensate y inverted axis
HIRect viewBounds, winBounds;
HIViewGetBounds(mView, &viewBounds);
HIViewRef root = HIViewGetRoot(HIViewGetWindow(mView));
HIViewRef content_root;
HIViewFindByID(root, kHIViewWindowContentID, &content_root);
HIViewGetBounds(content_root, &winBounds);
HIViewConvertRect(&viewBounds, mView, content_root);
GLint bufferRect[4] = { GLint(viewBounds.origin.x),
GLint((winBounds.size.height) - (viewBounds.origin.y + viewBounds.size.height)),
GLint(viewBounds.size.width),
GLint(viewBounds.size.height) };
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
aglSetInteger(mAGLContext, AGL_BUFFER_RECT, bufferRect);
aglEnable (mAGLContext, AGL_BUFFER_RECT);
swapBuffers(true);
mWidth = ctrlBounds.right - ctrlBounds.left;
mHeight = ctrlBounds.bottom - ctrlBounds.top;
mLeft = ctrlBounds.left;
mTop = ctrlBounds.top;
}
for (ViewportList::iterator it = mViewportList.begin(); it != mViewportList.end(); ++it)
{
(*it).second->_updateDimensions();
}
}
I found the code on the internet, and now my program works fine on OSX. It is not a proper solution, but at least it's working... If you have any idea why I get this strange behaviour, and a better way to solve it, please tell me !
-
- Gnoblar
- Posts: 18
- Joined: Thu Nov 30, 2006 3:32 am
Ogre/Qt OSX Application
Hey Mans,
Is there any way I could see the full source code for your application?
(Or maybe you could put together a very simple app for us?)
Thanks in advance!! Best,
-joshua
Is there any way I could see the full source code for your application?
(Or maybe you could put together a very simple app for us?)
Thanks in advance!! Best,
-joshua
- djbe
- Gnoblar
- Posts: 6
- Joined: Tue Oct 23, 2007 4:05 am
Hey, I was wondering if anyone got this to work? Because I've been trying for a while, and only get a blank screen... I don't want to modify the ogre source code (I'm not the only person who is going to use this) and I tried taking a look at QVTKWidget but couldn't really get what they are doing (they also have a lot of compatibility code with older qt versions and such, which I don't need). Anyway, here is a piece of the code I'm using:
If needed, you can find all the code here: http://david.thesneaky.com/Test or more conveniently in a zip file here: http://david.thesneaky.com/Test.zip
Thanks in advance,
David
edit: Yes I searched before posting, here and on the qt-interest archive, and yes ogre itself works fine here (tested all the examples out of curiosity
)
Code: Select all
// Create the renderwindow
Ogre::NameValuePairList params;
#if defined(Q_WS_MAC)
WId wid = (size_t) HIViewGetWindow(HIViewRef(winId()));
#else
WId wid = winId();
#endif
params["externalWindowHandle"] = Ogre::StringConverter::toString((size_t) wid);
params["vsync"] = "no";
#if !defined(Q_WS_WIN)
char buf[64];
sprintf(buf, "SDL_WINDOWID=0x%lx", (size_t) HIViewGetWindow(HIViewRef(winId())));
putenv(buf);
#endif
m_renderWindow = m_ogreRoot->createRenderWindow("View", width(), height(), false, ¶ms);
// not sure if this part is needed:
WId ogreWinId = 0x0;
m_renderWindow->getCustomAttribute("WINDOW", &ogreWinId);
std::cout << "ogreWinId: " << ogreWinId << "\n";
// why is ogreWinId 0? it should have another value I think
create(ogreWinId);
Thanks in advance,
David
edit: Yes I searched before posting, here and on the qt-interest archive, and yes ogre itself works fine here (tested all the examples out of curiosity

-
- Gnoblar
- Posts: 18
- Joined: Thu Nov 30, 2006 3:32 am
We need...
Ogre/Qt on OS X!!!!
On strike!
-joshua
PS - maybe we could pool together and pay someone to come up with a reliable method? -j
On strike!
-joshua
PS - maybe we could pool together and pay someone to come up with a reliable method? -j
-
- Gnoblar
- Posts: 20
- Joined: Thu Nov 15, 2007 2:14 am
Neither Qt nor Ogre's source should be changed.
it works fine here.
I only add these code:
when create a widget for ogre rendering
and
to make a render window.
in the widget's paintEvent ask the Ogre::RenderWindow to update
it works fine here.
I only add these code:
Code: Select all
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
and
Code: Select all
Ogre::NameValuePairList pl;
pl["externalWindowHandle"]=Ogre::StringConverter::toString((size_t)winId());
QSize size=this->size();
window=root->createRenderWindow(windowName.toStdString(),size.width(),size.height(),false,&pl);
in the widget's paintEvent ask the Ogre::RenderWindow to update
- djbe
- Gnoblar
- Posts: 6
- Joined: Tue Oct 23, 2007 4:05 am
After fiddling around, I noted the following things:
and don't do anything...
Depending on which value I pass to externalWindowHandle, I get one of the following results:

Case 2:

In case 1, it seems everything is being rendered in the titlebar (weird). In case 2, you can't see anything (that's what I had). Oh, and using parentWindowHandle instead of externalWindowHandle creates a 2nd window behind the qt window, where I can see the correct ogre scene. Btw, here it is recommended to use HIViewGetWindow() and HIViewRef().
Code: Select all
#if !defined(Q_WS_WIN)
char buf[64];
sprintf(buf, "SDL_WINDOWID=0x%lx", (size_t) HIViewGetWindow(HIViewRef(winId())));
putenv(buf);
#endif
Code: Select all
WId ogreWinId = 0x0;
m_renderWindow->getCustomAttribute("WINDOW", &ogreWinId);
create(ogreWinId);
Depending on which value I pass to externalWindowHandle, I get one of the following results:
- winId() ==> Case 1
- dynamic_cast<QWidget*>(parent())->winId() ==> Case 1
- HIViewGetWindow(HIViewRef(winId())) ==> Case 2
- HIViewGetWindow(HIViewRef(dynamic_cast<QWidget*>(parent())->winId())) ==> Case 2

Case 2:

In case 1, it seems everything is being rendered in the titlebar (weird). In case 2, you can't see anything (that's what I had). Oh, and using parentWindowHandle instead of externalWindowHandle creates a 2nd window behind the qt window, where I can see the correct ogre scene. Btw, here it is recommended to use HIViewGetWindow() and HIViewRef().
- djbe
- Gnoblar
- Posts: 6
- Joined: Tue Oct 23, 2007 4:05 am
Aaaaaaaah, I just love what all nighters do for you... They just get things done 
meteors, you said you were gonna pay someone to come up with a reliable method? I'm a poor poor student and any money is welcome
So I've got qt and ogre working together here, without modifying ogre source code. The only steps you need to take are:
Notes:
- Linux and windows are untested. I added the compatibility code I found on the forums/wiki.
- This was tested on OSX 10.5.1 with Ogre 1.4.5

meteors, you said you were gonna pay someone to come up with a reliable method? I'm a poor poor student and any money is welcome

So I've got qt and ogre working together here, without modifying ogre source code. The only steps you need to take are:
- get the code here (or download the whole thing here for QOgreWidget (getting the .pro file is recommended)
- from the ogre source, add these files to the headers dir in the ogre framework: OgreGLContext.h, OgreGLPrerequisites.h and GL/glew.h . You'll find them in {ogresourcedir}/RenderSystems/GL/include. In my opinion this is a bug in the ogre compile xcodeproject, I mean why does for example 'OgreOSXContext.h' get copied (wich depends on ogreglcontext.h)??
- subclass the QOgreWidget class (like in TestWidget)
- done!
Notes:
- Linux and windows are untested. I added the compatibility code I found on the forums/wiki.
- This was tested on OSX 10.5.1 with Ogre 1.4.5
Last edited by djbe on Sat Jul 05, 2008 7:05 pm, edited 1 time in total.
-
- Gnoblar
- Posts: 18
- Joined: Thu Nov 30, 2006 3:32 am
Hey dude,
Nice going
(I hope it works on 10.4, but if it doesn't, no worries.)
Do you take PayPal? Please message me with your email address. I want to send you $20 right now. I know that's such a small amount as to almost be insulting, but its all I have at the moment. We can arrange more after the holidays, etc.
Again, I know its not a lot but maybe you can buy someone *something* for Christmas on Friday.
Thanks man!! Best,
-joshua
Nice going

(I hope it works on 10.4, but if it doesn't, no worries.)
Do you take PayPal? Please message me with your email address. I want to send you $20 right now. I know that's such a small amount as to almost be insulting, but its all I have at the moment. We can arrange more after the holidays, etc.
Again, I know its not a lot but maybe you can buy someone *something* for Christmas on Friday.
Thanks man!! Best,
-joshua
- djbe
- Gnoblar
- Posts: 6
- Joined: Tue Oct 23, 2007 4:05 am
lol I was just kidding
I don't want any money for it, just some feedback on it to see if it works correctly on all platforms. Oh and about Tiger, there shouldn't be any problems, as long as you follow the steps I explained (and check the .pro file for which things to add to your project file).
So if people could just check if this works on windows and linux (and tiger, but that one should work
), and maybe find a tip for the following: in the .pro file, I have to add this to the includepath:
INCLUDEPATH += /Library/Frameworks/Ogre.framework/Versions/A/
I was wondering if anyone knows of a better way to do this (it is needed because otherwise OgreGLPrerequisites.h complains. This could be fixed by changing the line #include <GL/glew.h> to #include "GL/glew.h" in that file

So if people could just check if this works on windows and linux (and tiger, but that one should work

INCLUDEPATH += /Library/Frameworks/Ogre.framework/Versions/A/
I was wondering if anyone knows of a better way to do this (it is needed because otherwise OgreGLPrerequisites.h complains. This could be fixed by changing the line #include <GL/glew.h> to #include "GL/glew.h" in that file
-
- Gnoblar
- Posts: 14
- Joined: Wed Dec 05, 2007 9:40 pm
*Here comes the linux guy!*
SWEET! I was about to start my own since I was disappointed with not finding a clean QOgreWidget around. I'm glad I gave the forums another look today:) The widget is very nice and reusable, so thanks a lot.
I made it work in Linux and this required small touches, mostly on the qmake file. Here is the patch, here is the patched tarball and here is my blog entry, with the explanations of the changes I made.
Again, thanks a lot. I also edited the QtOgre wiki page to add a link to here. http://www.ogre3d.org/wiki/index.php/QtOgre
SWEET! I was about to start my own since I was disappointed with not finding a clean QOgreWidget around. I'm glad I gave the forums another look today:) The widget is very nice and reusable, so thanks a lot.
I made it work in Linux and this required small touches, mostly on the qmake file. Here is the patch, here is the patched tarball and here is my blog entry, with the explanations of the changes I made.
Again, thanks a lot. I also edited the QtOgre wiki page to add a link to here. http://www.ogre3d.org/wiki/index.php/QtOgre
-
- Kobold
- Posts: 32
- Joined: Mon Nov 19, 2007 6:24 pm
- x 1
- xibo
- Gnoblar
- Posts: 16
- Joined: Wed Oct 10, 2007 9:26 pm
- Location: Tyrol, Austria
I've played around a little bit with the widget on my linux box. Now I have a question: Why does the Ogre widget must have a parent?
If there is no parent, this gives a seg fault. But it's not working with the following code either:
Maybe I should have posted more code ^^. Here it is:
Code: Select all
winHandle += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId()));
//this code is also on the wiki
Code: Select all
winHandle += Ogre::StringConverter::toString((unsigned long)(this->winId()));
edit:X Error: BadWindow (invalid Window parameter) 3
Major opcode: 18 (X_ChangeProperty)
Resource id: 0x400000a
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Extension: 144 (Uknown extension)
Minor opcode: 9 (Unknown request)
Resource id: 0x400000a
X Error: BadWindow (invalid Window parameter) 3
Major opcode: 40 (X_TranslateCoords)
Resource id: 0x400000a
Maybe I should have posted more code ^^. Here it is:
Code: Select all
void QOgreWidget::createRenderWindow() {
Ogre::NameValuePairList params;
if (m_renderWindow)
return;
configure(); //creates Ogre::Root
#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
params["externalWindowHandle"] = Ogre::StringConverter::toString((size_t) winId());
#else
QX11Info info = x11Info();
Ogre::String winHandle;
winHandle = Ogre::StringConverter::toString((unsigned long)(info.display()));
winHandle += ":";
winHandle += Ogre::StringConverter::toString((unsigned int)(info.screen()));
winHandle += ":";
winHandle += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId()));
// winHandle += Ogre::StringConverter::toString((unsigned long)(this->window()->winId()));
params["parentWindowHandle"] = winHandle;
#endif
m_renderWindow = m_ogreRoot->createRenderWindow(
"View" + Ogre::StringConverter::toString((unsigned long) this),
width(), height(), false, ¶ms);
#if defined(Q_WS_MAC)
// store context for hack
Ogre::OSXContext *context;
m_renderWindow->getCustomAttribute("GLCONTEXT", &context);
context->setCurrent();
m_aglContext = aglGetCurrentContext();
resizeRenderWindow();
#endif
// take over ogre window
#if !defined(Q_WS_MAC)
WId ogreWinId = 0x0;
m_renderWindow->getCustomAttribute("WINDOW", &ogreWinId);
assert(ogreWinId);
create(ogreWinId);
#endif
}
- shams
- Halfling
- Posts: 96
- Joined: Mon May 21, 2007 2:30 pm
-
- Gnoblar
- Posts: 5
- Joined: Sun Apr 27, 2008 12:51 pm
Try my patch mentioned here.shams wrote:hello!
I tried to run Qt and Ogre on my mac... Done with your program and indications. But I tried to run the famous "showMesh" program and I have an error with QX11Info.... Do you have any idea from where it could come?
Thank you very much
- shams
- Halfling
- Posts: 96
- Joined: Mon May 21, 2007 2:30 pm
hey!
I've got another big problem with the QOgreWidget. All works prefectly, except that my ogre widget is into a QTabWidget, and when i change the current tab, the Ogre widget is still displayed....!!
It seems that it is mac os related, because there is no bug under linux.
Have you the same problem?
I've got another big problem with the QOgreWidget. All works prefectly, except that my ogre widget is into a QTabWidget, and when i change the current tab, the Ogre widget is still displayed....!!
It seems that it is mac os related, because there is no bug under linux.
Have you the same problem?