Cutexture: Qt UIs in Ogre
-
- Gnoblar
- Posts: 11
- Joined: Thu Nov 11, 2010 2:06 am
- x 3
Cutexture: Qt UIs in Ogre
Hi,
Please allow me a shameless (but hopefully useful) plug for a new framework called Cutexture which integrates Qt User Interfaces into Ogre. Compared to previous Qt integrations for Ogre, one of its primary features is that it does not rely on widget overlays but instead renders Qt widgets into textures. If you're interested, read more here.
Cutexture is open source so please leave feedback or post patches on Github.
Thanks!
Please allow me a shameless (but hopefully useful) plug for a new framework called Cutexture which integrates Qt User Interfaces into Ogre. Compared to previous Qt integrations for Ogre, one of its primary features is that it does not rely on widget overlays but instead renders Qt widgets into textures. If you're interested, read more here.
Cutexture is open source so please leave feedback or post patches on Github.
Thanks!
- Assaf Raman
- OGRE Team Member
- Posts: 3092
- Joined: Tue Apr 11, 2006 3:58 pm
- Location: TLV, Israel
- x 76
Re: Cutexture: Qt UIs in Ogre
Nice work.
I had a look at your code, what you basically do is render QT into an image then update that image into an OGRE texture.
From the code I see you render a 32 bit qt image - meaning it has an alpha channel and transparency - am I right?
The biggest downside I see for your solution is that you need to constantly update a texture buffer, so this update can become a rendering bottleneck.
I am wandering - won't it be more efficient to render using QPaintEngine::OpenGL directly to a texture? This way all the updates will be done on the GPU side.
I am not an export on QT - so forgive me if this doesn't make sense.
I had a look at your code, what you basically do is render QT into an image then update that image into an OGRE texture.
From the code I see you render a 32 bit qt image - meaning it has an alpha channel and transparency - am I right?
The biggest downside I see for your solution is that you need to constantly update a texture buffer, so this update can become a rendering bottleneck.
I am wandering - won't it be more efficient to render using QPaintEngine::OpenGL directly to a texture? This way all the updates will be done on the GPU side.
I am not an export on QT - so forgive me if this doesn't make sense.
Watch out for my OGRE related tweets here.
- Assaf Raman
- OGRE Team Member
- Posts: 3092
- Joined: Tue Apr 11, 2006 3:58 pm
- Location: TLV, Israel
- x 76
Re: Cutexture: Qt UIs in Ogre
I think it can be done, your starting point in the QT source is this directory: qt-everywhere-opensource-src-4.7.1\src\opengl
There are two main ways to go about this the "right way" as far as I can see:
1. An OpenGL only solution - meaning adding an option for the OpenGL QT renderer to get an external context (from OGRE) and then using the existing code to render to texture. You can do the same for GL ES 1 and 2 if you are interested in mobile platforms.
2. Implement a new QPaintEngine::OGRE, longer way to go - but with this method you will not be limited to OpenGL, meaning you can render QT on DX, you will only need to maintain one code base for all the render platforms (dx, gl, gles 1,2) and the code will less of a "hack".
The files you should start from if you are interested in GL are:
qt-everywhere-opensource-src-4.7.1\src\opengl\qpaintengine_opengl.cpp
qt-everywhere-opensource-src-4.7.1\src\opengl\qglpixelbuffer_win.cpp
All the GL shaders are in this file (158 fragment programs):
qt-everywhere-opensource-src-4.7.1\src\opengl\util\fragmentprograms_p.h
and sadly as assembler programs (meaning a hard time converting them back to CG\HLSL\GLSL)
You can also have a look at this file:
qt-everywhere-opensource-src-4.7.1\src\opengl\gl2paintengineex\qglengineshadersource_p.h
It contains the GL ES 2.0 shaders, because GL ES 2 supports only GLSL (and not assembly shaders) - the shaders are much more readable, but note this remark at the end:
Meaning GL ES is not finished...
What do you think?
There are two main ways to go about this the "right way" as far as I can see:
1. An OpenGL only solution - meaning adding an option for the OpenGL QT renderer to get an external context (from OGRE) and then using the existing code to render to texture. You can do the same for GL ES 1 and 2 if you are interested in mobile platforms.
2. Implement a new QPaintEngine::OGRE, longer way to go - but with this method you will not be limited to OpenGL, meaning you can render QT on DX, you will only need to maintain one code base for all the render platforms (dx, gl, gles 1,2) and the code will less of a "hack".
The files you should start from if you are interested in GL are:
qt-everywhere-opensource-src-4.7.1\src\opengl\qpaintengine_opengl.cpp
qt-everywhere-opensource-src-4.7.1\src\opengl\qglpixelbuffer_win.cpp
All the GL shaders are in this file (158 fragment programs):
qt-everywhere-opensource-src-4.7.1\src\opengl\util\fragmentprograms_p.h
and sadly as assembler programs (meaning a hard time converting them back to CG\HLSL\GLSL)
You can also have a look at this file:
qt-everywhere-opensource-src-4.7.1\src\opengl\gl2paintengineex\qglengineshadersource_p.h
It contains the GL ES 2.0 shaders, because GL ES 2 supports only GLSL (and not assembly shaders) - the shaders are much more readable, but note this remark at the end:
Code: Select all
/*
Left to implement:
RgbMaskFragmentShader,
RgbMaskWithGammaFragmentShader,
MultiplyCompositionModeFragmentShader,
ScreenCompositionModeFragmentShader,
OverlayCompositionModeFragmentShader,
DarkenCompositionModeFragmentShader,
LightenCompositionModeFragmentShader,
ColorDodgeCompositionModeFragmentShader,
ColorBurnCompositionModeFragmentShader,
HardLightCompositionModeFragmentShader,
SoftLightCompositionModeFragmentShader,
DifferenceCompositionModeFragmentShader,
ExclusionCompositionModeFragmentShader,
*/
What do you think?
Watch out for my OGRE related tweets here.
- Assaf Raman
- OGRE Team Member
- Posts: 3092
- Joined: Tue Apr 11, 2006 3:58 pm
- Location: TLV, Israel
- x 76
Re: Cutexture: Qt UIs in Ogre
After looking more into the code, I see that all the GL GLSL shaders are in this directory: qt-everywhere-opensource-src-4.7.1\src\opengl\util
meaning the GL to OGRE port may be more simple the I wrote in my last post.
meaning the GL to OGRE port may be more simple the I wrote in my last post.
Watch out for my OGRE related tweets here.
- madmarx
- OGRE Expert User
- Posts: 1671
- Joined: Mon Jan 21, 2008 10:26 pm
- x 50
Re: Cutexture: Qt UIs in Ogre
I don't know this CutTexture, but I did the same : rendering the qwidget (or parts of it, or qgraphics things) into an image is very easy, and you got transparency. You just need to fill your image with 0 at the beginning.alpha channel and transparency - am I right?
The good part of it is that it is damn easy to do (at least for one widget), comparing to the other solutions.
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
- Assaf Raman
- OGRE Team Member
- Posts: 3092
- Joined: Tue Apr 11, 2006 3:58 pm
- Location: TLV, Israel
- x 76
Re: Cutexture: Qt UIs in Ogre
From looking more at the QT code, an option to have a native OGRE renderer for QT can be created without compiling all of QT.
QT has a plugin system. In order to have a native OGRE QT renderer - you needed to inherit QGraphicsSystem, name it QOgreGraphicsSystem, implement, then run QT with this new plug-in (look for "graphicssystem" in qt-everywhere-opensource-src-4.7.1\src\gui\kernel\qapplication.cpp for more info).
I am becoming sure that this is technically possible, it is a sort of a classic GL to OGRE port work.
The benefits of such can help both projects, QT will get the option to render with all OGRE render systems, and OGRE will get an option to have great native high performance GUI.
The biggest downside I see now for using QT is that it uses LGPL license - meaning QT can never be used on the iPhone or platforms, I don't see on the QT site even an option to pay for the right to use it on the iPhone.
QT has a plugin system. In order to have a native OGRE QT renderer - you needed to inherit QGraphicsSystem, name it QOgreGraphicsSystem, implement, then run QT with this new plug-in (look for "graphicssystem" in qt-everywhere-opensource-src-4.7.1\src\gui\kernel\qapplication.cpp for more info).
I am becoming sure that this is technically possible, it is a sort of a classic GL to OGRE port work.
The benefits of such can help both projects, QT will get the option to render with all OGRE render systems, and OGRE will get an option to have great native high performance GUI.
The biggest downside I see now for using QT is that it uses LGPL license - meaning QT can never be used on the iPhone or platforms, I don't see on the QT site even an option to pay for the right to use it on the iPhone.
Watch out for my OGRE related tweets here.
- madmarx
- OGRE Expert User
- Posts: 1671
- Joined: Mon Jan 21, 2008 10:26 pm
- x 50
Re: Cutexture: Qt UIs in Ogre
Concerning qt/iphone, this is what I understood :
Qt is a nokia's product (cell phones etc...).
Iphone is an Apple's product.
For that reason, Qt has obviously no intention of supporting the iphone openly. There are dissident projects on the web for qt iphone, but even if you provide a perfect qt-iphone implementation, it is likely to be refused for qt trunk integration.
Qt cross platform? Not exactly the same meaning, as what I consider cross platform.
Qt is a nokia's product (cell phones etc...).
Iphone is an Apple's product.
For that reason, Qt has obviously no intention of supporting the iphone openly. There are dissident projects on the web for qt iphone, but even if you provide a perfect qt-iphone implementation, it is likely to be refused for qt trunk integration.
Qt cross platform? Not exactly the same meaning, as what I consider cross platform.
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
-
- Gnoblar
- Posts: 11
- Joined: Thu Nov 11, 2010 2:06 am
- x 3
Re: Cutexture: Qt UIs in Ogre
Hi all,
thanks for the replies.
@Assaf
The image rendered has 32bits, so you have full alpha channel support. You are correct that updating a texture buffer can become a bottleneck, therefore the texture is only updated if there was a change in the UI (e.g. moving the mouse over a non-changing area causes no update). If you have non-animated UIs, I believe this should be fast enough. If someone has a better way to get Qt into Ogre, I'd be happy to hear it. However, if I understand it correctly, writing a QGraphicsSystem extension which integrates Ogre into Qt (the other way round than Cutexture) would remove the ability to have Qt output applied as a texture to objects but with the advantage of having faster performance.
@madmarx
I don't think Nokia would openly oppose iPhone development since if you write for Qt (even when targeting Qt on the iPhone), you would at the same time be writing something that could easily be released on a Nokia device as well. I would bet you will face more problems releasing a Qt app on the Apple AppStore because of their restriction on the tools you may use.
thanks for the replies.
@Assaf
The image rendered has 32bits, so you have full alpha channel support. You are correct that updating a texture buffer can become a bottleneck, therefore the texture is only updated if there was a change in the UI (e.g. moving the mouse over a non-changing area causes no update). If you have non-animated UIs, I believe this should be fast enough. If someone has a better way to get Qt into Ogre, I'd be happy to hear it. However, if I understand it correctly, writing a QGraphicsSystem extension which integrates Ogre into Qt (the other way round than Cutexture) would remove the ability to have Qt output applied as a texture to objects but with the advantage of having faster performance.
@madmarx
I don't think Nokia would openly oppose iPhone development since if you write for Qt (even when targeting Qt on the iPhone), you would at the same time be writing something that could easily be released on a Nokia device as well. I would bet you will face more problems releasing a Qt app on the Apple AppStore because of their restriction on the tools you may use.
-
- Gnoblar
- Posts: 11
- Joined: Thu Nov 11, 2010 2:06 am
- x 3
Re: Cutexture: Qt UIs in Ogre
I just came by http://www.ogre3d.org/tikiwiki/List+Of+Libraries while searching for a library. Does anyone want to add Cutexture there under the GUI section? It might be helpful for people looking for another Ogre GUI alternative.
-
- Gnoblar
- Posts: 11
- Joined: Thu Nov 11, 2010 2:06 am
- x 3
Re: Cutexture: Qt UIs in Ogre
Just an update that Cutexture is now a library. I refactored the code and split the game-specific code into a separate example. Hopefully this makes is more useful for others. I'll add more documentation over the next days to describe how to use it in other projects. Should be relatively straightforward though even without specific documentation as the library just consists of two classes that developers need to interact with.
Get the code on Github or watch a short video of Cutexture in action on my blog.
Get the code on Github or watch a short video of Cutexture in action on my blog.
-
- Gnoblar
- Posts: 11
- Joined: Fri Sep 05, 2008 10:46 am
Re: Cutexture: Qt UIs in Ogre
It could be great to be able to render QT GUI into texture (which can be applied to a mesh) and use it like scaleform.
QT has a web browser and QT Quick seems to be able to create interesting things similar to Flash.
I hope you will continue and share your work !
QT has a web browser and QT Quick seems to be able to create interesting things similar to Flash.
I hope you will continue and share your work !
-
- Gnoblar
- Posts: 11
- Joined: Thu Nov 11, 2010 2:06 am
- x 3
Re: Cutexture: Qt UIs in Ogre
Hi Texel, Thanks for your feedback.
In the latest version you should already be able to render Qt widgets into any Ogre texture, so if you want to have e.g. Google or Facebook pages showing on the surface of any object in your 3D application/game, that should be no problem. QML should also be possible already if you use a QDeclarativeView as a widget.
Let me know if something doesn't work for you and I'll look into it.
In the latest version you should already be able to render Qt widgets into any Ogre texture, so if you want to have e.g. Google or Facebook pages showing on the surface of any object in your 3D application/game, that should be no problem. QML should also be possible already if you use a QDeclarativeView as a widget.
Let me know if something doesn't work for you and I'll look into it.
-
- Gnoblar
- Posts: 3
- Joined: Sun Jan 30, 2011 2:09 pm
Re: Cutexture: Qt UIs in Ogre
for me the good way is to provide an ogre3D backend to scenegraph (the coming new Qt backend for Qml) : see here :
http://labs.qt.nokia.com/2011/03/22/the ... ene-graph/
If we have the way to render (with full acceleration ... not cpu rendering qt widget, copy to image, then copy to buffer) a qml scene in an ogre3D texture ... it will rocks ... easy UI and good look, possibility to embed any 2D qml contents has a texture on Ogre3D....
http://labs.qt.nokia.com/2011/03/22/the ... ene-graph/
If we have the way to render (with full acceleration ... not cpu rendering qt widget, copy to image, then copy to buffer) a qml scene in an ogre3D texture ... it will rocks ... easy UI and good look, possibility to embed any 2D qml contents has a texture on Ogre3D....
-
- Gnoblar
- Posts: 8
- Joined: Sat Jul 25, 2009 10:05 pm
- Location: Oslo, Norway
Re: Cutexture: Qt UIs in Ogre
I did some experimentation on integrating Ogre with the QML Scene Graph
The repository is here: https://qt.gitorious.org/qt-labs/qmlogre
To compile the project:
- first you need to pull and compile Qt from the qml-team/qtquick2 branch of http://qt.gitorious.org/+qt-developers/qt/staging/
- set the OGRE_HOME environment variable
- qmake && make
What it does is that it renders Ogre in a framebuffer object then render the texture with the rest of the QML scene. No intermediate Image, no texture upload, the whole thing should be fast.
EDIT: I only tried on Linux, I don't know if it works on Windows or Mac.
EDIT2: I fixed the build on Windows and it also works fine on this platform.
The repository is here: https://qt.gitorious.org/qt-labs/qmlogre
To compile the project:
- first you need to pull and compile Qt from the qml-team/qtquick2 branch of http://qt.gitorious.org/+qt-developers/qt/staging/
- set the OGRE_HOME environment variable
- qmake && make
What it does is that it renders Ogre in a framebuffer object then render the texture with the rest of the QML scene. No intermediate Image, no texture upload, the whole thing should be fast.
EDIT: I only tried on Linux, I don't know if it works on Windows or Mac.
EDIT2: I fixed the build on Windows and it also works fine on this platform.
Last edited by Marseyeah on Mon May 02, 2011 4:02 pm, edited 1 time in total.
-
- Gnoblar
- Posts: 8
- Joined: Sat Jul 25, 2009 10:05 pm
- Location: Oslo, Norway
Re: Cutexture: Qt UIs in Ogre
Here's a video of it working on Linux:
http://www.youtube.com/watch?v=b_3xfFuwGOQ
http://www.youtube.com/watch?v=b_3xfFuwGOQ
-
- Gnoblar
- Posts: 7
- Joined: Thu Dec 20, 2007 12:16 pm
Re: Cutexture: Qt UIs in Ogre
This looks very cool. Will it have a noticeable impact on performance? Is Qt able to create "real" fullscreen applications? I'm currently starting to learn some QML-stuff and I think there would be some nice possibilities with QML to create an userinterface for some little Ogre-project I want work on.
-
- Gnoblar
- Posts: 2
- Joined: Mon Jun 13, 2011 2:47 am
Re: Cutexture: Qt UIs in Ogre
I am not sure about the performance impact of rendering the Ogre scene into a FBO. While the current repository won't be able to use "real" full screen mode, in one of the blog posts a Qt developer stated that the new scene graph implementation will simply use native OpenGL drawing calls and draw basically into anything as long as an OpenGL context is given (it shouldn't care where that comes from). The whole thing still seems to be in development, but if I understood the blog post about Qt5/lighthouse correctly, the entire QWidget stack won't be necessary to use QML/SceneGraph. This means: You get QML with native OpenGL2 rendering (no wrapper). While the current version still forces you to use a QGLWidget, that should be remedied until the end of 2011, when beta quality code for Qt5 should become available (according to their roadmap).Speculi wrote:This looks very cool. Will it have a noticeable impact on performance? Is Qt able to create "real" fullscreen applications? I'm currently starting to learn some QML-stuff and I think there would be some nice possibilities with QML to create an userinterface for some little Ogre-project I want work on.
I guess the steps you would still need to perform (or rather, any interation layer would need to perform) are:
- Setting up Qt/SceneGraph to use the OpenGL context it should render in.
- Disabling the threaded renderer would be required I guess.
- Set the viewport size for the scene graph.
- Translate and push user input events into QApplication (since the root window isn't owned by Qt)
- When the user interface should be drawn (callback function from the main rendering loop), process queued QApplication events, then call the paintEvent method for QSGView directly.
I really hope these issues are resolved on the Qt side and I will try to make the Game UI use case known to the Qt developers. While it's certainly nice to embed Ogre into QML, I guess the more interesting (and serious) use case would be embedding QML into Ogre. In my personal opinion, there's no really good (& free) alternative to Scaleform right now. QML would be a great contender for this.
Regards,
Sebastian
ps: Please vote for the feature request that would allow the QML scene to be render into an FBO.
-
- Gnoblar
- Posts: 11
- Joined: Thu Nov 11, 2010 2:06 am
- x 3
Re: Cutexture: Qt UIs in Ogre
Digging this thread out again with a brief update: I've modified the qmlogre example that was created by Nokia to build with the latest Qt 5.0.1 without using private Qt headers. Essentially this code has Ogre render into an FBO which is then integrated into a QML scene as a textured item. In other words, Qt manages the visible window as well as events and it is Ogre that renders into a texture. More infos on my blog at AdvancingUsability.
-
- Gnoblar
- Posts: 15
- Joined: Wed Aug 03, 2011 6:21 pm
Re: Cutexture: Qt UIs in Ogre
Hello. I have compiled Cutexture with Ogre 1.8.2 and Qt 4.8.4. With OpenGL renderer all OK, controls shows perfectly. But on DirectX i have blured image(see attachment). Where problem can be?
-
- Gnoblar
- Posts: 15
- Joined: Wed Aug 03, 2011 6:21 pm
Re: Cutexture: Qt UIs in Ogre
We need change Rectangle2D position to manage texel-to-pixel mapping in DirectX to solve problem in previous post. I used such code:
Code: Select all
Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
const Ogre::Viewport* vp = ViewManager::getSingletonPtr()->getPrimaryViewport();
Ogre::Real hOffset = rs->getHorizontalTexelOffset() / (0.5 * vp->getActualWidth());
Ogre::Real vOffset = rs->getVerticalTexelOffset() / (0.5 * vp->getActualHeight());
Ogre::Rectangle2D *miniScreen = new Ogre::Rectangle2D(true);
miniScreen->setCorners(-1.0 + hOffset, 1.0 - vOffset, 1.0 + hOffset, -1.0 - vOffset);
miniScreen->setBoundingBox(Ogre::AxisAlignedBox(-100000.0 * Ogre::Vector3::UNIT_SCALE,
100000.0 * Ogre::Vector3::UNIT_SCALE));
miniScreen->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
-
- Gnoblar
- Posts: 20
- Joined: Sat Mar 05, 2011 7:57 pm
Re: Cutexture: Qt UIs in Ogre
i suppose good stuff like context menus wont work with this right?
-
- Gnoblar
- Posts: 11
- Joined: Thu Nov 11, 2010 2:06 am
- x 3
Re: Cutexture: Qt UIs in Ogre
Check my new project QmlOgre for a more flexible way to integrate Ogre and Qt. Anything you can do with QML is possible there in terms of UI.rndbit wrote:i suppose good stuff like context menus wont work with this right?
-
- Gnoblar
- Posts: 20
- Joined: Sat Mar 05, 2011 7:57 pm
Re: Cutexture: Qt UIs in Ogre
i saw it but i stepped back due to very same reason - doubt that menus will work. do they? what about full screen mode? does it work too? seems like qt owns the world there..advancingu wrote:Check my new project QmlOgre for a more flexible way to integrate Ogre and Qt. Anything you can do with QML is possible there in terms of UI.rndbit wrote:i suppose good stuff like context menus wont work with this right?