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

Author Topic: sf::VertexArray for multiple Tilesets.  (Read 9259 times)

0 Members and 5 Guests are viewing this topic.

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
sf::VertexArray for multiple Tilesets.
« on: May 21, 2013, 11:02:52 pm »
Hi all,

After reading the documentation on the VertexArray class and textures I seem to be stuck.
It all works great.. for one tileset texture.
I have multiple tilesets which consists of 5 by 10 tiles (each tile is 32x32).

Positioning the x and y for both the screen (VertexArray.position) and the tileset (VertexArray.texCoords) is working fine.
I just need some help with how to handle multiple tilesets, I can't put my finger around this issue.

I am using SFML 2.0.
Any help or tips is highly appreciated!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::VertexArray for multiple Tilesets.
« Reply #1 on: May 21, 2013, 11:06:11 pm »
You can't, you must have one vertex array for each tileset (texture).

But 5x10 tiles of 32x32 is not a lot, can't you group your tilesets into a single bigger texture?
Laurent Gomila - SFML developer

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: sf::VertexArray for multiple Tilesets.
« Reply #2 on: May 21, 2013, 11:28:18 pm »
You can't, you must have one vertex array for each tileset (texture).

But 5x10 tiles of 32x32 is not a lot, can't you group your tilesets into a single bigger texture?
I suppose it's possible to put them into a bigger texture. But I'm not sure what the maximum dimensions are for sf::RenderTexture (assuming it could be done with this) as I have a lot of tilesets.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::VertexArray for multiple Tilesets.
« Reply #3 on: May 21, 2013, 11:53:30 pm »
It should be sf::Texture::getMaximumSize(), of which the result depends on the hardware. But most computers that are a few years old support 1024 and more...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: sf::VertexArray for multiple Tilesets.
« Reply #4 on: May 22, 2013, 12:35:16 am »
On my system this value is 16384, but I have no idea what this value is on other systems (will be released).
So I don't think this is much of a solution (I have read sf::RenderTexture had some problems on intel graphic drivers also, no idea where I have read that or what the problems were exactly).
Ill try to create a std::vector of sf::VertexArrays and tileset textures then. Thanks :-)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::VertexArray for multiple Tilesets.
« Reply #5 on: May 22, 2013, 08:00:40 am »
You can safely use 512x512 textures (I don't know how large you need the tileset to be, if there's only one).

You can avoid sf::RenderTexture, since you basically just need raw pixel copy. Use sf::Image::copy.
Laurent Gomila - SFML developer

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: sf::VertexArray for multiple Tilesets.
« Reply #6 on: May 22, 2013, 05:19:32 pm »
Faced another problem, the mapdata (tileIDs) are ofcourse spread out over the tileset textures so it wouldn't be possible to use sf::VertexArrays in the first place (I think?).

It seems the only possible solution in my case is either drawing all tile sprites individually (bad performance) or using sf::RenderTexture which is not optimal.

You can avoid sf::RenderTexture, since you basically just need raw pixel copy. Use sf::Image::copy.
Not sure what you mean by this. Could you elaborate?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: sf::VertexArray for multiple Tilesets.
« Reply #7 on: May 22, 2013, 05:56:58 pm »
The idea is that you'd load all Images(not Textures) and then compose them into big Image and load that Image into Texture using loadFromImage(). You can also use few vertex arrays, one for each Texture.
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::VertexArray for multiple Tilesets.
« Reply #8 on: May 22, 2013, 06:18:18 pm »
Quote
Faced another problem, the mapdata (tileIDs) are ofcourse spread out over the tileset textures so it wouldn't be possible to use sf::VertexArrays in the first place (I think?).

It seems the only possible solution in my case is either drawing all tile sprites individually (bad performance)
What problem is there? Sprites are vertex arrays internally, so if you can do it with a sprite you can do it with a vertex array.
Laurent Gomila - SFML developer

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: sf::VertexArray for multiple Tilesets.
« Reply #9 on: May 22, 2013, 06:40:53 pm »
Quote
Faced another problem, the mapdata (tileIDs) are ofcourse spread out over the tileset textures so it wouldn't be possible to use sf::VertexArrays in the first place (I think?).

It seems the only possible solution in my case is either drawing all tile sprites individually (bad performance)
What problem is there? Sprites are vertex arrays internally, so if you can do it with a sprite you can do it with a vertex array.
The problem is putting it all in one draw call in the end.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::VertexArray for multiple Tilesets.
« Reply #10 on: May 22, 2013, 06:44:53 pm »
Quote
The problem is putting it all in one draw call in the end.
Can you be more specific about what's blocking you?
Laurent Gomila - SFML developer

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: sf::VertexArray for multiple Tilesets.
« Reply #11 on: May 22, 2013, 06:57:19 pm »
Quote
The problem is putting it all in one draw call in the end.
Can you be more specific about what's blocking you?
My situation:
Multiple tilesets loaded into std::vector<sf::Texture>;
Not being able to put these into one big texture as it is way too much.
No idea how to reference VertexArrays to these tileset textures (std::vector) as each tileID (loaded from a file) is spread out over those textures and thus no idea how to get it so I only have to call draw (VertexArray, multiple textures) once for the entire map.

I hope its a bit more clear now.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::VertexArray for multiple Tilesets.
« Reply #12 on: May 22, 2013, 08:32:12 pm »
Quote
Not being able to put these into one big texture as it is way too much.
As I said in my first answer, you have to use one vertex array per texture. But it's still a lot better than one sprite per tile.

Quote
Not being able to put these into one big texture as it is way too much.
You still haven't said how much you would need ;)
Laurent Gomila - SFML developer

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: sf::VertexArray for multiple Tilesets.
« Reply #13 on: May 22, 2013, 08:59:30 pm »
As I said in my first answer, you have to use one vertex array per texture. But it's still a lot better than one sprite per tile.
Yeah I get this.. however I don't know how to link my tileIDs (which are loaded from a file) with those VertexArrays as each tileID could be only be used in one tileset texture.

Quote
Not being able to put these into one big texture as it is way too much.
You still haven't said how much you would need ;)
500+ tilesets. 5 by 10 tiles (each tile is 32x32). Which is too much to cram into a single texture.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::VertexArray for multiple Tilesets.
« Reply #14 on: May 22, 2013, 10:00:42 pm »
Quote
however I don't know how to link my tileIDs (which are loaded from a file) with those VertexArrays as each tileID could be only be used in one tileset texture.
But what are these tileIDs, and what do they mean at the vertex array level? Is it just another way to refer to specific texture coordinates inside a specific tileset?

Quote
500+ tilesets. 5 by 10 tiles (each tile is 32x32). Which is too much to cram into a single texture.
That's a lot, indeed.
Laurent Gomila - SFML developer

 

anything