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

Author Topic: Are off-screen objects rendered?  (Read 4590 times)

0 Members and 1 Guest are viewing this topic.

Sythical

  • Newbie
  • *
  • Posts: 9
    • View Profile
Are off-screen objects rendered?
« 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 :)
« Last Edit: July 02, 2013, 02:40:39 am by Sythical »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Are off-screen objects rendered?
« Reply #1 on: July 02, 2013, 02:56:14 am »
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. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Sythical

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Are off-screen objects rendered?
« Reply #2 on: July 02, 2013, 03:04:19 am »
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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Are off-screen objects rendered?
« Reply #3 on: July 02, 2013, 03:11:52 am »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Sythical

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Are off-screen objects rendered?
« Reply #4 on: July 02, 2013, 03:19:09 am »
Okay, that does make sense. Thank you for your help!

raycrasher

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Are off-screen objects rendered?
« Reply #5 on: July 08, 2013, 10:55:11 am »
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?

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Are off-screen objects rendered?
« Reply #6 on: July 08, 2013, 12:29:53 pm »
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.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).