Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

While working on a tile-based map I figured it would be a good idea if I would only render what the player sees on the game window, but then it occurred to me that SFML could already be optimized enough to know when it doesn't have to render those things.

Let's say I draw a 30x30 squared maps (A medium one) but the player only sees a bunch of them, not entirely. Would SFML automatically hide what the player doesn't see, or should I hide it myself?

share|improve this question
add comment

1 Answer 1

up vote 9 down vote accepted

Simple tile blitting engines will naturally cull objects outside the viewport, as they pretty much have to if using software rendering. Otherwise, the GPU will do the culling itself. Either way, the cost of the actual rendering of each tile is minimal. The speed problems are not the rendering in the graphics device, but rather the fact that your game and the high-level graphics API are doing a ton of work by simply considering rendering each tile.

That said, if you're interested in speed, culling objects on a one-by-one basis when they're outside the viewport is not going to give you much gain. You are far better off with an algorithmic approach that completely ignores entire swaths of objects that are off screen.

For a tile engine, this is as easy as calculating the bounding tiles of the viewport, and then only looping over those. Even if SFML does culling of objects, you will get a huge net gain in speed. You avoid looping over tiles that can't be seen. You avoid making draw calls for tiles that can't be seen. You avoid needing any culling code -- fast or not -- being run in the first place.

That said, a quick 10 second Google search indicates that the SFML lead developer does recommend that you do your own frustum (viewport, in 2D) culling: http://en.sfml-dev.org/forums/index.php?topic=7933.0

share|improve this answer
    
Thanks for the link, and the great answer. –  Bugster Nov 10 '12 at 19:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.