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

Author Topic: 1024 x 1024 tile map  (Read 4119 times)

0 Members and 1 Guest are viewing this topic.

LimeFruut

  • Newbie
  • *
  • Posts: 3
    • View Profile
1024 x 1024 tile map
« on: June 23, 2017, 02:01:45 am »
I was browsing the forum and I've read the tutorial on drawing tile maps, but it uses quads only. I would like to use a vector of vertex in order to draw each line of the array as a triangle strip, but I don't know how to do it yet. Currently this is the way I am storing each tile type from a file. I plan to use this array for path finding at a later point. Maybe I can use this to insert into the vertex vector?

if (file.is_open())
   {
      while (!file.eof())
         for (int row = 0; row < 1024; row++)
         {
            getline(file, line);
            stringstream ssLine(line);
            for (int col = 0; col < 1024; col++)
            {
               string sValue;
               getline(ssLine, sValue, ',');

               stringstream convertor(sValue);
               convertor >> MapTiles[row][col];
            

            }
         }

      file.close();
   }

the idea is to to have 1024 triangle strips, which I will draw, thus making it quicker.

Thanks in advance!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: 1024 x 1024 tile map
« Reply #1 on: June 23, 2017, 06:28:32 am »
You didn't tell us with what you're stuck with. How can we help you?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

LimeFruut

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: 1024 x 1024 tile map
« Reply #2 on: June 23, 2017, 11:05:56 am »
So what I want to do is create the vertecies while im filling up the array. So every 1024 columns would be 1 triangle strip. Also I am aware that i have to select the texture/color of the maptile as I am giving them vector2f value. This way I would reduce my draw calls from 1024*1024 to only 1024

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: 1024 x 1024 tile map
« Reply #3 on: June 23, 2017, 04:47:55 pm »
Like eXpl0it3r, I'm not sure I'm understanding what your actual question is. I think I understand what you are trying to do, but what are you actually stuck on? Here is the tutorial for vertex arrays. Is this the one you read? Do you not know how to even get started or are you just unsure on how to calculate the position of the vertices?

LimeFruut

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: 1024 x 1024 tile map
« Reply #4 on: June 23, 2017, 05:40:43 pm »
So I've added this method to the loop which creates 4 vertecies in a
vector<vector<sf::Vertex>> vertices;

this is the way I'm currently assigning them

void CGameMap::CreateRenderingVertecies(int row,int col)
{
   int temp = col * 4;
   sf::Vertex* tStrip = &vertices[row][temp];
   tStrip[0].position = sf::Vector2f(temp / 4 * multiplier row * multiplier);
   tStrip[1].position = sf::Vector2f(temp / 4 * multiplier, (row + 1) * multiplier);
   tStrip[2].position = sf::Vector2f((temp / 4 + 1)*multiplier, row * multiplier);
   tStrip[3].position = sf::Vector2f((temp / 4 + 1)*multiplier, (row + 1) * multiplier);

   tStrip[0].texCoords = sf::Vector2f(0, 0);
   tStrip[1].texCoords = sf::Vector2f(0, 16);
   tStrip[2].texCoords = sf::Vector2f(16, 0);
   tStrip[3].texCoords = sf::Vector2f(16, 16);
}

I am not sure, how to attach the texture and/or states in order to use it in my draw method where im passing a reference of the window.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: 1024 x 1024 tile map
« Reply #5 on: July 01, 2017, 04:09:01 pm »
For a row of triangle strips, it's better to think of it in terms of two vertices at a time rather than four: top then bottom for each side (strip edge or adjoining quads). The number of these "sides" should be the number of quads plus one. Basically, loop quad+1 number of times and process only two vertices at a time.

Note that 1024 draw calls (one for each row vertex array) can be quite a lot. It would make more sense to draw the entire map with just one call: add each row to the same vertex array. You can use the triangle strip to draw all rows in one go!
There are a couple of things to note:
  • the "sides" should be processed in an alternating direction. e.g. right, then left, then right etc.
  • you can (although it's not necessary) miss off the duplicated vertex (the final one of the row is the same as the first one of the next row)

You may want to consider that it's simpler to just use quads (instead of a triangle strip) in a single vertex array. That is, you can just add multiple (mostly) independent quads to a vertex array. This is still only one draw call, which is better than 1024 triangle strips and much better than the call per quad that you were originally trying to avoid.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: 1024 x 1024 tile map
« Reply #6 on: July 02, 2017, 01:19:10 am »
you want a tilemap made of triangles? like this?


is that it?
Visit my game site (and hopefully help funding it? )
Website | IndieDB