Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » display problem using primitives (horizontal line glitch)

This thread is locked; no one can reply to it. rss feed Print
display problem using primitives (horizontal line glitch)
TadaNoButa
Member #17,111
August 2019

Hi there,

I'm running into a display problem using allegro 5 on linux. I'm drawing moving circles and there's a horizontal line appearing. I'm wondering if it is a graphic card driver problem. But I have this problem on two different computer. The problem appears more obviously when circles move faster.

I've put a preview image of the problem here.

In case of utility, there is my test code.

Any idea anyone ?

raynebc
Member #11,908
May 2010

It looks like tearing, ie. drawing to the video memory while it is being output to the screen. It has this effect of part of the picture being the current frame and part of the picture being the previous frame, so there is a distortion that occurs along horizontal line like this. Traditionally, avoiding this involved drawing everything to a buffer, then quickly copying the buffer to video memory while the screen isn't being refreshed from video memory (ie. wait for vsync to blit to video memory).

MikiZX
Member #17,092
June 2019

your code works OK on my end (no tearing or glitching present, though I did only test with Windows PrintScreen command to capture the screen and analyze it). the issues you report are possibly due to the OS/driver that you are using. my end I am on Windows10/Nvidia card.
As Raynebc suggested, try setting up your Allegro display with VSYNC enabled and see if that helps (I am not an expert here but maybe your application will need to ask for full screen display for the VSYNC to kick in - windowed modes will be more dependent of the OS in regard to VSYNC).

Peter Hull
Member #1,136
March 2001

I couldn't see that effect either on Mac, so may be a Linux thing.
How did you capture your screen shot?

TadaNoButa
Member #17,111
August 2019

Thank you so much for your answers. I love you community people !

Now I realize it is a vsync issue. There's actually nothing specific to primitives. I have the same problem with bitmaps.

To answer you question, Peter, I did just use Xubuntu's standard screen capture utility to make the screenshot. And that screenshot fairly well renders what the look can grasp when seeing things move on the screen.

So, the problem seems to be that allegro can't access the vsync from my graphic card's driver. I've tried to add al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE) before setting up the display to force the use of vsync. But in that case, the display just isn't created.

I've also tried putting al_wait_for_vsync() before al_flip_display(): the framerate drops to about 10fps and there's still the tearing...

I've tried if it was better with real ALLEGRO_FULLSCREEN (instead of ALLEGRO_FULLSCREEN_WINDOW or normal windowed mode), but it's not.

So I don't really know what to do. I'll try digging into triple buffering, but I'm afraid it will not help, since if allegro doesn't know the vsync of the graphic card, the problem would probably be the same.

Izual
Member #2,756
September 2002
avatar

If you are using NVIDIA card you can try this:

Open NVIDIA X Server Settings then go to X Server Display Configuration.
Press Advanced button to display more options and check Force Full Composition Pipeline.
Apply, do not forget to Save to X Configuration file if you want to keep the changes after restart.
It helps a lot with tearing on linux machines.

TadaNoButa
Member #17,111
August 2019

Thank you.

Actually my point is not so much to resolve this problem on my computers (which have a radeon and an intel cards...), but I'm thinking ahead in terms of portability. I'd like my application to work out of the box for people without having to care too much about their graphic card's driver settings. I don't know if this is realistic with allegro then. :-/

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

TadaNoButa
Member #17,111
August 2019

Hi Edgar !
So, if it's set on a per application basis, there's no way in the allegro application to register for the vsync or anything ?

MikiZX
Member #17,092
June 2019

In my experience... per application basis means that the driver can either respect the vsync requests of the application or filter them out.
On the other hand, if application is running in a window on a desktop and this desktop is drawn using no VSYNC then even if the application (Allegro app) is requesting the VSYNC and the per application driver settings say it should use the VSYNC it will be ignored and drawn using no VSYNC since it is the OS that controls the desktop and your app is part of that desktop.
I believe this 'per application' setting only applies to the true fullscreen (not windowed apps or 'fullscreen windowed' ones).

You could try running your app in full screen (not 'fullscreen windowed'), but when you are initializing the display request it to be full screen, in screen resolution that is different from your desktop and possibly even different color depth (I am naively hoping that this would have the gfx card actually initialize a new video mode and hopefully give Allegro's request for VSYNC some thought). You can possibly try this just for test.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Elias
Member #358
May 2000

Some Window Managers (like rather recent versions of XFCE or Mate) also cannot do vsync, so no matter what the application or GPU settings say there won't be any.

--
"Either help out or stop whining" - Evert

TadaNoButa
Member #17,111
August 2019

Thank you for all your help !

With an intel card, the addition of the Option "TearFree" "true" in the /usr/share/X11/xorg.conf.d/20-intel.conf worked well. And with a radeon card, I just had to create a config file /usr/share/X11/xorg.conf.d/20-amd.conf with that same option and it worked also.

It seems not to activate vsync, because al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE) still doesn't work, but it eliminates tearing.

As I run XFCE (Xubuntu), I've seen there's also this option in the Window Manager Tweaks "synchronize drawing to the vertical blank" that works after reboot (without need to install that Compton that link speaks about). It's still not "real vsync" (same as above) and maybe it just adds the TearFree option, but it's really accessible for people not knowing anything about the console, which is good.

Thanks again ! No more glitches ! :)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

You can also attempt to simulate vsync yourself. Get the frequency of the monitor from allegro and use a timer at the same rate. Synchronize it with the vsync and then let it run. It may work, however, it may result in a slow moving tear instead, due to minor differences between the timer rate and the refresh rate.

#SelectExpand
1al_wait_for_vsync(); 2al_start_timer(timer); 3 4/// Game loop 5while (Events()) { 6 if (ev.type == ALLEGRO_EVENT_TIMER) { 7 if (flip) { 8 al_flip_display(); 9 flip = false; 10 } 11 } 12} 13/// redraw normally but only flip on a timer event and only after redraw 14if (redraw) { 15 /// Draw(); 16 redraw = false; 17 flip = true; 18}

Go to: