SFML community forums

General => Feature requests => Topic started by: Kernelpanic on May 16, 2008, 10:21:09 pm

Title: Not clearing the contents of a RenderWindow after Display
Post by: Kernelpanic on May 16, 2008, 10:21:09 pm
Hi,
I'm a new (and happy ;)) SFML-User.

When I call Display(), the RenderWindow ist displayed and his contents are cleared, I can call Display() again and there is only the background.
I have searched for a function in the Documentation, but I haven't found a option to disable this cls.

This is my idea for a new feature:
void Display(bool clear = true), developers would be able to keep the content of a RenderWindow.
Would it be possible to implement that feature?

"Kernelpanic"

PS:
Sorry for my bad English - German guy  :roll: ;)
Title: Not clearing the contents of a RenderWindow after Display
Post by: eleinvisible on May 16, 2008, 10:37:23 pm
Hehe "ist displayed"... =D

I suppose this is decent suggestion? Except in SDL when you flip the screen it clears the contents as well (if I remember correctly)...so this may be something more technical than I understand (I'm too lazy to understand OpenGL beyond textures and vertices).
Title: Not clearing the contents of a RenderWindow after Display
Post by: Kernelpanic on May 16, 2008, 10:44:08 pm
haha, if u have written "ist" thousand times...

I think, Flip doesnt clear the Window, but I'm not sure.
I have made one SDL-Project, and I think, I had to delete manually, it would be nice to have the choice.

Edit:
Yes, SDL_Flip doesn't clear the window.
I had the function oldRect to fill a rect with the backgroundcolor, without calling this function I get a long groove.
Title: Not clearing the contents of a RenderWindow after Display
Post by: Redien on May 16, 2008, 11:32:58 pm
SDL uses software rendering as default if I'm not mistaken. And thus probably uses bitmaps to store the current frame in RAM. OpenGL talks directly to the graphics hardware which stores the frames in the internal video memory. Thus in SDL you would just be modifying the bitmap in RAM which was then sent to the video card (if present) by OS calls every time it needs to be updated. (I don't know anything about SDL's internals so I'm just speculating here. :))

This is why you only draw what you need to draw onto the bitmap as it's slower for the CPU to blit an image in RAM than using graphics hardware to draw a textured primitive.

You could do the same thing with OpenGL and store the last frame in a texture and then render it before you render the new primitives.

But this kind of defeats the original purpose as this would probably just make it slower.
Title: Not clearing the contents of a RenderWindow after Display
Post by: Kernelpanic on May 16, 2008, 11:36:01 pm
Yes, that's the problem.
Copying it each frame makes the program much more slower.
Title: Not clearing the contents of a RenderWindow after Display
Post by: Redien on May 16, 2008, 11:39:25 pm
Why do you need such a feature anyway?
Title: Not clearing the contents of a RenderWindow after Display
Post by: Nexus on May 17, 2008, 03:08:08 pm
I think sometimes you could leave part of the screen - for example if you are just changing some small sprites, but must redraw the whole scene.
Isn't that a great loss of performance?
Title: Not clearing the contents of a RenderWindow after Display
Post by: Laurent on May 17, 2008, 04:21:30 pm
The usual technique for games, even not real-time ones, is to refresh the display continuously even if no update happens. Just redraw everything every loop.

If you don't refresh your display at all, you could have problems when resizing the window, moving other windows or cursor over it, etc.
Title: Not clearing the contents of a RenderWindow after Display
Post by: workmad3 on May 17, 2008, 05:59:51 pm
It is definitely the usual process when you have hardware acceleration available :) The main reason being that the small gain from only drawing changed sections is offset by the extra logic and processing required to keep track of just changed sections. This changes with software rendering of course, but as SFML is designed around OpenGL and 3d hardware is so prevalent nowadays, there isn't really a need to only clear part of the screen.
Title: Not clearing the contents of a RenderWindow after Display
Post by: Kernelpanic on May 17, 2008, 07:37:22 pm
Hey, in our discussion about SDL and Hardware we have lost the topic.
I don't search for a function like SDL_UpdateRect().
But when I Draw a sprite into a window and then call Display twice, I see only the Background.
In simple guis or turnbased games there are many parts of the window, which do not change each frame.
It would be efficient to keep the old content of the window.
You would still redraw the hole window with Display, but you wouldn't draw all the sprites again.
Title: Not clearing the contents of a RenderWindow after Display
Post by: workmad3 on May 17, 2008, 10:10:41 pm
The point I was trying to make was that with hardware acceleration, the extra logic required to track the parts that need changing is less efficient than just redrawing the entire screen (especially if your sprites are stored as textures on the graphics hardware, so don't require touching the CPU in it's renderpath).
Title: Not clearing the contents of a RenderWindow after Display
Post by: Kernelpanic on May 17, 2008, 10:35:18 pm
Yes, right, but I have already said so:
My problem is not the Displaying of the Window, it is the Drawing of the Sprites.
I could do that:
Code: [Select]

Image img = mainwindow.Capture();
mainwindow.Display();
Sprite sprite;
sprite.SetImage(img);
sprite.SetPosition(0, 0);
mainwindow.Draw(sprite);

..but that is really slow.
Title: Not clearing the contents of a RenderWindow after Display
Post by: workmad3 on May 17, 2008, 10:47:24 pm
Why is redrawing the sprites an issue? Thats part of redrawing the window and falls under what I've already mentioned.
Title: Not clearing the contents of a RenderWindow after Display
Post by: Kernelpanic on May 17, 2008, 10:54:27 pm
Is it really a problem, only to keep the old content?
You want to say this code is efficient?
Title: Not clearing the contents of a RenderWindow after Display
Post by: Redien on May 17, 2008, 11:10:24 pm
There's no reason to do that kind of optimization if you don't have huge amounts of static geometry (or sprites) that never change. Even if you did have, there are ways to speed that up by using VBO's, Vertex arrays etc. or just render it to a texture and draw it to the screen before every frame.

It's generally good practice to create the game or application first and optimize later when you actually need better performance. ;)
Title: Not clearing the contents of a RenderWindow after Display
Post by: workmad3 on May 18, 2008, 12:03:18 am
The code required to check which pixels have changed is more inefficient than brute force pixel pushing with todays hardware, yes. Especially when doing such an 'optimisation' will frequently require you to do things like get the rendered image from the hardware which is hugely inefficient in todays rendering pipelines as copying data to and from the graphics hardware is frequently a bottleneck. If a software renderer is introduced into the SFML library, then I'd expect issues like this to start appearing (or for laurent to implement it in such a way that redrawing things that haven't changed become a no-op if possible :))
Title: Not clearing the contents of a RenderWindow after Display
Post by: Laurent on May 18, 2008, 06:12:41 am
The Display() function means "display what you have rendered since last call". So if you don't draw anything between two calls of Display(), the second call won't show anything.

I agree with workmad3, there's really no point doing that. If you come back one day in big trouble because of this particular thing, ok, but right now there's no point trying to do such things.

SFML is designed for fast real-time graphics, which means we shouldn't have to care about optimizing static stuff.
Title: Not clearing the contents of a RenderWindow after Display
Post by: Kernelpanic on May 18, 2008, 12:56:37 pm
Okay, for the moment I manage the redrawing with a few pointers.
Thank you! Nice Forum!