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

Author Topic: Not return "canva" when window.display() ?  (Read 5913 times)

0 Members and 1 Guest are viewing this topic.

Dacapo

  • Newbie
  • *
  • Posts: 2
    • View Profile
Not return "canva" when window.display() ?
« on: November 05, 2021, 07:36:29 pm »
I'm making a project where I want that drew elements with window.draw() don't disappear when I run window.display(). It seems that this code:

window.draw(item);
window.display();
window.draw(item);

make item doesn't disappear when we reuse window.display(). I think it's because window is like a piece of paper drew on one side and showed on the other. When we call window.display(), the paper is returned and we now draw on the other side.
However, I need a lot of efficiency in my code, and I was wondering if it was possible to draw directly on the side of the paper that is showed so that when we call window.display(), the "piece of paper" isn't returned but just showed with all items (these that were already drew and these that were drew just before window.display())

I apologize if my English is barely understandable (I'm not native speaker),  I did the best I could to explain my problem.
Thanks in advance !

kojack

  • Sr. Member
  • ****
  • Posts: 314
  • C++/C# game dev teacher.
    • View Profile
Re: Not return "canva" when window.display() ?
« Reply #1 on: November 06, 2021, 03:14:31 am »
Your piece of paper analogy is basically right.
SFML uses "double buffering". There are two graphics buffers: front and back. The front buffer is shown on the monitor. The back buffer is the target for draw operations. When display() is called, the front and back buffers are swapped, the previous back buffer becomes the current front buffer and is shown on the monitor, the previous front buffer is now the target for drawing.

If you want to do cumulative rendering (where each thing you draw remains in a single buffer), you can use a RenderTexture.
Have a look at the "Off-screen drawing" section of this tutorial page: https://www.sfml-dev.org/tutorials/2.5/graphics-draw.php
A RenderTexture can be used like a window, you draw into it the same way. Then every frame you draw the RenderTexture onto the window. While the window will still be double buffered, the RenderTexture itself isn't, so you don't