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

Author Topic: Getting random lines rendered in VertexArray - SFML bug?  (Read 5966 times)

0 Members and 1 Guest are viewing this topic.

Chunker120

  • Newbie
  • *
  • Posts: 31
    • View Profile
Getting random lines rendered in VertexArray - SFML bug?
« 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.
« Last Edit: June 25, 2013, 03:52:47 pm by Chunker120 »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Getting random lines rendered in VertexArray - SFML bug?
« Reply #1 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
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Getting random lines rendered in VertexArray - SFML bug?
« Reply #2 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.
Laurent Gomila - SFML developer

Chunker120

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Getting random lines rendered in VertexArray - SFML bug?
« Reply #3 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()

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Getting random lines rendered in VertexArray - SFML bug?
« Reply #4 on: June 24, 2013, 09:42:15 pm »
Are your tiles located at decimal coordinates?
Laurent Gomila - SFML developer

Chunker120

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Getting random lines rendered in VertexArray - SFML bug?
« Reply #5 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);

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Getting random lines rendered in VertexArray - SFML bug?
« Reply #6 on: June 24, 2013, 10:24:40 pm »
Is the orange color part of the texture? Or is it coming from nowhere?
Laurent Gomila - SFML developer

fallahn

  • Hero Member
  • *****
  • Posts: 505
  • Buns.
    • View Profile
    • Trederia
Re: Getting random lines rendered in VertexArray - SFML bug?
« Reply #7 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.

Chunker120

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Getting random lines rendered in VertexArray - SFML bug?
« Reply #8 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.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Getting random lines rendered in VertexArray - SFML bug?
« Reply #9 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);
Back to C++ gamedev with SFML in May 2023

Chunker120

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Getting random lines rendered in VertexArray - SFML bug?
« Reply #10 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.

Chunker120

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Getting random lines rendered in VertexArray - SFML bug?
« Reply #11 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.