0

I am training in using the allegro library with c++ but I am getting an issue, while using large images for parrallax backgrounds i get a constant sort of load/glitch scrolling down the screen, making all my images flicker for a bit, is there a way to load backgrounds without having such an issue? The flicker does not appear when I try to print the screen.

Thanks

Ted
  • 629
  • 2
  • 8
  • 19
  • 1
    The default settings with Allegro 5 shouldn't cause any tearing issues. Could you post a link to some code and images that illustrate your problem? – Matthew Jun 25 '13 at 12:26
  • First link has main parts of code related to drawing : http://pastebin.ca/2409101 second is the whole code of the prototype with both classes http://pastebin.ca/2409099 . Any screen image I take doesn't show the problem, however, it is present on whatever platform I test it – Ted Jun 27 '13 at 01:04
  • 1
    just took a quick glance. Your calls to `al_set_new_display_option()` do nothing because you've already created the display. They only affect future `al_create_display()` calls. So if you want to see if any of those settings help, you'll need to call them before the display is created. – Matthew Jun 27 '13 at 09:22
  • 1
    Also, the last display mode isn't guaranteed to be the biggest. If you want to use the full resolution of the current display, `ALLEGRO_FULLSCREEN_WINDOW` is your best option. – Matthew Jun 27 '13 at 09:23
  • regarding the option, thank you I didn't know how they work, I assumed they handle new options for already created displays, I'll change and try again now – Ted Jun 27 '13 at 16:35
  • I have tried I am still getting the same issues, you can see when I draw the backgrounds, the sizes of the images, 7200, 800 (width and height) I am pretty sure it's because of the sheer size, is there a way to fix that? Is allegro unable to handle that size? Is there any other library that can? – Ted Jun 27 '13 at 17:25
  • What is the maximum texture size your video card supports? If you exceed the size (on either h/v edge), you'll be using memory bitmaps. You can query the maximum texture size from Allegro or you can just look up what your card supports. You'll be better off chopping it down into multiple bitmaps that are each within the maximum texture size. This is a limitation of your card (not Allegro), although Allegro does not provide any easy way to automate this task. Not sure if it is causing your problem, but it's worth looking at. – Matthew Jun 27 '13 at 20:57
  • Could you tell me a way of finding the max size of textures? I lowered the bg to 800px from 7600 and yet still the same visual glitch – Ted Jun 29 '13 at 00:48
  • `int max_size = al_get_display_option(display, ALLEGRO_MAX_BITMAP_SIZE);` - the maximum size of the longest side. – Matthew Jun 29 '13 at 15:51

2 Answers2

1

The flickering is most likely a result of you redrawing your scene, and the monitor refreshing partway through.

The cure for this is to use double buffering. Read this:

http://wiki.allegro.cc/index.php?title=Double_buffering

There is another artifact called 'tearing', which is caused by blitting your buffer during a refresh cycle. This is generally solved by waiting for a vertical sync (retrace) and then drawing, but that's a little oldschool now that most of us use libraries such as OpenGL or DirectX to talk to our graphics hardware.

Nevertheless, Allegro provides a function that waits for the vertical retrace to begin, which is the time at which you can safely blit your buffer without worrying about tearing. See here:

https://www.allegro.cc/manual/4/api/graphics-modes/vsync

paddy
  • 60,864
  • 6
  • 61
  • 103
  • Is blit or vsync available in some other manner in allegro5? I can't figure out how to call them with this version of the library – Ted Jun 25 '13 at 04:35
  • 1
    It seems that in Allegro 5 you shouldn't have to worry about buffering or vsync, as it's now using hardware acceleration. Have a look here: https://www.allegro.cc/manual/5/al_flip_display - if you are using Allegro 5 properly, you shouldn't be seeing flickering. – paddy Jun 25 '13 at 04:48
  • 1
    In addition to my last comment, it looks like you might need to explicitly create your displays for buffering. See https://www.allegro.cc/manual/5/al_set_new_display_option – paddy Jun 25 '13 at 04:51
  • I am using flip display, maybe I didn't describe it properly, it's not as much flickering as the images just seem to like, load a bit more to the side, by some sort of invisible line that goes down every once in a while in a continous cycle – Ted Jun 25 '13 at 05:11
1

I cannot promise that this is the solution, but looking at your code, I don't understand why you are creating multiple buffers.

bufDisplay = al_create_bitmap(WIDTH, HEIGHT);
buffer = al_create_bitmap(WIDTH, HEIGHT);

Unless you are doing some type of special effect that requires buffers, they are unnecessary. Allegro 5 already provides a double buffer with default settings.

Just draw everything to the default target bitmap (the display's back buffer), and then al_flip_display().

If you want to center or scale your output to a different sized window, you can usually just use transformations.

I don't know why you are calling Sleep(8).

If using Windows, you could switch to using OpenGL (set the ALLEGRO_OPENGL display flag).

You should try other Allegro games and demos (plenty come with the source) to see if it's a problem on all of them.

Matthew
  • 47,584
  • 11
  • 86
  • 98
  • I indeed used multiple buffers to resize the screen in case of different resolutions, in order to keep the level of detail of the images, however, even with one buffer I am still getting this problem. setting openGL would be through al_set_new_display_flags(ALLEGRO_OPENGL) ? I did so but it just crashes saying the display could not be initialized. I will try to find in the allegro forums if anyone else experienced this, thank you – Ted Jul 01 '13 at 17:28
  • @Ted, that is correct. If that crashes during display creation, sounds like something is very wrong. Cannot really say what would cause that without stepping through the debugger. – Matthew Jul 02 '13 at 02:11