Making a GUI for OpenGL Games?
stuck in a bind asks: "I am currently coding a civilization-type game (in C) but on a galactic scale. OpenGL is used to draw everything so far. However I have been unable to find a decent, nice GUI, practically all of them are coded in C++.
The only other options I can think of is coding my own toolkit (too much work, and I would hate to reinvent the wheel here), using SDL to draw 2D bitmaps on top of my OpenGL window. The last option would be to switch to GTK and use the GTK GL widget. What would the educated gamer/programmers of Slashdot recommend?"
It's been done before: Galactic Civilizations
I am government man, come from the government. The government has sent me. -- G.I.R.
using SDL to draw 2D bitmaps on top of my OpenGL window.
don't use SDL's method for blitting SDL_Surface's over OpenGL.. it's too slow.
do your 2D with OpenGL (textured polys).
-metric
see Gui toolkits
GLUI would be a good one GLUI website
try it out
regards
John Jones
--
http://www.johnjones.me.uk/
What would the educated gamer/programmers of Slashdot recommend?
Choose one:
(1) Switch to C++. Problem solved. Nobody in their right mind (outside of tiny platforms such as the Gameboy and certain icky parts of the Playstation 2) is still writing games in straight C. C++ does a much better job of encapsulation and maintaining a clear codebase - particularly if you expect the codebase to be worked on by more than one person.
Besides, UI programming is a pain in the ass without object-orientated encapsulation.
(2) If you're amazingly stubborn and still don't want to modernize your codebase, you can still use C++ without C++ features (you can ignore language features like classes, for example). This will let you use the C++ toolkits that you want.
(3) Write your own. If you really have the incentive and dedication to write a game, you should be able to write a UI toolkit for it.
I know that what you want is a C-based UI toolkit that can render widgets in OpenGL. I recently had to research this, and my impression is that you're stuck. As others have suggested, you might consider switching to a C++ compiler and just linking in your C code. You'll be hard pressed to find an advanced UI toolkit that isn't based in C++. Object orientation just matches user interface coding too well.
i tepapers.html
Here's the results of my search. This was for an application which had a very large number of Windows-like UI elements, but had to be able to render a 3D world using OpenGL.
FLTK -- Unsuitable. LGPL. Can open GL windows. Uses direct calls to OS line-drawing routines, so could be adapted to render directly to GL. Reasonable number of widgets, but ugly. No skin support. Development slow (two check-ins in last month).
wxWidgets(aka wxWindows) -- Good. LGPL. Can open GL windows.Used by Mitch Kapor's Chandler PIM project. Would require separate UI thread not to block. Requires awkward preprocessor macros in UI classes. Third-party graphical widget layout tools.
GLOW -- Unsuitable. Renders to GL. Not actively maintained. Uses advanced C++ (STL, RTTI). Clean code. No access to OS features, based on GLUT. Very simple, ugly widgets. Small library of widgets
Qt -- Very good. Commercial license. Can open GL windows. Included graphical UI layout tools. XML-based UI files, but compiled into code rather than loaded at runtime.
GLUI -- Unsuitable. LGPL. Renders to GL. Not actively maintained. Simplistic C++ code. No access to OS features, based on GLUT. Very simple, ugly widgets. Small library of widgets.
XPToolkit(aka Mozilla/XUL) -- Unsuitable. Tri-license MPL/LGPL/GPL. No GL support. Would need to ship Mozilla or Firefox as part of app. Excellent ideas for XML-based UI layout, though.
Full-custom with XML library -- Good. Renders to GL. Easiest for migration. Could do in-game UI editing, both for default skin, user skins, and script UI controls. Probably more work for you.
Also, if you're new to UI library development, I strongly suggest you read the Qt whitepapers. Their concept of signals and slots seems quite powerful (though I have not used it myself).
Qt 3.3 whitepaper:
http://www.trolltech.com/products/wh
James
> Do you need a good reason to be opposed to C++?
Most emphatically YES when the universe of discourse is game programming!
The unofficial
That would be your easiest route. It's all C, it's a decent toolkit, it's fairly portable, etc...
If it were me, I'd explore that first - but if that didn't work out right (say you want odd shaping of how the GUI overlays the GL stuff), then I'd switch to rendering the GUI into textures and letting OpenGL put the GUI on the screen. Just about anything (GTK or what-have-you) can be made to render to a bitmap in memory which serves as the texture for an OpenGL polygon that's placed where it needs to be for the GUI to look right.
11*43+456^2
I did find one written in C however: Agar. It's also being actively developed, so might be worth a shot.
This sig is intentionally left blank
has a zlib[?] licence, no obligations really, and you can redist for commercial use.
l
Has a full UI set of things.[buttons sliders]
Yep written in C++ but can use DX 8.1, 9.0, OpenGL1.2 and somethign else, and software.
And has skeletal animated or quake 2 style meshes. and loads quake 3 maps, objs or 3ds, jpgs and even psd.
Scenegraph and special effects you can turn on [water, fire etc]
http://irrlicht.sourceforge.net/screenshots.htm
#hostfile 0.0.0.0 primidi.com 0.0.0.0 www.primidi.com 0.0.0.0 radio.weblogs.com
Write your own, in C++. It's easier than it sounds if you design the controls correctly. I wrote the UI for our games (see Betty's Beer Bar for an example) and it didn't take too much time. It's not OpenGL but the idea is the same, only the drawing part changes.
As for OpenGL, keep it generic - you can hook a SDL window and Direct3D (I submitted a mini howto but I think Sam never included it, check the mailing list archives), so a good idea may be to create or use an abstraction library that can use either OpenGL or Direct3D. Since Direct3D 8+ is almost a copy of OpenGL, writting one is also easier than it sounds. And if your license is compatible, there's a simple wrapper in the Doomsday Engine project.
Of course, you can always use a 3D engine which already includes a GUI (we are currently using OGRE) and which solves the OpenGL/D3D/Whatever abstraction.
Good luck!
My website
Of cource it is bothering job when you invent wheel that already exist.
But it is better. Fast. Smaller code. And it makes your code *SIMPLER*.
You don't have to learn GUI developer's coding style.
I also doing my GUI job on my own using OpenGL Ortho + GL_RECT + Textures.
It didn't took that long time. Almost 2 weeks passed and I managed to make the GUI controls that is very simple button, text, editing area, list control for the long text, combobox for the my 3D modeler and popup style menu...
Every control shares most part of their elements so you don't need any hard job to make new component, just a simple modification you get new one. I use C++ so just one inherit I get new one.
And you can and will use this codes all over the game. Because game need not only windows style GUI that is hard to manage with GUI library.
Well what I wanted talk about is.. it doesn't take that long time and it worth it. Just make your own.
It's UI is completely done in opengl and the library (Ghost) hasn't been mentioned. The blender developers wrote it when Glut didn't quite fit the bill for them.
Blender
If you see spelling or grammatical errors don't blame me. I tried to preview but IE here at work borked the CSS