# GTK for games?

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

## Recommended Posts

Hi! I'm looking for a cross-platform library to handle the windowing and input-related code in my application. I've tried a few up till now, and I'm still looking at the alternatives. I've used SDL, and it's a while ago now, so I can't remember exactly why I wasn't satisfied with it. (I think, among other things, that I ran into a bug where SDL spent ages creating a window). Afterwards I decided to try glfw. I'm quite pleased with the interface and documentation, but sadly there are a few bugs, and the maintainer is no longer maintaining it, (though some people have recently started a mailing list (glfw-dev@stacken.kth.se) and are contributing patches to the project, but it's slow going). Now I've decided to replace glfw with something else, and I'm considering using gtk. As far as I can tell, (and I've only glanced at it thus far), this seems to present me with a few choices. 1) Use the GtkGLArea widget for rendering and other Gtk functions for handling input. 2) Use GtkGLExt. 3) Use GtkGLExtmm, (a C++ interface to GtkGLExt). GtkGLArea seems to be the "old" way of doing things, and GtkGLExt seems more suited for my purpose. The only problem I can see with using GtkGLExt is that GTK controls the main loop. I would rather do this myself, and instead use some sort of conventional event polling system (as in SDL or glfw). Since I'm programming C++ anyway, maybe I should use GtkGLExtmm. Does anyone have any experience with this? Another benefit to using GtkGLExt is that it would also take care of things like font rendering using pango. Perhaps I could even use gtk for the in-game gui? Any thoughts?

##### Share on other sites
For tools it would be okay. For a game it's going to look ugly unless you are programming a board game like chess, go, or battleship.

You might consider moving to OpenGL and using a GUI built for that.

##### Share on other sites
If I'm not mistaken, there was some member here working on a game-based GUI. I believe it was called "OpenGL GUI". If no one finds the link by tomorrow, I'll search for it at work.

##### Share on other sites
For window creation and management, wxWidgets or GTK+ are both excellent packages, and I can think of many Linux games that use them. Go right ahead.

It is here

##### Share on other sites
Quote:
 Original post by RavuyaFor window creation and management, wxWidgets or GTK+ are both excellent packages, and I can think of many Linux games that use them. Go right ahead.

Thanks, Ravuya, that helps. I wanted to make sure before I spent too much time studying it further. It's a pretty large library.

Quote:
 Original post by leiavoiaFor tools it would be okay. For a game it's going to look ugly unless you are programming a board game like chess, go, or battleship.You might consider moving to OpenGL and using a GUI built for that.

Perhaps it would be a good idea only to use GTK+ for the window-management then.

Quote:
 Original post by Alpha_ProgDesIf I'm not mistaken, there was some member here working on a game-based GUI. I believe it was called "OpenGL GUI". If no one finds the link by tomorrow, I'll search for it at work.

Right, I remember that thread. It looked fairly neat. I remember downloading the source code and taking a look at it, but I imagined that it would be hard to integrate into my own engine. I'll look at it again.

Quote:
 Original post by Daniel ProtopopovIt is here

Much appreciated!

Does anyone have any ideas or comments when it comes to the problem of gtk controlling the main loop? I'm still uncertain about this one, but perhaps it's not so bad as I'm imagining, I heard that this was a problem when trying to use gtk with pygame, but in that case perhaps both libraries want to control the main loop?

I think the best would be just to code up a test, see if it works. If not, I could try to work around it somehow.

Thanks for the help so far. More comments are welcome.

##### Share on other sites
standard rectangular gui elements in games suck
go and make your own gui or use an existing one where you can have gui elements in more interesting shapes, a game with a boring gui will always appear to be boring!

the best gui system (LGPL) is www.cegui.org

##### Share on other sites
Thought I'd post a little update. Maybe it'll be helpful to others who might be considering using gtk.

I'm nearly finished rewriting the code to use gtk, and thus far it's working very well. I decided to use the C-interface, and not the C++ interface.

The window handling is very nicely managed by gtk itself. The code is very high level, so you avoid the gritty details. I've only tested this on linux as of yet, but it should be fully portable without any changes.

I also found the solution to gtk taking over the main loop. I found that it doesn't necessarily have to do so, and you can poll for events and update the gtk window and widgets whenever you like with the helpful gtk_main_iteration() function:

// Update the gtk widgetswhile (gtk_events_pending())  gtk_main_iteration();

I found the gtkglext port of the classical gears application to be a very helpful example when writing the windowing code: http://cvs.sourceforge.net/viewcvs.py/gtkglext/gtkglext/examples/gears.c?rev=HEAD&content-type=text/vnd.viewcvs-markup

Thanks for the help, guys.

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
14

• 14
• 10
• 23
• 9
• 32
• ### Forum Statistics

• Total Topics
632631
• Total Posts
3007534
• ### Who's Online (See full list)

There are no registered users currently online

×