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

Author Topic: [solved][sfml 2.0]Text not always rendering correctly  (Read 2044 times)

0 Members and 1 Guest are viewing this topic.

Inubis

  • Newbie
  • *
  • Posts: 8
    • View Profile
[solved][sfml 2.0]Text not always rendering correctly
« on: February 23, 2013, 12:48:49 pm »
SFML beginner here. I'm having weird issues with rendering text. I'm writing a program that reads nodes, any edges and then draws them to the screen. I want each node to have a number. The issue is that adding some stuff to the program(like setting the outline color for the nodes) breaks the text, showing it as squares. Relevant piece of code:

Code: [Select]
sf::CircleShape node[11];
sf::Font font; font.loadFromFile("arial.ttf");
sf::Text nodeNumber("",font,15.f);
nodeNumber.setStyle(sf::Text::Bold);
nodeNumber.setColor(sf::Color::White);

for(int i=1; i<=n; i++)
{
        node[i].setRadius(15.f);
        node[i].setFillColor(sf::Color(78,190,218));
        //node[i].setOutlineThickness(1.f);
        //node[i].setOutlineColor(sf::Color(0,120,120));
        node[i].setPosition(pos[i][0],pos[i][1]);
}
//...some code
for(int i=1; i<=n; i++)
{
        window.draw(node[i]);
        nodeNumber.setString(char('0'+i));
        nodeNumber.setPosition(pos[i][0]+10,pos[i][1]+6);
        window.draw(nodeNumber);
}



As you can see, it works fine. However, adding outline to the nodes(commented out) causes this:



Thanks.

edit: I'm using Windows 7 32bit with an AMD B55 CPU and AMD HD5770 video card.
« Last Edit: February 23, 2013, 01:28:14 pm by Inubis »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [sfml 2.0]Text not always rendering correctly
« Reply #1 on: February 23, 2013, 12:57:29 pm »
You must update your graphics card's drivers.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: [sfml 2.0]Text not always rendering correctly
« Reply #2 on: February 23, 2013, 12:59:35 pm »
Why do you begin iteration at index 1 and stop at n?

The valid indices are 0 up to size-1. And I recommend std::array or std::vector instead of arrays, they are also able to detect index errors and have a lot of other comfortable features.

If the error persists and you've updated your driver, come up with a minimal and complete example.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Inubis

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: [sfml 2.0]Text not always rendering correctly
« Reply #3 on: February 23, 2013, 01:22:44 pm »
Thanks. Updating the drivers did the trick.

@Nexus Mostly because by starting the indexing from 1, identifying the nodes is easier. Also helps a lot with the adjacency matrix. As for the second part, only lately I've started studying the OOP/STD side of C++ (I know, it's stupid but the school taught us "c with cout" and didn't focus on the actual improvements of c++ over c)
« Last Edit: February 23, 2013, 01:33:03 pm by Inubis »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: [solved][sfml 2.0]Text not always rendering correctly
« Reply #4 on: February 23, 2013, 01:59:45 pm »
You can also write an adapter function at() that translates indices, so you don't always have a never-used element:
sf::CircleShape& shape = at(array, index); // same as array[index-1]

Yeah, it's a pity most people learn C++ wrongly. I really recommend to take a look at the STL, it is something you will always use.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything