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

Author Topic: Errors in Vertex Arrays Tutorial for SFML 2.0  (Read 4060 times)

0 Members and 1 Guest are viewing this topic.

natesdakota

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Errors in Vertex Arrays Tutorial for SFML 2.0
« on: May 02, 2013, 10:25:17 pm »
Hi,

I was reading through the tutorial module on vertex arrays, and I found a few code typos that might need to be fixed.

Please take a look at the tilemap example.  When you are getting the position of the tile's texture from the texturemap, the tu variable is wrong.  It currently reads:

int tu = tileNumber / (m_tileset.getSize().x / tileSize.x);

A modulus should be used there instead like this:

int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);

Another couple of errors I found is when you define the quad's four corners.  If you look at top left and bottom left corner the code is:

quad[0].position = sf::Vector2f(i) * tileSize.x, j * tileSize.y);
quad[3].position = sf::Vector2f(i) * tileSize.x, (j + 1) * tileSize.y);

You're closing out those two parenthesis too early.  The code should be something like:

quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);

Those corrections might be helpful for someone that's new to coding.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Errors in Vertex Arrays Tutorial for SFML 2.0
« Reply #1 on: May 03, 2013, 08:37:34 am »
Quote
When you are getting the position of the tile's texture from the texturemap, the tu variable is wrong.
No it's right. When you want to extract a row and a column from a single index, you use a divide for one dimension and a modulus for the other. If I apply your modification, tu and tv will always be equal (given that the tilemap is a square).

Quote
You're closing out those two parenthesis too early.
Right, this doesn't even compile (damn, I was sure I pasted the exact code that I compiled and ran to take the screenshot...).

Thanks for your feedback.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Errors in Vertex Arrays Tutorial for SFML 2.0
« Reply #2 on: May 03, 2013, 01:43:05 pm »
Fixed.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Errors in Vertex Arrays Tutorial for SFML 2.0
« Reply #3 on: May 05, 2013, 02:39:23 pm »
Although your formula was not exactly the right one, it seems that you were right, mine was wrong too ;D

It's fixed now.
Laurent Gomila - SFML developer