SFML community forums

Help => Window => Topic started by: bdens on August 27, 2015, 04:48:26 am

Title: Drawing without Clearing - Monitor "Broken"
Post by: bdens on August 27, 2015, 04:48:26 am
Hi,

I'm implementing a minimap for my 2D Tile game.  I have a vector of tiles, and I really wanted to just draw the map once, and then draw changes (excluding window.clear() calls), since drawing each tile of the map each cycle will be very intensive for large maps.

The problem is that when I do not clear after each frame, the screen portions that are not drawn each frame will flicker between black and their desired color.

Is there a way to fix this?

Also, the flickering has made a permanent square of flickering on my monitor :\, effectively ruining my monitor, so, perhaps a word of caution to others experimenting with such.
Title: Re: Drawing without Clearing - Monitor "Broken"
Post by: Jesper Juhl on August 27, 2015, 06:16:52 am
You must call clear/draw/display every frame.
See the big red box : http://www.sfml-dev.org/tutorials/2.3/graphics-draw.php
Title: Re: Drawing without Clearing - Monitor "Broken"
Post by: SeriousITGuy on August 27, 2015, 10:46:49 am
... since drawing each tile of the map each cycle will be very intensive for large maps.

This is pre-mature optimization. Don't even think about optimization until you clearly know there is a performance problem (with profilers and stuff), because modern compilers and hardware can optimize better than you (and any of us). ;)
Title: Re: Drawing without Clearing - Monitor "Broken"
Post by: Hapax on August 27, 2015, 01:35:26 pm
I understand that it's best not to draw all of the tiles in a map when only some of them are within the window's limits but the solution to that is to only draw the ones that are visible.
Clear the window, draw the ones that are visible (not the masses of tiles outside of the view), then display it.

It's flickering because the display is double-buffered. It's drawn to a hidden buffer and then swapped. This means that the following drawing is applied on top of the frame that is two frames behind it (the one behind the currently displayed one). Therefore, it needs clearing.
The only time you can get away with not clearing is when you draw on every pixel.
Even then, clearing probably isn't going to make a noticable dent in your display rate.