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

Author Topic: To keep a RenderWindow's partial region unrefreshed  (Read 1602 times)

0 Members and 1 Guest are viewing this topic.

Irunfold

  • Newbie
  • *
  • Posts: 3
    • View Profile
To keep a RenderWindow's partial region unrefreshed
« on: April 16, 2019, 10:18:30 pm »
Hello,

I am looking to get the same effect as the GraphicsPath from Winforms which allows to keep some particular areas of myForm unrefreshed. f.i.:
myForm.Invalidate(new Region(graphicsPath));

My final goal is to draw things at the unrefreshed location, using a HDC (Device context handle) that I will provide to an external application. (This currently works using winforms).

I am using SFML.Net 2.4 and I create my window this way:
 SFML.Graphics.RenderWindow  mySfmlWindow = new RenderWindow(myForm.Handle, settings);

I can still create the HDC on myForm, however, even without calling :
mySfmlWindow.Clear(color);

, the things drawn by the external application are still instantly cleared when i call:

mySfmlWindow.Display();

I suppose this is due to the fact SFML keeps its double buffers somewhere else than the window itself, so anything drawn by an external application using the window's HDC will get overwritten by the copy of SFML's internal buffers... What can I do?
« Last Edit: April 17, 2019, 04:03:24 pm by Irunfold »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: To keep a RenderWindow's partial region unrefreshed
« Reply #1 on: April 18, 2019, 07:46:51 am »
Quote
What can I do?
Have you external app refresh its area whenever you redraw with SFML.
Laurent Gomila - SFML developer

Irunfold

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: To keep a RenderWindow's partial region unrefreshed
« Reply #2 on: April 18, 2019, 04:13:16 pm »
Thank you for your answer Laurent, that is an interesting suggestion.

TL;DR : 2 likely possible issues using this method:
  • Area flicker between Display() and the external app to finish its drawing
  • External app probably refreshes only some parts of the area each frame

Long version:
I am not sure yet, but I could maybe ask for the client to adapt his external app's code to refresh the window right after I trigger an event meaning "I just called Display(), now you need to draw/refresh your area again".

Although the issue will probably be a flickering display, because, during the short time interval between my event and the external app to finish its drawing, there will be something else drawn by the SFML on the screen, different than what the client intends to display.

Also, I don't know yet either but the external app might be redrawing only some parts of the area (the area I want to share and keep unrefreshed). In this last case, asking the external app to refresh after the SFML redraw would not work.

I am currently waiting for an answer from the client which develops the external app and I will come back when I will have more information.
« Last Edit: April 18, 2019, 04:21:59 pm by Irunfold »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: To keep a RenderWindow's partial region unrefreshed
« Reply #3 on: April 18, 2019, 05:58:17 pm »
Can't you provide a HDC to an off-screen area to the external app, let it do whatever it wants there, and use it as a source to update a sf::Texture whenever it is changed? This way you don't really mix SFML and the external app on the same surface.
Laurent Gomila - SFML developer

Irunfold

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: To keep a RenderWindow's partial region unrefreshed
« Reply #4 on: April 18, 2019, 06:07:07 pm »
That is what i did, but since il developing in C#, the process of copying pixels one by one is rather slow, for an area of 770x770, i dropped from 50fps to 15fps using SetPixel , the loop alone in c# spends lots of time to go through..

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: To keep a RenderWindow's partial region unrefreshed
« Reply #5 on: April 18, 2019, 09:09:13 pm »
Pixel by pixel is of course overkill. I don't know if it's possible with SFML.Net, but you should try to get a "pointer" to the pixel area and pass it directly to Texture.Update.
Laurent Gomila - SFML developer