Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Using Allegro in Qt

This thread is locked; no one can reply to it. rss feed Print
Using Allegro in Qt
billyquith
Member #13,534
September 2011

Could someone who has good knowledge of Allegro 5 explain how you might use Allegro in a Qt application? E.g. say I want to write an editor and use the same code to draw a map as I use in my game.

There might be different ways you could do this. There may not be a best way.

Thanks.

beoran
Member #12,636
March 2011

A slightly different approach would be to change your drawing code a bit so it draws on Allegro displays OR on QT canvases depending of the compilation options, or perhaps even at runtime. You could use some macros like #ifdef ALLEGRO_RENDERER ... #ifdef QT_RENDERER , or function pointers, or some class inheritance to do this.

Itachihro
Member #12,001
May 2010

I don't know, duplicating all your drawing code doesn't sound like a terribly great idea. You can create an OpenGL surface in Qt, I suppose it should be possible to make allegro use that somehow?

OICW
Member #4,069
November 2003
avatar

Theorethically it should be doable, but it's PITA as far as I've searched more about this way back when I was considering a GUI library to use. The only sane thing would be to have your drawing code in OpenGL and once run that from your application and once from the editor. QT supports OpenGL canvas, but trying to open Allegro window in it would be hard in my opinion. Not to mention that you'd have duplicity in input etc.

One other way would be to use some dedicated gaming GUI library (guichan, gwen, TGui) and write the editor in that. Or you could try to extract drawing from your drawable objects, then you'd use these in both - the game and the editor - just supply the appropriate drawing code for the respective application. See the Visitor pattern for example.

[My website][CppReference][Pixelate][Allegators worldwide][Who's online]
"Final Fantasy XIV, I feel that anything I could say will be repeating myself, so I'm just gonna express my feelings with a strangled noise from the back of my throat. Graaarghhhh..." - Yahtzee
"Uhm... this is a.cc. Did you honestly think this thread WOULDN'T be derailed and ruined?" - BAF
"You can discuss it, you can dislike it, you can disagree with it, but that's all what you can do with it"

billyquith
Member #13,534
September 2011

Thanks for feedback so far. :)

beoran said:

A slightly different approach would be to change your drawing code a bit so it draws on Allegro displays OR on QT canvases ...

I did consider this, but, have to write everything twice. But, yes, an option.

Itachihro said:

... You can create an OpenGL surface in Qt, I suppose it should be possible to make allegro use that somehow?

Yes there is a QGLWidget, which can wrap OpenGL code in. Allegro could be modified to let Qt do the GL setup, then you could use your own drawing code. Could perhaps add a define, and then you'd compile Allegro in "embeddable mode".

OICW said:

it's PITA ... QT supports OpenGL canvas, but trying to open Allegro window in it would be hard in my opinion.

Yes I think it might be a bit of work.

Quote:

One other way would be to use some dedicated gaming GUI library (guichan, gwen, TGui) and write the editor in that. ...

I am currently using GWEN. I was the one who ported it to Allegro. But it doesn't have a designer, and there are lots of the little issues with it. I don't want to spend all my time doing tool UI. I want to write a game! Making a UI in Qt is fast and easy. :)

beoran
Member #12,636
March 2011

Is this a tile map editor you need? Tiled is your friend (http://www.mapeditor.org/).
Just edit your game maps in Tiled, and load the xml that Tiled generates into your game. That's what I'm doing too for my own game project Eruta, and it works well enough. :)

OICW
Member #4,069
November 2003
avatar

I am currently using GWEN. I was the one who ported it to Allegro. But it doesn't have a designer, and there are lots of the little issues with it. I don't want to spend all my time doing tool UI. I want to write a game! Making a UI in Qt is fast and easy. :)

Yeah, not having the designer is PITA as well. I've spent some "quality" time hardcoding GUI with alguichan for my demonstration application last week. On the other hand, I haven't found Qt that straightforward, fast and easy. A year ago I was trying to run some examples from my supervisor and getting it to compile with Qt was a lot of "fun". But that's just my point of view, use whatever suits you best.

[My website][CppReference][Pixelate][Allegators worldwide][Who's online]
"Final Fantasy XIV, I feel that anything I could say will be repeating myself, so I'm just gonna express my feelings with a strangled noise from the back of my throat. Graaarghhhh..." - Yahtzee
"Uhm... this is a.cc. Did you honestly think this thread WOULDN'T be derailed and ruined?" - BAF
"You can discuss it, you can dislike it, you can disagree with it, but that's all what you can do with it"

billyquith
Member #13,534
September 2011

beoran said:

Is this a tile map editor you need?

That was just an example. I want to edit particle effects, etc. A lot of modern engines allow you to edit your game and drop straight into it.

OICW said:

On the other hand, I haven't found Qt that straightforward, fast and easy.

But once you learn it there is a lot of material to use. It is pretty well thought out. It probably has the most powerful widget set of any UI library I've used.

OICW
Member #4,069
November 2003
avatar

But once you learn it there is a lot of material to use. It is pretty well thought out. It probably has the most powerful widget set of any UI library I've used.

Well, no doubt about that.

Quote:

A lot of modern engines allow you to edit your game and drop straight into it.

Anyway, you might want to consider to use those engines if you want that kind of user friendliness. Frankly, I don't see a point in making all of this fancy functionality, either you want to make a game or an engine.

[My website][CppReference][Pixelate][Allegators worldwide][Who's online]
"Final Fantasy XIV, I feel that anything I could say will be repeating myself, so I'm just gonna express my feelings with a strangled noise from the back of my throat. Graaarghhhh..." - Yahtzee
"Uhm... this is a.cc. Did you honestly think this thread WOULDN'T be derailed and ruined?" - BAF
"You can discuss it, you can dislike it, you can disagree with it, but that's all what you can do with it"

Ashteth
Member #3,310
March 2003
avatar

If you don't mind wxWidgets, there are a few samples floating around for both Allegro 4 and 5. Also, as others have said, you may wish to use an in-game GUI. AGUI works with Allegro 5 is more than up to this task.

For my own game, I have created some fairly non-trivial menus with AGUI for particle editing. I also use a standalone wxWidget application for inputting raw data.

Thomas Fjellstrom
Member #476
June 2000
avatar

At one point I was considering making some Qt bindings. Either allowing you to use allegro as a widget, or going the reverse route, and implementing a Qt PaintEngine so QT can draw into an Allegro window.

It is not something that is on my immediate radar however.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Go to: