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

Author Topic: Drawing without Clearing - Monitor "Broken"  (Read 2038 times)

0 Members and 1 Guest are viewing this topic.

bdens

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Drawing without Clearing - Monitor "Broken"
« 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.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Drawing without Clearing - Monitor "Broken"
« Reply #1 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

SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
Re: Drawing without Clearing - Monitor "Broken"
« Reply #2 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). ;)

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Drawing without Clearing - Monitor "Broken"
« Reply #3 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything