Lazarus

Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: Roland57 on April 18, 2021, 06:19:40 am

Title: Bouncing balls with Phong effect
Post by: Roland57 on April 18, 2021, 06:19:40 am
Hello!

Here are bouncing balls with Phong effect.

https://github.com/rchastain/collisions

Adaptated (with the help (https://www.developpez.net/forums/d1476320/autres-langages/pascal/lazarus/anti-aliasing-fond-noir-bibliotheque-bgrabitmap/#post8309416) of an expert) from a program (https://corpsman.de/index.php?doc=beispiele/pingpong) found on the excellent website corpsman.de (https://www.corpsman.de/).

Regards.

Roland.
Title: Re: Bouncing balls with Phong effect
Post by: circular on April 18, 2021, 12:44:55 pm
Nice.

Note that it doesn't show anything on MacOS. To make it compatible, you need to draw within the OnPaint event of the form. So for example, call Form1.Invalidate after you have rendered and do the final Draw in the OnPaint event.
Title: Re: Bouncing balls with Phong effect
Post by: Roland57 on April 18, 2021, 04:03:48 pm
Note that it doesn't show anything on MacOS. To make it compatible, you need to draw within the OnPaint event of the form. So for example, call Form1.Invalidate after you have rendered and do the final Draw in the OnPaint event.

Done, thank you.
Title: Re: Bouncing balls with Phong effect
Post by: circular on April 18, 2021, 06:43:34 pm
Yep, that fixes the problem.

Does it work the same way after this change on your system?
Title: Re: Bouncing balls with Phong effect
Post by: Roland57 on April 18, 2021, 07:05:51 pm
Does it work the same way after this change on your system?

I have the impression that the movement is a little less fluid.
Title: Re: Bouncing balls with Phong effect
Post by: circular on April 18, 2021, 07:34:16 pm
Hmm

What if you call Repaint instead of Invalidate?

Note that is doesn't really fix this problem on MacOS but it might on Windows.

Edit: something that seems to work, is to add a boolean WaitingForDisplay. After calling Invalidate, set this boolean to True. In the Idle event, do not call render when it is True. And in the FormPaint, set it to False.
Title: Re: Bouncing balls with Phong effect
Post by: Roland57 on April 18, 2021, 10:03:20 pm
Hmm

What if you call Repaint instead of Invalidate?

Note that is doesn't really fix this problem on MacOS but it might on Windows.

Edit: something that seems to work, is to add a boolean WaitingForDisplay. After calling Invalidate, set this boolean to True. In the Idle event, do not call render when it is True. And in the FormPaint, set it to False.

I don't see a clear difference here (on Linux). Still less fast and smooth than the first version. (I did reset the code on GitHub to the initial state, so that everybody can try and compare.)
TinyPortal © 2005-2018