SFML community forums

Help => General => Topic started by: Chunker120 on June 24, 2013, 05:40:07 pm

Title: Getting random lines rendered in VertexArray - SFML bug?
Post by: Chunker120 on June 24, 2013, 05:40:07 pm
I'm making a game in SFML 2.0 (I built the source myself) with Visual Studio 2012. I made a map system with vertexArrays, and it works nicely, everything is perfect in the game except a detail.

When walking around the map, I see some lines being displayed randomly for a very short amount of time, in random places, like a stuttering graphical bug. My friend said he also experienced this with his game so it made me think it's a SFML bug rather than a coding bug. Here's a screenshot bellow, you can see the line, it randomly appeared when I took the picture. Also in this picture I zoomed in the in-game camera.
Title: Re: Getting random lines rendered in VertexArray - SFML bug?
Post by: FRex on June 24, 2013, 06:09:29 pm
Wild guess:
http://en.sfml-dev.org/forums/index.php?topic=11944.msg82959#msg82959
Texture coordinates have to be in middle of pixels so rect at 64,64 that is 32x32 has coords 64.5 64.5 95.5 95.5 not 64 64 96 96
Title: Re: Getting random lines rendered in VertexArray - SFML bug?
Post by: Laurent on June 24, 2013, 08:50:36 pm
It's probably caused by decimal coordinates. Round your view's position and everything should be ok.
Title: Re: Getting random lines rendered in VertexArray - SFML bug?
Post by: Chunker120 on June 24, 2013, 09:07:43 pm
It's probably caused by decimal coordinates. Round your view's position and everything should be ok.
I tried this, but it didn't work:

void camera::update()
{
        const int halfDistanceX = view -> getCenter().x/2;
        const int halfDistnaceY = view -> getCenter().y/2;

        if(getCornerPoint().x <= 0 && getCornerPoint().y <= 0)
                view -> setCenter((int)Player -> pos.x, (int)Player -> pos.y);
}

I could also try with roof() or floor()
Title: Re: Getting random lines rendered in VertexArray - SFML bug?
Post by: Laurent on June 24, 2013, 09:42:15 pm
Are your tiles located at decimal coordinates?
Title: Re: Getting random lines rendered in VertexArray - SFML bug?
Post by: Chunker120 on June 24, 2013, 09:59:18 pm
Are your tiles located at decimal coordinates?
Nope. Here's the code without the cast to int (Casting them to int was also a possibility, but failed)

// Set their positions
                                up_l_point.position =   sf::Vector2f((int)(index*tile_size),                            (int)(index_y*tile_size));
                                up_r_point.position =   sf::Vector2f((int)(index*tile_size + tile_size),        (int)(index_y*tile_size));
                                down_r_point.position = sf::Vector2f((int)(index*tile_size + tile_size),        (int)(index_y*tile_size + tile_size));
                                down_l_point.position = sf::Vector2f((int)(index*tile_size),                            (int)(index_y*tile_size + tile_size));

                                // Set their texture bounding box
                                up_l_point.texCoords =   sf::Vector2f((j%tiles_per_row) * tile_size, (j/tiles_per_row) * tile_size);
                                up_r_point.texCoords =   sf::Vector2f((j%tiles_per_row * tile_size) + tile_size, (j/tiles_per_row) * tile_size);
                                down_r_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size + tile_size, (j/tiles_per_row * tile_size) + tile_size);
                                down_l_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size, (j/tiles_per_row * tile_size) + tile_size);
Title: Re: Getting random lines rendered in VertexArray - SFML bug?
Post by: Laurent on June 24, 2013, 10:24:40 pm
Is the orange color part of the texture? Or is it coming from nowhere?
Title: Re: Getting random lines rendered in VertexArray - SFML bug?
Post by: fallahn on June 25, 2013, 10:42:56 am
I experienced the same thing when I was working on my Tiled map loader. I'd tried rounding the position and the half pixel trick but the only work-around I found was to load the tile set as an image, then copy each tile to a texture, pushing it onto a vector each time so that the vector indices matched the tile IDs. Oh and this was happening when drawing the tiles as sprites too.
Title: Re: Getting random lines rendered in VertexArray - SFML bug?
Post by: Chunker120 on June 25, 2013, 12:10:21 pm
Is the orange color part of the texture? Or is it coming from nowhere?

It looks like it's part of the texture, because if it wasn't, I doubt I'd see random darkened pixels, that's my artistic style.
Title: Re: Getting random lines rendered in VertexArray - SFML bug?
Post by: FRex on June 25, 2013, 12:17:59 pm
The question was if the orange pixels are pixels of next tile in your tilesheet or do they appear out of nowhere(which would be entirely different bug).

Also, try this:
                // Set their texture bounding box
                up_l_point.texCoords =   sf::Vector2f((j%tiles_per_row) * tile_size +0.5f, (j/tiles_per_row) * tile_siz +0.5f);
                up_r_point.texCoords =   sf::Vector2f((j%tiles_per_row * tile_size) + tile_size-0.5f, (j/tiles_per_row) * tile_size+0.5f);
                down_r_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size + tile_size-0.5f, (j/tiles_per_row * tile_size) + tile_size-0.5f);
                down_l_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size +0.5f, (j/tiles_per_row * tile_size) + tile_size-0.5f);
Title: Re: Getting random lines rendered in VertexArray - SFML bug?
Post by: Chunker120 on June 25, 2013, 03:39:54 pm
The question was if the orange pixels are pixels of next tile in your tilesheet or do they appear out of nowhere(which would be entirely different bug).

Also, try this:
                // Set their texture bounding box
                up_l_point.texCoords =   sf::Vector2f((j%tiles_per_row) * tile_size +0.5f, (j/tiles_per_row) * tile_siz +0.5f);
                up_r_point.texCoords =   sf::Vector2f((j%tiles_per_row * tile_size) + tile_size-0.5f, (j/tiles_per_row) * tile_size+0.5f);
                down_r_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size + tile_size-0.5f, (j/tiles_per_row * tile_size) + tile_size-0.5f);
                down_l_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size +0.5f, (j/tiles_per_row * tile_size) + tile_size-0.5f);

Yes the tile is before the grass tile, and the lines are always like that.
Title: Re: Getting random lines rendered in VertexArray - SFML bug?
Post by: Chunker120 on June 25, 2013, 03:46:32 pm
Frex's sollution seems to have worked, even though the map seems a bit more shaggy when walking around, at least there are no more lines.