SFML community forums

Help => Graphics => Topic started by: Inubis on February 23, 2013, 12:48:49 pm

Title: [solved][sfml 2.0]Text not always rendering correctly
Post by: Inubis 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);
}

(http://s11.postimage.org/4eupxzlqr/22_23_2013_1_29_41_PM.png)

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

(http://s11.postimage.org/edfokgv6b/22_23_2013_1_30_18_PM.png)

Thanks.

edit: I'm using Windows 7 32bit with an AMD B55 CPU and AMD HD5770 video card.
Title: Re: [sfml 2.0]Text not always rendering correctly
Post by: Laurent on February 23, 2013, 12:57:29 pm
You must update your graphics card's drivers.
Title: Re: [sfml 2.0]Text not always rendering correctly
Post by: Nexus 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 (http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368).
Title: Re: [sfml 2.0]Text not always rendering correctly
Post by: Inubis 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)
Title: Re: [solved][sfml 2.0]Text not always rendering correctly
Post by: Nexus 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.