Jump to content
  • Advertisement
Sign in to follow this  
ToniKorpela

OpenGL Thinking of Rolling My own GUI toolkit.

This topic is 2343 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I am probably going to do the same mistake as many other programmers have done and maybe failed.

You know the feeling when you want to reinvent the wheel and everyone tries to say that don't do that, but you just want to roll your own even though you really don't have any specific reason.

Well I am currently only thinking of programming my own game graphical user interface toolkit to run on top of OpenGL 3.3 with C++. I'm writing here because I want to know if I am missing something.

Basically first I need to write button, which is actually quite easy to draw with opengl and the mouse clicks on the button are quite easy to track with existing window framework, like with glfw. The button requires data like width, height, xyz position, bgcolor/bgimage and child text. Before I can create the text child I need to write code to load fonts and draw text on the screen. That's 3 classes, button, text, font.

Now I have the required classes to create window. First the window requires whole window width, height, bg. Header of the window needs width, height, bg and window text child for title. Three buttons as windows child for minimize, close and resize. Though implementing resizing feature I will most likely leave for later. The header actually itself needs to be a button, so that the window can be moved. After the window has been written I can write different widgets to fill the window. :) Next are the little bit more complex ones like text input, radio boxes, etc.

Basically my only problem is font loading, but well if I start doing this it's not going to be big problem. What I think I can bring to the table is easy way to build GUI widgets to your games with .xml templates and afterwards registering event calls on the code. Qt, GTK and MFC does something like this, but those are not good for game development in my mind.

So the only question remains should I roll my own or just use CEGUI?

Share this post


Link to post
Share on other sites
Advertisement
There are only two reasons to roll your own framework:

1) You think it's fun and want to learn something new *and* there are no time/budget constraints.
2) You're in the business of making frameworks, and the framework is a product in itself (or a vital part of a product).

For hobby projects, you might want to do it for reason 1. But for commercial projects, neither of the reasons apply, and you should consider going with an existing framework (even when it doesn't meet you needs perfectly). Edited by Felix Ungman

Share this post


Link to post
Share on other sites
I agree with felix, there are some quite reasonable 3rd party GUIs so consider using these first.

Off the top of my head: CeGUI, MyGUI, GWEN, then bigger ones like QT, GTK.
As well as this there are often propriety solutions for each platform, if you are not multiplatform.

If you want to have a go at rolling your own it's quite doable, depending how good your kung fu is, and depending how much or how little you want it to do. Each widget needs it's own code, so if for example, you don't need a treeview widget, don't write one till you need one.

I found text rendering to be as big (or bigger) an undertaking as writing the rest of the system. Consider using something like the freetype library to do this for you (I believe many of the other GUIs use freetype).

If you choose to have a go at text rendering this may help : I wrote my own subpixel text renderer with layout (justification etc), but used something like BMFont to precreate some pre-rendered fonts at the required sizes. Even so it still took a good week to get working to a decent standard, and getting subpixel rendering to look 'good' is not an easy task. The handling of subpixel spacing, kerning, and using 2 passes for justification makes it slightly more involved than you'd think, there was a lot of debugging layout problems. And mine (currently) can't handle images interspersed with the text as in html.

Then for the actual GUI itself I probably spent about a week of coding on it so far (on and off), and mine is pretty basic. I know it's probably heresy to say it, but I found it pretty easy, but maybe because I had a good idea of what would be involved / how to do it from the outset.

If you use inheritance, once you have the basic widgets / functionality, it becomes easier to build new more complex widgets by deriving from and combining the basic widgets.

Share this post


Link to post
Share on other sites
If you have fun and the kind of feeling to reinvent the wheel... do it...
I also want/started to write a little GUI Framework for my engine. It was a hard decision for me... Everytime I thought if it may be good to reinvent the wheel. But I'm very familiar with QT and I love it soo much that I start to "reimplement" QT on top of my engine...
But It failed hard...
I realized that QT has too much features that I don't need... like Signal/Slots, Metasystem... but these kind of things are the core of the framework...
So I dropped the idea to reimplement QT on top of my engine and started to make my own GUI Framework from scratch. My Framework is QT-like but there are also huge differences.
For example: I don't need signals and slots. In my framework every interaction code is done with my own scripting language (PSL, currently only planned) or with Lua.
One big problem (maybe the biggest problem) is the Font System. To display text is not really a problem but to display it fast, very fast is one of the biggest problems I have on my engine currently.

But it makes fun and I think now it was the right decision. My engine is currently very young so there is no real graphic visible and maybe many people think it will never be finished... no matter I love my engine and like to develop.
If you are thinking the same, do it do it do it...

And If you fail you still have learned a lot.

(Of course this suggestion is only really useful for hobby developing, not for commercial project ;) )

Share this post


Link to post
Share on other sites
I do not have time restraint and I kinda want to do it for learning too, so i think i will write the gui toolkit and will only implement what i need until someone requests me to write more features for it.

Thanks for your opinions.

Share this post


Link to post
Share on other sites
Actually most commercial (non game) products will use either Qt, Gtk or MS Windows GUI.

F.e. we actually have our own GUI for in-game stuff (meaning like main menu, inventory, and such - note that it contains just buttons, check boxes, radio buttons and such basic stuff) - and for editors, etc. - we use Gtk# - .NET ...

Share this post


Link to post
Share on other sites
I strongly suggest to bite the bullet with CEGUI.
On a side note, its dependancy on LUA (which is NOT the scripting language used in my system) prevented it from being useful for me.

Share this post


Link to post
Share on other sites
there are soo many UI libs, but even more ways to design them, it's hard to find the one that fits your desire.
I also run my own little UI lib, I wish I had time to add more features, but so far it's very light weight, copes with my renderer and event system. was just a weekend of work, it took me more to try other libs, which were usually full of 3rd party dependencies.

I think most games nowadays use scaleform. simply because there are quite some artist that can create flash UIs.

So I would suggest, if you want to create your own lib, especially if you do it for learning, it would be useful to support a skin format that is widely used, otherwise you have crappy looking UI or you need to create your own UI designer (which can be twice the work).

Share this post


Link to post
Share on other sites

On a side note, its dependancy on LUA (which is NOT the scripting language used in my system) prevented it from being useful for me.

Just for info. CEGUI has no required dependency on Lua, and at no time in the past has it ever had such a required dependency. We do provide a Lua based scripting module for people who want that, but this is completely optional. People who do not want it do not even have to build it.

The other place we use Lua is for the premake build system used with current (0.7.x) versions. But it is important to note that this does not introduce a runtime dependency for people using CEGUI, it is merely used to generate MSVC++ project files on Windows. In this respect it's no different to cmake (which we will be using starting with the next major release), and the fact that using cmake as a build generator does not add a runtime dependency on cmake.

Hope this helps to avoid any confusion regarding Lua and how CEGUI uses it, and sorry for the minor OT.

CE Edited by CrazyEddie

Share this post


Link to post
Share on other sites
Thank you very much for your clarification. Are event handlers part of this optional module?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!