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

Author Topic: The best way to render a 2D tile map with vertex arrays and multiple textures  (Read 3842 times)

0 Members and 1 Guest are viewing this topic.

Jimmyee

  • Newbie
  • *
  • Posts: 21
    • View Profile
Hello. I've been trying to render a map without lose of CPU. Some day I found this: http://www.sfml-dev.org/tutorials/2.0/graphics-vertex-array.php It's a good tutorial but it didn't help me at all and there is my question: how can I render a map using vertex arrays with use of multiple textures loaded from files? My map tiles are saved in several files and I don't want to call draw() so often but only once. Should I join all the textures to a big one (if it's possible) and use it?

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
You either have one vertex array per texture, so you can draw each one with each texture, or you use some tilemaps, grouping all the textures into one.

There aren't any good workarounds to this problem :)

Jimmyee

  • Newbie
  • *
  • Posts: 21
    • View Profile
Yes, this is what I was doing last time - each tile had it's individual verticles initialized in the class constructor and the texture was chosen using the tile ID number, then they all were drawn in a MapRender class in a big loop. It's still slow so I'm just gonna use one texture for now... Until I don't find better solution :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Quote
Should I join all the textures to a big one (if it's possible) and use it?
Of course you should! If the texture is not too big.
Laurent Gomila - SFML developer

Jimmyee

  • Newbie
  • *
  • Posts: 21
    • View Profile
Oh OK. I found found needed functions.
Thank you for your opinions!
By the way, I'm new so I should tell you who I am.
I am Charlie and I'm from Poland, 20 years old. I'm making a 2D RPG using the SFML 2.0 engine. It gonna be MMO in the future but first I have to master all the functions of SFML I need. I'm a C++ programmer for like 5 years now but I don't feel like experienced with making games :P

 

anything