Best way to handle GUI rendering in Ogre?

Problems building or running the engine, queries about how to use features etc.
AusSkiller
Gremlin
Posts: 158
Joined: Wed Nov 28, 2012 1:38 am
x 13

Best way to handle GUI rendering in Ogre?

Post by AusSkiller »

I'm getting to the stage where I'd like to scrap the GUI system I'd been using from the samples and start making a real GUI for my game, but I'd just like to get a few opinions from people who are more familiar with the use of Ogre on what the best way to handle rendering a GUI is in Ogre. I've written GUIs before but they were using raw OpenGL so I was very easily able to just keep filling a VBO with the GUI elements until the buffer was full or I needed a state change (different material) at which point I just flush that buffer to render and switch to a secondary buffer that I could start to fill while the first is potentially still rendering. In Ogre I'm not sure exactly how to approach doing the same thing as Ogre seems to prefer to handle the render order and draw calls it's self, and that being the case I'm thinking that perhaps there's a better method I should use in Ogre instead. I'm also not particularly interested in using existing UI libraries, I always find they don't do some fundamental thing I would like and it's never easy to try to cram such features into existing systems, and given it only takes me a week or two to knock out a purpose built functional UI anyway it's usually not worth using existing libraries.

I'd appreciate any thoughts on the matter, thanks :)

Edit:
I would also like to hear about rendering text in ways other than the simple bitmap font method I've used in the past as I may want to handle languages that have too many characters for bitmap fonts to be a viable solution, though I guess that's less of an Ogre issue.
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Best way to handle GUI rendering in Ogre?

Post by bstone »

Since Ogre is a general purpose 3D rendering engine you won't be able to issue one render call while you prepare another one. But if that's critical to your UI then you should consider a 2D engine with a bit of 3D stuff added instead :)

If you're fine with Ogre having control over that then have a look at Gorilla. It's a lightweight library for 2D rendering in Ogre. You should be able to do whatever UI you want with that without limiting yourself too much.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Best way to handle GUI rendering in Ogre?

Post by jacmoe »

AusSkiller wrote:.. it only takes me a week or two to knock out a purpose built functional UI anyway it's usually not worth using existing libraries.
Harh, harh! :mrgreen:

Actually, this is exactly what people have reinvented the most during the last couple of years.
There are tons of discussions - and code - for Ogre based GUIs.

I am intrigued: what exactly is it you need from existing Ogre based GUIs that they don't give you?

Could you give a list of those you have tried?
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Best way to handle GUI rendering in Ogre?

Post by bstone »

jacmoe wrote:I am intrigued: what exactly is it you need from existing Ogre based GUIs that they don't give you?
I guess we should see a video capture of the working demo in less than a week now? :wink:
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Best way to handle GUI rendering in Ogre?

Post by bstone »

And yeah... this one is not getting any older yet:

Image
User avatar
Daixiwen
Greenskin
Posts: 105
Joined: Fri Feb 08, 2013 11:30 am
Location: Oslo
x 16

Re: Best way to handle GUI rendering in Ogre?

Post by Daixiwen »

Or this one from xkcd ;)

Image
AusSkiller
Gremlin
Posts: 158
Joined: Wed Nov 28, 2012 1:38 am
x 13

Re: Best way to handle GUI rendering in Ogre?

Post by AusSkiller »

bstone wrote:Since Ogre is a general purpose 3D rendering engine you won't be able to issue one render call while you prepare another one. But if that's critical to your UI then you should consider a 2D engine with a bit of 3D stuff added instead :)
Nah it's not critical for the UI at all, in my previous UI system 99 times out of 100 it had finished rendering before anything else would have been added to the buffer anyway so a blocking call wouldn't have had much impact on performance anyway.
bstone wrote:If you're fine with Ogre having control over that then have a look at Gorilla. It's a lightweight library for 2D rendering in Ogre. You should be able to do whatever UI you want with that without limiting yourself too much.
Looks a bit basic for all my UI needs, but it might offer a solution for text rendering (though I'll have to look into it further to be sure), because as I mentioned I'm not keen on using bitmap fonts again and haven't looked into font renders much yet.
jacmoe wrote:
AusSkiller wrote:.. it only takes me a week or two to knock out a purpose built functional UI anyway it's usually not worth using existing libraries.
Harh, harh! :mrgreen:
No that's really all it takes me to program a *purpose built* *functional* UI, obviously it wouldn't have anywhere near the same level of functionality that a third party library would, but it would be capable of pretty much everything I'd need. And it only takes a week or two to get it functional, but that wouldn't be complete, it takes more time for me to polish it up, fix bugs and add a few additional features here and there but that's just work I can do as needed throughout the rest of the project and it takes a lot less time to do when I write all the code myself compared to when I need to change or add something to a third party library.
jacmoe wrote:I am intrigued: what exactly is it you need from existing Ogre based GUIs that they don't give you?
The main thing that I keep running into is the mixing of different coordinate types, sometimes I will want to specify the width of an element as a percentage of parent size, but other times as percentage of screen size, fixed pixel size, reference scaled size independent of aspect ratio, reference scaled size dependent on aspect ratio or even DPI based size. Most UIs don't support different all those coordinate types so I always end up needing to write code to do the conversions for many of the elements to get the desired results which kind of ruins the point of having a data driven UI (which is another thing I want). Android's UI system does a fairly decent job of this sort of thing but there were a few times when I needed coordinate types it didn't support.

I also like using anchor points so I can lock parts of the UI to specified places on the screen, being able to use render textures so I can have 3D models displayed in the UI, fully customizable graphics including the ability to use my own shaders, and a pretty full compliment of elements (buttons, toggles, radio buttons, labels, text entry, check buttons, spinners, combo boxes, sliders, scroll bars, scrollable lists, tab controls, tables, ect.) though I can probably get by without multi-line text entry for this game.
jacmoe wrote:Could you give a list of those you have tried?
I haven't tried any Ogre UIs yet because I want more information so I can make a better decision on how to proceed, but many of the UIs I briefly looked at didn't seem to have what I wanted anyway. CEGUI looked OK but I didn't see any indication that it supported all the coordinates types I like to use :(.
bstone wrote:And yeah... this one is not getting any older yet:
Haha, yeah I know, I'm often guilty of re-writing stuff unnecessarily, my colleagues often refer to the time I re-wrote printf because I felt Microsoft's implementation might be slow and it wasn't entirely thread safe, I spent ages working on it even though I knew printf would have been perfectly acceptable, but at least in the end I had an equivalent function that was completely thread safe and many times faster in pretty much all cases. I'm just more comfortable and much more productive when I'm using my own code, I figured I'd make an exception for the rendering engine because Ogre had a lot of features I really couldn't be bothered writing myself in such a robust manner, but UIs are much easier and quicker to code when they are purpose built so I'd rather not use a library unless it already has pretty much everything I intend to use built in.
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Best way to handle GUI rendering in Ogre?

Post by bstone »

Alright, alright. You have your week now for the multiple coordinate types, anchors, and the full compliment of elements. No need to thank me :D
AusSkiller
Gremlin
Posts: 158
Joined: Wed Nov 28, 2012 1:38 am
x 13

Re: Best way to handle GUI rendering in Ogre?

Post by AusSkiller »

bstone wrote:Alright, alright. You have your week now for the multiple coordinate types, anchors, and the full compliment of elements. No need to thank me :D
Yeah but the problem remains, what is the best way render it in Ogre? I mean I suppose I could probably just use manual objects, I could certainly get the job done quickly that way and with an orthographic projection and using depth on the scene node position I suppose that would ensure correct render order but surely there's a better way to do it.

Also I'm not actually up to putting in the UI stuff yet, I'm in the middle of refactoring what I have and documenting the code a bit better (doxygen), but I suppose I could post when I start on the UI and put up a screenshot/video of what I have two weeks later, it might actually serve as good motivation to not slack off as much as I currently do ;).
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Best way to handle GUI rendering in Ogre?

Post by bstone »

Have a quick glance at the Overlays plugin. That will answer some of your questions.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Best way to handle GUI rendering in Ogre?

Post by jacmoe »

Go with Gorilla, it has been used as a base for at least one GUI using Ogre.
Betajaen made Gorilla which is the successor of Betagui, one of the first truly minimal GUIs for Ogre.
It simply can't get any more minimal than that.
/* 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

Re: Best way to handle GUI rendering in Ogre?

Post by jacmoe »

Betagui was what really started this chain reaction of reinventing the GUI wheels. :)

Start here:
http://www.ogre3d.org/tikiwiki/tiki-ind ... on+of+GUIs

That list is totally incomplete, btw. ;)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
AusSkiller
Gremlin
Posts: 158
Joined: Wed Nov 28, 2012 1:38 am
x 13

Re: Best way to handle GUI rendering in Ogre?

Post by AusSkiller »

jacmoe wrote:Go with Gorilla, it has been used as a base for at least one GUI using Ogre.
Betajaen made Gorilla which is the successor of Betagui, one of the first truly minimal GUIs for Ogre.
It simply can't get any more minimal than that.
I got to admit I do like minimal + open source, I'll investigate it further, as long as it's hardware accelerated I'm sure I'll be able to bend it to my needs, but not sure if it'll be worth all the extra time spent trying to figure it out, but I guess since I'm not really on the clock time isn't such a big deal and I do know how much better it is to use a well tested library than it is to just write it myself and hope I didn't miss any bugs.
That's exactly where I started looking before creating this thread, but none really jumped out as being a great solution for my needs though, CEGUI looked good but also a little too developed to easily modify if I needed to, but I did only briefly look at each. I'll have a proper look into Gorilla to see how that works and if it'll do for what I want.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Best way to handle GUI rendering in Ogre?

Post by jacmoe »

There are lots of people who are really happy with myGUI. :)
If you haven't, check it out.
-> http://mygui.info/
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
AusSkiller
Gremlin
Posts: 158
Joined: Wed Nov 28, 2012 1:38 am
x 13

Re: Best way to handle GUI rendering in Ogre?

Post by AusSkiller »

Oh sweet, I just noticed the RenderSystem stuff that Gorilla is using, it looks like that could give me access to the lower level graphics operations that I'm more used to dealing with, with a bit more reading into that I might have found the answer to my problems and be able to manually control the rendering of the UI :D. I also noticed that Gorilla seems to use bitmap fonts which is disappointing, I might have to find a different library to handle font rendering :(.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Best way to handle GUI rendering in Ogre?

Post by jacmoe »

TwOgreGui uses direct API calls (DirectX/OpenGL) take a look at the code:
https://bitbucket.org/jacmoe/twogregui
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58

Re: Best way to handle GUI rendering in Ogre?

Post by betajaen »

It really is difficult to write a GUI.

Fine; buttons, sliders and text boxes (to an extent) are easy (providing you have a good 2D drawing layer) - but when it comes to more complicated UI then it gets excessive, it can be just as big as your program.

I mean, you picked to use Ogre than using DirectX and OpenGL? Why not do the same for a GUI library?


p.s. Bitmap fonts aren't too bad, if you want a scalable font - then Valve solved this with Signed Distance Fields. ;)
AusSkiller
Gremlin
Posts: 158
Joined: Wed Nov 28, 2012 1:38 am
x 13

Re: Best way to handle GUI rendering in Ogre?

Post by AusSkiller »

betajaen wrote:It really is difficult to write a GUI.

Fine; buttons, sliders and text boxes (to an extent) are easy (providing you have a good 2D drawing layer) - but when it comes to more complicated UI then it gets excessive, it can be just as big as your program.
I tend to find GUI code is usually rather easy to write, the only part that gives me any difficulty is text, though bitmap fonts usually make that a non-issue. Of course this time I'm thinking I may try not using bitmap fonts so that could be a lot more tricky than I'm estimating, but at least the rest I should be able breeze through pretty quickly. Of course since I'd be making a purpose built UI for this one game rather than a general purpose library I can take a heap of shortcuts skipping a lot of common features of UIs that I know I'm not going to need in this game.
betajaen wrote:I mean, you picked to use Ogre than using DirectX and OpenGL? Why not do the same for a GUI library?
I know, but third party libraries can limit what you can do and you may be using it too extensively to do anything about it when you actually realize the limitation, but if you write stuff yourself you can pretty much guarantee you can do everything you want. I'm willing to use libraries for things that would take considerable effort to write myself, like the graphics engine, audio, and the physics engine (though I'm not sure I'll need a physics engine in this game), but for something like UI that I'll have little trouble writing myself I'd rather not deal with the potential limitations of a library.
betajaen wrote:p.s. Bitmap fonts aren't too bad, if you want a scalable font - then Valve solved this with Signed Distance Fields. ;)
Yeah I read about that ages ago, quite an interesting solution to that sort of thing, but the real problem with bitmap fonts is language support, if I wanted to support Asian languages there are FAR too many characters for bitmap fonts to be viable (I think there are over 100,000 characters in Chinese alone, though I suspect they have a simplified set for use on computers). It's not a deal breaker though, if it looks like a it'll be a lot of effort to support large character sets then I'll just use bitmap fonts which should be fine for most European languages at least.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Best way to handle GUI rendering in Ogre?

Post by jacmoe »

Can't wait to see that earthshatteringly awesome GUI you are going to cook up.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Re: Best way to handle GUI rendering in Ogre?

Post by syedhs »

Finish the games first, then only you worry the nitty gritty details.. :mrgreen:
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
AusSkiller
Gremlin
Posts: 158
Joined: Wed Nov 28, 2012 1:38 am
x 13

Re: Best way to handle GUI rendering in Ogre?

Post by AusSkiller »

jacmoe wrote:Can't wait to see that earthshatteringly awesome GUI you are going to cook up.
I think you may have the wrong idea about what I intend to do, I'm only going to be making a rather basic UI, nothing ground breaking, it'll just have a few features that make it easier/quicker for me to set up the UI layouts, and a few minor back end conveniences like basic nine patch support, other than that it'll be a very run of the mill, unspectacular UI, that's why I know I can get it done relatively quickly.
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Best way to handle GUI rendering in Ogre?

Post by bstone »

Any updates? :)
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Best way to handle GUI rendering in Ogre?

Post by jacmoe »

Judging by the date, it's show time. :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
AusSkiller
Gremlin
Posts: 158
Joined: Wed Nov 28, 2012 1:38 am
x 13

Re: Best way to handle GUI rendering in Ogre?

Post by AusSkiller »

Haven't started on the UI yet, was doing some more back end work like integrating Bullet so I can do some more efficient ray casting, I've also been refactoring/documenting code and cleaning up a heap of code that I'd been using for testing and is either no longer needed or that I needed to be able to be #ifdef out (like code for data structure visualization), but I'll probably start on the UI code in the next few days. However be prepared to be underwhelmed when I'm done, like I said it's going to be very basic, the only thing that will really set it apart from your typical basic UI will be little features that make it easier for me to layout the UI data and maybe some code that will make it easier to customize the look of the various UI elements. I also doubt I'll have any art for the UI so it'll be very ugly too ;).
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Best way to handle GUI rendering in Ogre?

Post by bstone »

Sounds good. I don't need much to be impressed. A fluid dynamic layout with buttons, edit boxes, and text areas would do :)