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

Author Topic: Displaying text error SFML 1.6  (Read 1769 times)

0 Members and 1 Guest are viewing this topic.

Grisnak

  • Newbie
  • *
  • Posts: 8
    • View Profile
Displaying text error SFML 1.6
« on: July 28, 2012, 05:53:00 pm »

So I'm using the arial font and I have a statement in the console window that says success when the font is successfully loaded and error when it doesn't. I've tried 6 different fonts but all of them give me the same mangled result as the one in the picture. The text in the picture should say "ERMAGERD" and if you look closely, there's 8 character spaces but it appears as if the characters have been randomly cropped and flipped around  :-[
If anyone could help me out I'd really appreciate it  :D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Displaying text error SFML 1.6
« Reply #1 on: July 28, 2012, 08:39:05 pm »
Please give more details (code, version of SFML, ...)

http://en.sfml-dev.org/forums/index.php?topic=5559.msg36367#msg36367
Laurent Gomila - SFML developer

Grisnak

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Displaying text error SFML 1.6
« Reply #2 on: July 28, 2012, 11:55:31 pm »
Please give more details (code, version of SFML, ...)

http://en.sfml-dev.org/forums/index.php?topic=5559.msg36367#msg36367

I apologize for not having read the rules before!

I'm using visual studio 2010 on a windows 7 32 bit OS  with SFML v1.6


//TEXT CLASS HEADER

#pragma once
#include <SFML\Graphics\Font.hpp>
#include <SFML\Graphics\String.hpp>
#include <string>
#include <iostream>

class Text
{
public:
        Text(std::string b, float _x, float _y); //takes a string to output and position coordinates
        sf::Font myFont; //the font object
        std::string a;
        sf::String theText; //the string object
        float x; //the x coordinate for the text to be printed
        float y; //the y coordinate for the text to be printed
};
 

Text class cpp
#include "Text.h"

Text::Text(std::string b, float _x, float _y)
{
        if (!myFont.LoadFromFile("Fonts/BAUHS93.ttf"))
        {
                std::cout<<"Error loading the text HURRRRR DURRRRR \n";
        }
        else
        {
                std::cout<<"TEXT SUCCESSS ERMAGERD \n";
        }
        this->a = b;
        this->x = _x;
        this->y = _y;
        theText.SetFont(this->myFont);
        theText.SetText("ERMAGERD");
        theText.SetColor(sf::Color(0, 128, 128));
        theText.SetPosition(200.f, 300.f);
        theText.SetRotation(0.f);
        theText.SetSize(50.f);
}
 

The code blow is a segment from the main where the game is being drawn. Right now theGame is an object in the main and the update loop is a member of it. Test is the name of the level object. Each level in the game is it's own object containing that level's respective data. The level objects are members of the Game class and test is a "test level". Hello is an object of the Text class from above and theText is a string object that is a member from the class above.

theGame, test, and hello objects as they appear in the snippet below are all pointers to the objects (I think)
When you put the cursor over the respective objects they appear as
"Game *theGame"
"Level *test"
"Text *hello"
"sf::String Text::theText"


theGame->draw();
                        if(theGame->test->isLoaded==true)
                        {
                                sf::String paddy = theGame->test->hello->theText;
                                App.Draw(paddy);
                        }
                        App.Display();

 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Displaying text error SFML 1.6
« Reply #3 on: July 29, 2012, 10:39:31 am »
Can you show how you use the Text class?

My guess is that the instance is copied somewhere (probably implicitely, when passed by copy to a function), and therefore the sf::String -> sf::Font link is broken. This is similar to what you can read at the end of the sf::Sprite tutorial.
Laurent Gomila - SFML developer

Grisnak

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Displaying text error SFML 1.6
« Reply #4 on: July 29, 2012, 02:46:17 pm »
Can you show how you use the Text class?

My guess is that the instance is copied somewhere (probably implicitely, when passed by copy to a function), and therefore the sf::String -> sf::Font link is broken. This is similar to what you can read at the end of the sf::Sprite tutorial.

sure
the object is declared in the level class header file as Text *hello;
It's intantiated in the loadtestLevel() function below.
I also wanted to know if the SetText function can take a std::string variable as a parameter? It doesn't give me an error when I do it but no text appears when I run the program  :-\

void Level::loadtestLevel()
{
        std::string a = "hi this is some text";
        hello = new Text(a, 200.f, 300.f);
}
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Displaying text error SFML 1.6
« Reply #5 on: July 29, 2012, 02:57:42 pm »
You should try to reproduce this problem in a complete and minimal example, so that we can test it and point out the error easily.
Laurent Gomila - SFML developer

Grisnak

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Displaying text error SFML 1.6
« Reply #6 on: July 30, 2012, 02:44:44 am »
hmmm so the code below still gives me the same error :\ I put it in my main function
                        sf::String Text;
                        Text.SetText("ERMAGERD");
                        Text.SetFont(sf::Font::GetDefaultFont());
                        Text.SetColor(sf::Color(0, 128, 128));
                        Text.SetPosition(200.f, 300.f);
                        Text.SetSize(50.f);
                        App.Draw(Text);
 

Grisnak

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Displaying text error SFML 1.6
« Reply #7 on: July 30, 2012, 04:28:11 am »
The error even happened with the tutorial file from the 1.6 rendering text tutorial

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Displaying text error SFML 1.6
« Reply #8 on: July 30, 2012, 08:20:57 am »
You should switch to SFML 2 if possible.
Laurent Gomila - SFML developer

Grisnak

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Displaying text error SFML 1.6
« Reply #9 on: July 30, 2012, 07:06:24 pm »
Hmm so I've been getting opengl errors as well in my console now
"an internal opengl call failed in rendertarget.cpp <90> a numeric argument is out of range" :\

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Displaying text error SFML 1.6
« Reply #10 on: July 30, 2012, 07:16:51 pm »
Are your graphics drivers up to date?
Laurent Gomila - SFML developer

Grisnak

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Displaying text error SFML 1.6
« Reply #11 on: July 30, 2012, 09:09:24 pm »
I'm using the beta drivers from Nvidia for my Quadro NVS 4200M
Beta Driver 304.79 32 bit

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Displaying text error SFML 1.6
« Reply #12 on: July 30, 2012, 10:17:10 pm »
Could you try stable drivers?
Laurent Gomila - SFML developer

Grisnak

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Displaying text error SFML 1.6
« Reply #13 on: July 31, 2012, 02:38:05 am »
Alright so I reverted to stable and still nothing  :-\

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Displaying text error SFML 1.6
« Reply #14 on: July 31, 2012, 08:17:46 am »
Can you show a complete and minimal code that reproduces the problem?
Laurent Gomila - SFML developer