Hello, I have been using the library for several years now and am wondering about the Canvas functionality. I thought several times I understood it, only to come away confused.
I’ll explain the problem I am having:
I am drawing multiple layers of backgrounds to a “canvas” and when I am finished I want to display the “canvas”.
(python pseudo code)
- create new canvas
Canvas = TheMatrix.CreateFrameCanvas()
**LOOP**
- clear canvas
Canvas.Fill(0,0,0)
- draw a bunch of pixels (multiple passes for multiple layers)
Canvas.SetPixel(x,y,r,g,b)
Canvas.SetPixel(x,y,r,g,b)
- display the results
TheMatrix.SwapOnVSync(Canvas)
The problem I am having is a noticeable flicker when I execute Canvas.Fill(0,0,0). I THOUGHT this would only draw on the canvas (i.e. it was drawing on a buffer off screen) and the main display would not be affected until the SwapOnVSync.
Have I mis-understood how the Canvas object works?
I am also a pretty new user of this library. My understanding is that you are operating off screen and that it isn’t until you do the SwapOnVSync() that the updated canvas takes effect. However I have noticed that any cpu intensive activity on my pi can cause the panels to flicker. Perhaps that is the issue?
You might want to try canvas.Clear() instead of canvas.Fill(), I haven’t tested/measured the relative cost of this api, but I use canvas.Clear() on my pi zero w and haven’t had an issue with it causing flicker.
The clear function still causes the screen to blank, almost as if the “canvas” I am workign with is the actual live display. I am going through the python docs to see where my mis-understanding is coming from.
I was thinking I had a “canvas” and by swapping, I was just swapping the information in it onto the display. Nope. There are TWO canvases. One being drawn from, one that I am painting on. I need to swap them and keep writing.