Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Not clearing window  (Read 911 times)

0 Members and 1 Guest are viewing this topic.

raylo

  • Newbie
  • *
  • Posts: 1
    • View Profile
Not clearing window
« 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.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Not clearing window
« Reply #1 on: March 25, 2023, 03:04:03 am »
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.
Visit my game site (and hopefully help funding it? )
Website | IndieDB

kojack

  • Sr. Member
  • ****
  • Posts: 336
  • C++/C# game dev teacher.
    • View Profile
Re: Not clearing window
« Reply #2 on: March 25, 2023, 04:04:22 am »
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.

 

anything