Buffering

27 views
Skip to first unread message

Moisés Ackerman

unread,
Feb 14, 2021, 7:05:43 AM2/14/21
to Haskell Gloss
Hello,

I'm currently trying to (ab)use Gloss as a Haskell alternative to Processing. One of the primitives in Processing is the PGraphics class, which can be used to draw offscreen and then the image function can be used to draw it on the main canvas. The PGraphics object can be used as a sort of buffer: one can draw to it each frame, then draw the entire thing into the main canvas, so the content in previous frames is kept.

When trying to replicate this in Gloss (see my gist), the naive approach would be to keep a [Picture] in the model, update it by appending a new Picture each frame, and finally draw it as part of the display function. However, this means that each frame takes longer to draw, and after a while performance gets visibly choppy. This is the naiveMain function in my gist.

So, then I tried using the gloss-export package to emulate the PGraphics class. Here, the updateBuffer function uses IO to draw a Picture consisting of the previous buffer state (a bitmap) plus a new Picture into a new bitmap. This is the bufferMain function in my gist. This works alright until transparency is added to the mix. Anything with less than 100% alpha is lost. This could be a bug in my code or in gloss-export, though.

My question is, is there a better way to achieve this? Do you think I'm headed in the right direction with gloss-export? If so, how should I go about debugging the issues I'm seeing with transparency?

Thank you!
Moisés
Reply all
Reply to author
Forward
0 new messages