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

Author Topic: Tile tearing vs texture smoothing  (Read 7898 times)

0 Members and 1 Guest are viewing this topic.

_Fiction_

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Tile tearing vs texture smoothing
« Reply #15 on: June 22, 2013, 07:41:39 pm »
What about if I have multiple tilesets making up the map? From what it looks like, a VertexArray only lets you draw from a single texture, so I think I would have to make a VertexArray for each texture in the scene. This would force me to do dynamic allocation each frame as the number of tiles from each tileset would change each frame. Is there a way to get around this?

EDIT: Actually, I'm pretty sure that I can find the answer to something like that somewhere on the forum. Don't want to waste anyones time with something off-topic. Thank you for your help :D

EDIT2: Here's the working version :)
« Last Edit: June 22, 2013, 09:32:55 pm by _Fiction_ »

_Fiction_

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Tile tearing vs texture smoothing
« Reply #16 on: August 10, 2013, 04:47:32 am »
Since this is related to the same issue I thought I would post it here. I originally thought I had solved my problem because the diagonals were smoothed just fine. However, we recently added in a grass texture, and with smoothing on, I get a white border on the outside of the grass, as well as an obvious line between the tiles, which should fit perfectly.


If I remove the half-pixel addition to each size of a tile that was recommended earlier in this thread, the line between the tiles is now gone, but all of the grass now has a white border (and the tiny lines of pixels that jut out from the OP return).


To avoid the jutting pixels and the white grass tips, I turn smoothing off. Both of these issues are gone, but my original problem now remains. The diagonals are once again adding extra pixels, creating a jagged look. Another but also came up, which adds/removes single lines of pixels when i move around. I have highlighted both issues in the image. The vertical line of pixels is tough to see, but its a brown line that has been added to the bottom image. This can be avoided if I implement the solution from earlier, except instead of .5 extra pixels around each tile, I add an entire pixel. This of course adds the line between the grass and the floor again, and causes a bunch of other issues.




In case it comes up, I am rounding my view coordinates to an integer, so that is not the issue. The resolution I am using on my view is 1920, 1080. When I zoom in far enough on the issues in the last image, they both go away. Note sure if that helps. My current code for drawing my tiles is:

for( int tx = leftTile; tx < rightTile; ++tx )
                {
                        for( int ty = topTile; ty < bottomTile; ++ty )
                        {
                                if( staticTileSets[tx][ty] != NULL )
                                {
                                        int tc = ((tx - leftTile) + (ty - topTile) * viewHalfWidthTiles * 2) * 4;

                                        VertexArray &map = *(texVertexMap[staticTileSets[tx][ty]->texture]);
                                        // define the position of the 4 points of the current tile
                                        map[tc + 0].position = sf::Vector2f((tx + 0) * tileSize, (ty + 0) * tileSize);
                                        map[tc + 1].position = sf::Vector2f((tx + 0) * tileSize, (ty + 1) * tileSize);
                                        map[tc + 2].position = sf::Vector2f((tx + 1) * tileSize, (ty + 1) * tileSize);
                                        map[tc + 3].position = sf::Vector2f((tx + 1) * tileSize, (ty + 0) * tileSize);

                                        // define the texture coordinates of the 4 points of the current tile
                                        float blend = .5f;
                                        int ix = staticTileSets[tx][ty]->GetSubRect( staticLocalID[tx][ty] ).left / tileSize; // X index of the tile in the tileset
                                        int iy = staticTileSets[tx][ty]->GetSubRect( staticLocalID[tx][ty] ).top / tileSize; // Y index of the tile in the tileset ;
                                        map[tc+ 0].texCoords = sf::Vector2f((ix + 0) * tileSize + blend, (iy + 0) * tileSize + blend);
                                        map[tc+ 1].texCoords = sf::Vector2f((ix + 0) * tileSize + blend, (iy + 1) * tileSize - blend);
                                        map[tc+ 2].texCoords = sf::Vector2f((ix + 1) * tileSize - blend, (iy + 1) * tileSize - blend);
                                        map[tc+ 3].texCoords = sf::Vector2f((ix + 1) * tileSize - blend, (iy + 0) * tileSize + blend);
                                }
                                else
                                {
                                }
                        }
                }
               
                for( std::map<sf::Texture*, sf::VertexArray*>::iterator mapIt = texVertexMap.begin();
                        mapIt != texVertexMap.end(); ++mapIt )
                {
                        window->draw( *(*mapIt).second, (*mapIt).first );
                }
 


_Fiction_

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Tile tearing vs texture smoothing
« Reply #17 on: August 17, 2013, 06:37:43 am »
Is bumping allowed here? Doesn't seem like I'm getting any responses :(