Distortion when moving across the screen sprite (Raspberry 4B))

New to FreeBASIC? Post your questions here.
PavelUT
Posts: 78
Joined: Jun 14, 2021 14:42

Distortion when moving across the screen sprite (Raspberry 4B))

Post by PavelUT »

This program moves the yellow rectangle over the blue background. At the same time, the rectangle is strongly distorted when moving.
Question. I have a bug in the code or is this a FreeBasic feature to overcome?
(My computer Raspberry 4B)

Code: Select all

ScreenRes 800, 600, 32,2
Screenset  1,0
Dim As Integer x = 0
    Color RGB(255, 128, 0), RGB(0, 0, 200) 
    Cls 
Do
    Cls
    Line (x, 80)-Step(63, 127), RGB(255, 255, 0), BF
    x += 3: If (x > 639) Then x = 0
     ScreenSync
     Flip 
Loop While Inkey = ""

sleep
end
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by D.J.Peters »

Try this without sceensync does it solve the problem ?

Joshy

Code: Select all

ScreenRes 800, 600, 32,2
Screenset  1,0
Dim As Integer x = 0
Color RGB(255, 128, 0), RGB(0, 0, 200)
Do
  Cls
  Line (x, 80)-Step(63, 127), RGB(255, 255, 0), BF
  x += 3: If (x > 639) Then x = 0
  Flip : sleep 1
Loop While Inkey = ""
sleep
PavelUT
Posts: 78
Joined: Jun 14, 2021 14:42

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by PavelUT »

Hello dear D.J. Peters. I am very glad that you paid attention to my question.
PavelUT
Posts: 78
Joined: Jun 14, 2021 14:42

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by PavelUT »

Unfortunately no. With this change in the program, the rectangle moves across the screen very quickly, and the distortion is even greater.
As you may have guessed, I am interested in moving sprites in 800x600 mode and 32 bit color. And this is just a simple example of a problem.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by fxm »

Can you test this with a [ScreenLock ... ScreenUnlock] block, by locking instead of double buffering?

Code: Select all

ScreenRes 800, 600, 32
Dim As Integer x = 0
Color RGB(255, 128, 0), RGB(0, 0, 200)
Do
  Screenlock
  Cls
  Line (x, 80)-Step(63, 127), RGB(255, 255, 0), BF
  Screenunlock
  x += 3: If (x > 639) Then x = 0
  Sleep 20
Loop While Inkey = ""
Sleep
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by caseih »

By "distortion" do you mean tearing? I can confirm your sample code does show tearing on my desktop Linux machine running X11 (and compiz composite manager). fxm's code shows no tearing, but has some flicker.
PavelUT
Posts: 78
Joined: Jun 14, 2021 14:42

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by PavelUT »

Yes it is. It is very strange. Refreshing the 640x480, 32 screen takes about 0.001 seconds. That is, at a screen refresh rate of 60 hertz (which is already enough for comfortable graphics reproduction), the background is redrawn in 1/15 of a second. The sprite is much faster. Despite this, incomprehensible distortions occur. What's the matter? I do not understand
PavelUT
Posts: 78
Joined: Jun 14, 2021 14:42

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by PavelUT »

fxm, nothing helps. I have tried many examples. With all screen modes. I get the impression that 32-bit 2D graphics in FreeBasic are not working without OpenGL and Direct X
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by caseih »

Tearing is a common complaint with X11 on Linux. It's kind of the nature of the graphics server. It's asynchronous, so it's hard to get redraws to coincide with the refresh. There are ways of synchronizing the drawing to the refresh rate but it's complicated and tricky with X11. That's part of the reason why everyone is trying to move to Wayland. If the FB graphics library was ported to wayland everything would be a lot smoother.

Fortunately you have a lot of options. You can work with straight OpenGL. Or you could use a library like SDL, which uses a variety of backends to get the smoothest drawing and decent frame rates. SDL is nearly as simple as the built-in FB graphics library. Plus it has sprites.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by counting_pine »

What do these distortions look like? Can you provide a screenshot, or failing that, a photo of the screen?
PavelUT
Posts: 78
Joined: Jun 14, 2021 14:42

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by PavelUT »

Believe it or not, when photographing with a phone and pressing the PrtSc key, perfect rectangles are obtained. Your only chance to test is to repeat this program on a Linux computer.
PavelUT
Posts: 78
Joined: Jun 14, 2021 14:42

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by PavelUT »

Here we managed to photograph the distortion
[img]I can not insert a picture
[/img]
SARG
Posts: 1764
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by SARG »

PavelUT wrote:[img]I can not insert a picture
[/img]
You have to upload the image somewhere and then put the link between the tags.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by caseih »

He's seeing tearing, which is quite common on X11 on Linux. The top part of the rectangle appears sheared off (offset slightly) from the bottom part of the rectangle, and kind of flickers. The rectangle is being redrawn by FB while X11 is displaying it. This happens because X11 lacks a vertical sync signal. Also X11 is asynchronous, meaning you ask it do draw something and it returns immediately, and draws whenever it can. This was good for the low-powered graphics systems of ancient days, but does not work well for modern video and animation requirements. TThere's really no solution for X11, other than using OpenGL as a backend, which is what libraries like SDL can do. As much as I love X11and its flexibility and ability to operate over a network, there are some significant drawbacks to X11, and this is one of them. Wayland, by contrast, focuses on making everything silky smooth and completely synchronized with the refresh rate of the screen.
PavelUT
Posts: 78
Joined: Jun 14, 2021 14:42

Re: Distortion when moving across the screen sprite (Raspberry 4B))

Post by PavelUT »

Thanks for the detailed answer. That is, it turns out that the better the computer, the worse the image ...
Means under Windows these distortions will not be? And here's what's strange. When x + 1 is changed, the distortion is minimal, at x + 3 it becomes very noticeable. What is very strange, what difference does it make to a video card driver?
Post Reply