SFML community forums
Help => Window => Topic started by: raylo on March 24, 2023, 11:46:01 pm
-
I'm making a langton's ant thing and to optimise it i thought i could stop clearing the screen and only draw each cell i needed to each frame and let the previous frames still be drawn, but the window seems to wait a frame before drawing the previous frame again and the cells end up flickering.
Any ideas on how i could prevent this from happening?
Can provide screenshots if needed.
-
what is happening is that you're actually not optimizing it ;D
modern video cards are able (and made to) handle constant clearing/drawing, so don't be afraid to do that. SFML is built with this concept in mind, but unfortunately I personally don't know the exact techical reasons.
-
The display is double buffered.
This means there are two buffers for your rendering: the front buffer and the back buffer. The front buffer is what is shown on the monitor. The back buffer is where drawing happens.
When the program calls the window's display() function, the two buffers are swapped.
If the window isn't cleared each frame, you have to make sure every pixel of the window is overwritten by something. For example drawing a full window background sprite, or a tile map, etc. What you are drawing on top of isn't the last frame rendered, but the second last frame, since the last frame is in the other buffer.
If pixels aren't overwritten, you'll get flickering anywhere the two buffers don't have the same pixels.