I am having some issues with Allegro that I simply can't figure out how to solve myself, after spending some time searching for an answer I still haven't found anything that I could use.

I am new to Allegro, so there's much I don't know yet, so please don't hate me for this question. I have, however, spent some time with C++ so I know how to do some things, but I'm far, far from an expert.

I'm trying to make a program that I will eventually expand to a game, but for now I'm working on a level editor, and I've managed to set up a decent interface and the GUI is working as I want it to. Everything works just as I expected - just tens if not hundreds of times slower... I have noticed that my simple GUI renders at about 20-30 FPS, which is just ridiculously slow. However, as soon as I take out the drawing part from my main loop, the program runs much faster, I'd estimate much more than 1000 FPS. Just a very rough guess as the program seems to run 960 frames in less than a second.

I have no idea what I can do to fix this...I'm using Microsoft Visual C++ 2010 and Allegro 5.0.4, and this is some parts of the code I use to draw everything:

Other details:The surfaces aren't anything else than allegro bitmaps with a different name, so surface_reset_target() simply means al_set_target_backbuffer(screen). surface_set_target is just the same as al_set_target_bitmap, just with a little bit more code related to my engine.

I really hope that anyone can help me out with this. I really do want to make a game with C++, which is something I've never been able to do before. But I can't because my program is running so slow that it hurts...

EDIT:After running some tests, I notice that most of the slowdown seems to come from the al_flip_display() call. Running 960 cycles with everything but that lines seems to take just around 5 seconds which I might be able to live with, but with that line... Oh boy, soooo slow.

Okay, I tried to shift around the order the code executes.Now resources load before the display is created. It looks like that caused even more issues, as now the program runs even slower, about ten-fifteen seconds per frame. Seconds per frame, not frames per second :/

About the buffer... It's being created/destroyed in the code, but I don't use it. I have simply forgotten to remove it, so that's not the problem either.

The order would now be as following:Init AllegroInit addonsInit displayInit resourcesMain loop: - Process logic - Process drawingFree resourcesFree Allegro

Try moving also the addons initialization and place them after creating the display and see if that helps. Also, keep in mind that drawing to anything other than the backbuffer can be really slow on some older cards, so if your current target is not the backbuffer, it can be the cause.

Creating the display before the addons does squeeze a few more FPS out of this, but it's still running slow. I've added a special case when there's zero viewports, so the engine uses the backbuffer directly. But what if I really need two viewports at the same time? I would have to render everything separately to each of those viewports (The drawing can be different depending on the viewport, say you don't want to render something to the second viewport, but only the first), then combine them to the backbuffer, how could that be optimized?

But still, this program is still running too slow, even when rendering directly to the backbuffer, without the other targets. Is there anything else I can do to speed this up? I'm willing to send the whole project over to do so, if that is what it takes to solve this.

Are you using Direct3D or OpenGL? try with both and see if there's any difference.

Well, I don't really know how to change to those. Any pointers would be helpful.

Also, about the backbuffer, would that work even if I want to draw one thing to the first viewport, but not the other, or the other way around? Also, there's some cases where I really have to use surfaces, I can't cheat that by using the backbuffer, can I? Besides, sounds like this will grossly over-complicate everything...

Well, I do have aal_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);before the surfaces are created, well, right after the addons has been initialized, actually. So they should be video bitmaps, right?

As I said, I'm willing to share the entire source code if is required to solve this issue.

If you're using Windows then you're using Direct3D as it's the default on Windows. Try adding al_set_new_display_flags(ALLEGRO_OPENGL); before the display creation and see whether it runs better or not.

It's true that using the backbuffer for everything could complicate things and it probably isn't necessary on recent graphics cards. What's your graphics card? and do you have the latest drivers for it?.