SFML community forums
Help => Graphics => Topic started by: Sythical on July 02, 2013, 02:37:57 am
-
Hello, let's say if I draw a 50 by 50 rectangle at (-200, -200), will SFML actually draw the rectangle or simply ignore it since the rectangle won't be visible on the screen. I'm asking this because at the moment I am only drawing sprites that will be visible but now I'm not sure if there is any point in checking.
Thank you :)
-
Well they are not "rendered", otherwise you'd see them, but they will get processed and thus use up CPU & GPU time. SFML does not auto-clip things, so it's something you'll have to implement. :)
-
Thank you for your answer :)
Sorry, yes I meant processed instead of rendered. Doesn't this mean that using sf::View is a bad idea, since in larger maps a lot of unnecessary stuff will be drawn? Or are the graphics cards good enough that I shouldn't be worrying about this when making 2D games?
-
Doesn't this mean that using sf::View is a bad idea, since in larger maps a lot of unnecessary stuff will be drawn?
No, it's perfectly fine to work with sf::View, but as I said, you're resposible for only drawing what's really being displayed. So if you're at the top-left corner of the map, there's no reason for processing the part at the bottom-right corner.
Or are the graphics cards good enough that I shouldn't be worrying about this when making 2D games?
It always depends on the actual size and on the age of the notebooks you want to make your game run on. Newer graphics card will handle quite a big space, where as older one, need more optimization.
-
Okay, that does make sense. Thank you for your help!
-
I wonder - if I have a large worldspace and have lots of things to draw scattered on that world, should it take less time to check each object if it is actually visible (AABB intersection with appropriate transforms) before drawing than to just draw it all?
-
It's not about the time it takes to cull the hidden vertices/fragments, your GPU probably culls much faster than you can with your AABBs, using all sorts of tricks. It is about saving the data upload to the GPU. If you have to upload 1GB of vertex data every frame only to have 99% of it get discarded, you will notice an FPS decrease. Reduce the transfer size by culling yourself and sending only what is necessary.
There are also more efficient ways of determining if something is visible or not other than AABBs, which in your approach is O(n). A widely known algorithm to speed detection up is binary space partitioning (http://en.wikipedia.org/wiki/Binary_space_partitioning).