SFML community forums

Help => Graphics => Topic started by: dabo on March 07, 2008, 11:41:47 am

Title: The new font class
Post by: dabo on March 07, 2008, 11:41:47 am
Hi, I was wondering is the interface / management the only new thing then you handle fonts? or are they drawn differently on the screen too? in other words do they look different when you draw them than they did before the font class? For a second I though they looked differently but they probably don't.
Title: The new font class
Post by: Laurent on March 07, 2008, 12:07:36 pm
Maybe they are a bit different (I rewrote some parts of the rendering code), but it's not supposed to be worse.

The main thing which could be different is that the fonts are no more reloaded to fit the strings maximum size ; they just keep the size you loaded them with.

What difference did you notice exactly ?
Title: The new font class
Post by: dabo on March 07, 2008, 04:57:40 pm
Quote from: "Laurent"
Maybe they are a bit different (I rewrote some parts of the rendering code), but it's not supposed to be worse.

The main thing which could be different is that the fonts are no more reloaded to fit the strings maximum size ; they just keep the size you loaded them with.

What difference did you notice exactly ?


They didn't look as smooth and nice as they did before I downloaded the latest source. But I'm gonna take a closer look later today, maybe I was just tired last night.
Title: The new font class
Post by: Laurent on March 07, 2008, 05:20:08 pm
They might look blurrier if you load the font with a character size too low.
Title: The new font class
Post by: dabo on March 07, 2008, 08:08:51 pm
Well, i know what it is now. Setting the second parameter in LoadFromFile() to the same size as the font size did the trick. I didn't know what the second parameter did so I used the default value that's why it looked worse. I'm still not sure what it is but at least it looks great now again.

Sorry, should have tried that before but it just hit me :)
Title: The new font class
Post by: Laurent on March 08, 2008, 04:32:49 am
The size you give to LoadFromFile is the size of one character in the texture which will be created. So the higher the size, the more precise the rendering of the characters.
Title: The new font class
Post by: dabo on March 08, 2008, 12:08:11 pm
But to use the same size as the font itself is the best right?
Title: The new font class
Post by: Laurent on March 08, 2008, 12:12:02 pm
Yes, as no stretching will occur ;)
Title: The new font class
Post by: dbest on March 16, 2008, 09:34:10 pm
Didnt want to start a new thread, so i hope its ok if i hijack this one..

Am working on the code from the SVN, i have compiled the libs.

Am having an issue with the String class.

I have have the following functions.
Code: [Select]

//constructor to load the string with the required font
CText::CText()
{
 //  Font.LoadFromFile("cheeseburger.ttf");
 //  sf::String TextString(L"",Font);
}
//to plot the text on the screen
void CText::Plot(sf::RenderWindow& App, char text[10], int r, int g, int b, int x, int y, int size)
{
  //  Font.LoadFromFile("cheeseburger.ttf");
  //  sf::String TextString(L"",Font);
    TextString.SetText(text);
    TextString.SetSize(size);
    TextString.SetColor(sf::Color(r,g,b));
    TextString.SetPosition(x,y);

    App.Draw(TextString);
}




When the font is loaded in the constructor, the text is not plotted clearly on the screen. The output is all blobby, looks like square.
The text is plotted clearly when i load the font into the string in the Plot function.


Does anyone else face this issue?
Title: The new font class
Post by: Laurent on March 17, 2008, 02:12:05 am
Are you sure your font object is still alive when you're rendering the string ?
Title: The new font class
Post by: dbest on March 17, 2008, 05:56:51 am
Using the code from the SVN, i have added only the FONT object and intialized the STRING object with the "cheeseburger.ttf" font.

When I used the same code without the modifications mentioned above and compiled it with SFML release 1.2, it worked fine.

The code as posted above, should now by default use arial.ttf and plot fine. But it does not.. :(
Title: The new font class
Post by: Laurent on March 17, 2008, 07:04:38 am
Youy didn't answer my question ;)

Can you show us the declaration of your CText class ?

If you use the default built-in font, is it working ?
Title: The new font class
Post by: dbest on March 17, 2008, 10:59:00 am
Yups, i think i didnt :(

Okies, i dont have the system with me, rite now, as I am in the office... but this is as best as I can remember..

in CText.h
Code: [Select]

class CText {

private:
sf::Font Font;
sf::String TextString;

public:
CText();
~CText();

Plot(sf::RenderWindow& App, char text[10], int r, int g, int b, int x, int y, int size);
};


The code i posted in ma previous mail is CText.cpp.

The summarized main.cpp is like this:

Code: [Select]
#include "CText.h"

CText Text;

int main()
{
..........
..........

Text.Plot(App,"text here", 255,255,200, 200, 20, 22); --> This is where i call the function
App.Draw();
}



I hope i have answered your question... so help me please... :)
Title: The new font class
Post by: Laurent on March 17, 2008, 11:59:10 am
I think you have such problem because CText is global, and is constructed before the OpenGL context (so the font texture fails to load -- you could see it in the error log).

This is fixed in the current sources.
Title: The new font class
Post by: dbest on March 17, 2008, 03:44:39 pm
It worked once I initialed Text after the RenderWindow is constructed.
But i still need to set the Font to the string in the Plot function. It does not work if the Font is assigned to the string in the constructor. Its not a big deal, as the FPS is still the same. :)

Thanks for your help..
Title: The new font class
Post by: Laurent on March 17, 2008, 04:13:28 pm
It should work. Can you show us your new code ?
Title: The new font class
Post by: dbest on March 17, 2008, 04:27:54 pm
The code is all over the place.. i hope thats not a problem..

main.cpp

Code: [Select]
int main()
{
      /// Create the main window
    sf::RenderWindow App;

    App.Create(sf::VideoMode(SCREENWIDTH, SCREENHEIGHT, 32), "SFML Window", sf::Style::Fullscreen);

    CText Text;
....
....
Text.Plot(App,"UITILE", 200,0,128,200,10,15);



text.h

Code: [Select]
class CText {
    private:
    sf::String TextString;
    sf::Font Font;

    public:
    CText();
    ~CText();

    ///Create text string with size and color
    void Plot(sf::RenderWindow& App, char text[10], int r, int g, int b, int x, int y, int size=20);
};


text.cpp

Code: [Select]
#include "Text.h"

CText::CText()
{
  Font.LoadFromFile("cheeseburger.ttf");
  sf::String TextString(L"",Font);
}

CText::~CText()
{
}


void CText::Plot(sf::RenderWindow& App, char text[10], int r, int g, int b, int x, int y, int size)
{
     //sf::String TextString(L"",Font);
    TextString.SetText(text);
    TextString.SetSize(size);
    TextString.SetColor(sf::Color(r,g,b));
    TextString.SetPosition(x,y);

    App.Draw(TextString);
}


If i uncomment the sf::String TextString(L"",Font); line in the Plot function, then the cheeseburger.ttf font is used, else the default font is used.
Title: The new font class
Post by: Laurent on March 17, 2008, 04:45:10 pm
Quote
sf::String TextString(L"",Font);

Here you're declaring a new variable which has nothing to do with the member of your class, and will be destroyed at the end of the constructor ;)
Title: The new font class
Post by: dbest on March 17, 2008, 07:09:29 pm
Got it thanks...
fixed it with
Code: [Select]
TextString.SetFont(Font); in the constructor.


Thanks a lot.. :)