![]() |
|
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. |
Peter Hull
Member #1,136
March 2001
|
I couldn't see that effect either on Mac, so may be a Linux thing.
|
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. 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
![]() |
If you are using NVIDIA card you can try this: Open NVIDIA X Server Settings then go to X Server Display Configuration.
|
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
![]() |
If Allegro can't enable VSYNC, it's because your graphics drivers have it turned off or set on a per application basis. There's nothing Allegro can do if your settings are wrong. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
TadaNoButa
Member #17,111
August 2019
|
Hi Edgar ! |
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. |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
It seems the issue on Linux is not so clear. The waters are quite muddy, but here are some solutions. It's basically up to the user to enable vsync on linux. https://www.maketecheasier.com/get-rid-screen-tearing-linux/ My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
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. -- |
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
![]() |
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. 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}
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|