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

Author Topic: Vertex array not drawing all points  (Read 4868 times)

0 Members and 1 Guest are viewing this topic.

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Vertex array not drawing all points
« on: February 09, 2014, 12:05:47 am »
When I fill up a sf::VertexArray with a primitive type as Points, it does not draw all points I add to the array. For example, a vertex array filled as
sf::VertexArray vertexarray(sf::Points);
for (int i = 50; i < 400; i++) {
    sf::Vertex vertex(sf::Vector2f(i,50),sf::Color::Green);
    vertexarray.append(vertex);
}
will show something like

which is not what I intended.

How is this happening? Do the vertex coordinates not match the window coordinates exactly or something along these lines?
I'm using this to try and check my algorithms to make sure I have collected all points and didn't omit any. I'll be using it for quad-trees and pixel perfect collision.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Vertex array not drawing all points
« Reply #1 on: February 09, 2014, 01:20:16 am »
That's odd. I just had exactly the same problem just now. However, I fixed it as I've read through this forum.
It is - apparently - due to some rounding by OpenGL of coordinates and the fix seems to be to add a half to the coordinates.
So, try
sf::Vertex vertex(sf::Vector2f(i + 0.5f, 50.5f), sf::Color::Green);
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: Vertex array not drawing all points
« Reply #2 on: February 09, 2014, 02:09:01 am »
Thanks for the quick reply! The method seems to work, but it is indeed very odd.. Since it should be due to OpenGL, why does it only happen while using vertices as points? Does SFML account for this internally?

Where did you find that post? I've searched a number of posts, but couldn't find any related problem.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Vertex array not drawing all points
« Reply #3 on: February 09, 2014, 02:50:25 am »
I'm not sure, sorry. I read it a day or so ago and remembered it when I started getting those artefacts.
I don't know how much work SFML does to compensate for this rounding. It could be none, or it could be most things.  ???

Anyway, glad it works now and I'm glad I could help! :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Vertex array not drawing all points
« Reply #4 on: February 09, 2014, 09:28:11 am »
Points (or lines) expand half their width (0.5) in each direction, the coordinate that you give is the center. So if you want your point/line to fully cover a pixel, you must give its center position, which is xxx.5.
Laurent Gomila - SFML developer

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: Vertex array not drawing all points
« Reply #5 on: February 09, 2014, 11:44:20 am »
I'm not sure, sorry. I read it a day or so ago and remembered it when I started getting those artefacts.
I don't know how much work SFML does to compensate for this rounding. It could be none, or it could be most things.  ???

Anyway, glad it works now and I'm glad I could help! :)
No problem. That question wasn't aimed specifically at you ;)

Points (or lines) expand half their width (0.5) in each direction, the coordinate that you give is the center. So if you want your point/line to fully cover a pixel, you must give its center position, which is xxx.5.
Aha, and the distance they cover eventually get rounded to int's then I suppose? Thanks already for the explanation!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Vertex array not drawing all points
« Reply #6 on: February 09, 2014, 12:31:11 pm »
Quote
Aha, and the distance they cover eventually get rounded to int's then I suppose?
Yes, you cannot light less than one full pixel on your screen ;)
Laurent Gomila - SFML developer

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Vertex array not drawing all points
« Reply #7 on: February 09, 2014, 03:34:34 pm »
Points (or lines) expand half their width (0.5) in each direction, the coordinate that you give is the center. So if you want your point/line to fully cover a pixel, you must give its center position, which is xxx.5.
That explains everything. Thanks :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything