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

Author Topic: Drawing huge amount of sprites  (Read 4269 times)

0 Members and 1 Guest are viewing this topic.

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
Drawing huge amount of sprites
« on: September 27, 2009, 07:10:26 pm »
Hello. I'm trying to find enough efficient way for drawing map in my game. I want to draw 10000 (100x100) small tiles (32x32px for now). Drawing it in every frame with loop is much faster in SFML 2, but it's still to slow. I'm getting only 60fps (without vsync) on modern computer (on my old laptop it's completely unplayable). So, is there any better way to do this? I was thinking about drawing only actually visible elements, but I'm going to implement zooming (sometimes all sprites will be drawn).
It would be nice to draw all sprites in one call like OpenGL lists, but I don't know how to implement this in SFML...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Drawing huge amount of sprites
« Reply #1 on: September 27, 2009, 10:24:00 pm »
Quote
Drawing it in every frame with loop is much faster in SFML 2

Wow, I'm so glad to hear this... :lol:

Quote
I was thinking about drawing only actually visible elements, but I'm going to implement zooming (sometimes all sprites will be drawn).

Drawing only the visible tiles is straight-forward, even with zooming. As long as you don't use rotation, the view is just an aligned rectangle, just like your tiles (I assume you have an axis-aligned grid of tiles).

Quote
It would be nice to draw all sprites in one call like OpenGL lists, but I don't know how to implement this in SFML...

This is what SFML 2 does since last week (with the "automatic batching feature"), if all your tiles use the same states (blending mode, color, image).

In this scenario, rendering 100x100 tiles on my 2 year old computer (nVidia 7600 GT, Athlon 3800+), I was able to reach 100 FPS.
Laurent Gomila - SFML developer

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
Drawing huge amount of sprites
« Reply #2 on: September 28, 2009, 06:48:54 pm »
Quote
Drawing only the visible tiles is straight-forward, even with zooming. As long as you don't use rotation, the view is just an aligned rectangle, just like your tiles (I assume you have an axis-aligned grid of tiles).


Yes, but sometimes all the sprites will be drawn. When I zoom out, I'll notice a huge slowdown (especially on old computers). SFML does automatic batching, what gives me large speedup, but I still have to rebuild render queue, making a loop with 10 000 iterations in every frame. I think that it causes slowdowns.
It would be nice to see something, what'll allow me to fill render queue in static (maybe precompiled?) sprites with one call.

I was trying to render all map sprites into OpenGL list and display it by glCallList(). I reached huge speed improvement, but all sprites in list were blinking and disappearing after changing any of sf::View values...

K-Bal

  • Full Member
  • ***
  • Posts: 104
    • View Profile
    • pencilcase.bandcamp.com
    • Email
Drawing huge amount of sprites
« Reply #3 on: September 28, 2009, 07:02:07 pm »
You could draw your tilemap on RenderImages with a bigger size if your map is static.
Listen to my band: pencilcase.bandcamp.com

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Drawing huge amount of sprites
« Reply #4 on: September 28, 2009, 07:26:35 pm »
Quote
You could draw your tilemap on RenderImages with a bigger size if your map is static.

That's an option, but keep in mind that RenderImages are limited in size. You may need to use 4 of them for a 3200x3200 pixels image, on older GPUs.

Quote
It would be nice to see something, what'll allow me to fill render queue in static (maybe precompiled?) sprites with one call.

That could be an improvement for SFML 2 :)
Laurent Gomila - SFML developer

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
Drawing huge amount of sprites
« Reply #5 on: September 28, 2009, 07:36:08 pm »
I know. But the maximum size of sf::Image is too small for the large map. Of course, I can split it into smaller pieces, but that metod still takes huge ammount of memory and isn't easy to implement (some sprites can be larger than grid)...

 

anything