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

Author Topic: %&#¤%&¤#&¤ FONTS!  (Read 2964 times)

0 Members and 1 Guest are viewing this topic.

Maximilian

  • Newbie
  • *
  • Posts: 13
    • View Profile
%&#¤%&¤#&¤ FONTS!
« on: October 14, 2013, 09:00:38 pm »
So yeah... Let's talk about ""#¤"&% fonts... I've spent two days trying to make the VERY simple line:
font.loadFromFile("C:\Windows\Fonts\Calibri.ttf");
work. But no matter what I try to to I get the good old "failed to create the font face" error... Is this a bug with Fonts?! I'm going insane... There is no minimal code to be posted, as it is litterally just that one line, in an innocent constructor... :/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: %&#¤%&¤#&¤ FONTS!
« Reply #1 on: October 14, 2013, 09:07:12 pm »
C++ basics, you have to escape the backslash character (or simply use forward slash)... ;)

But... two days? Are you sure you have nothing else to do? :P
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Maximilian

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: %&#¤%&¤#&¤ FONTS!
« Reply #2 on: October 14, 2013, 09:18:30 pm »
well... That did get it loaded... now its throwing exceptions in release mode and randomly corruption the stack in debug mode... I dont understand. I've been doing this for a long time now, and never before have I ran into something seamlessly corruption my stack -.- anyway... Here is the member function thats having issues:
void Graph::draw(sf::RenderWindow& window){
        for(int j=0; j<nodes.size(); j++){
                for(int i=0; i<nodes.at(j)->edges.size(); i++){
                        double startX=nodes.at(j)->edges.at(i)->start->x;
                        double startY=nodes.at(j)->edges.at(i)->start->y;
                        double endX=nodes.at(j)->edges.at(i)->end->x;
                        double endY=nodes.at(j)->edges.at(i)->end->y;
                        sf::Vertex line[2]={
                                sf::Vertex(sf::Vector2f(startX, startY)),
                                sf::Vertex(sf::Vector2f(endX, endY))
                        };
                        window.draw(line, 2, sf::Lines);
                        sf::CircleShape temp(5, 3);
                        temp.setOrigin(5, 5);
                        temp.setPosition(endX, endY);
                        double theta;
                        if(endX==startX&&startY<endY)
                                theta=3.1415/2;
                        else if(endX==startX&&endY<startY)
                                theta=3*3.1415/2;
                        else{
                                theta=atan((endY-startY)/(startX-endX));
                                if(endX>startX)
                                        theta=3.1415-theta;
                                if(endY>startY)
                                        theta=-theta;
                                if(endX>startX&&endY<startY)
                                        theta=-theta;
                        }
                        temp.rotate(30);
                        temp.rotate(-180/3.1415*theta);
                        temp.move(10*cos(theta), -10*sin(theta));
                        window.draw(temp);
                        std::ostringstream strs;
                        strs << nodes.at(j)->edges.at(i)->size;
                        std::string str = strs.str();
                        sf::Text tempTxt("str", font, 50);
                        tempTxt.setFont(font);
                        tempTxt.setString(str);
                        tempTxt.setPosition((startX+endX)/2+(startX-endX)/5, (startY+endY)/2+(startY-endY)/5);
                        tempTxt.setCharacterSize(12);
                        tempTxt.setColor(sf::Color(0, 255, 255, 255));
                        window.draw(tempTxt);
                }
        }
//From here and onwards the stack gets randomly corrupted...
        for(int j=0; j<nodes.size(); j++){
                sf::Text tempTxt("str", font, 50);
                tempTxt.setFont(font);
                tempTxt.setString(nodes.at(j)->name);
                tempTxt.setPosition(sf::Vector2f(nodes.at(j)->x, nodes.at(j)->y-20));
                tempTxt.setCharacterSize(12);
                tempTxt.setColor(sf::Color(255, 255, 0, 255));
                window.draw(tempTxt);
                sf::CircleShape temp(5, 60);
                temp.setOrigin(5, 5);
                temp.setPosition(sf::Vector2f(nodes.at(j)->x, nodes.at(j)->y));
                temp.setFillColor(sf::Color(255, 0, 0, 255));
                window.draw(temp);
        }
}

Anything not related directly to the font (which is a private member of the Graph class) works just fine. All the drawables work no problem... This is just so confusing -.-

EDIT: What's even better, none of this happens if I don't load the font -.-

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: %&#¤%&¤#&¤ FONTS!
« Reply #3 on: October 14, 2013, 09:26:20 pm »
Minimize your code until the mistake becomes obvious, or at least easy to find. Use the debugger to locate the exact position of the problem.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything