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

Author Topic: The new font class  (Read 8667 times)

0 Members and 1 Guest are viewing this topic.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
The new font class
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
The new font class
« Reply #1 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 ?
Laurent Gomila - SFML developer

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
The new font class
« Reply #2 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
The new font class
« Reply #3 on: March 07, 2008, 05:20:08 pm »
They might look blurrier if you load the font with a character size too low.
Laurent Gomila - SFML developer

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
The new font class
« Reply #4 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 :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
The new font class
« Reply #5 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.
Laurent Gomila - SFML developer

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
The new font class
« Reply #6 on: March 08, 2008, 12:08:11 pm »
But to use the same size as the font itself is the best right?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
The new font class
« Reply #7 on: March 08, 2008, 12:12:02 pm »
Yes, as no stretching will occur ;)
Laurent Gomila - SFML developer

dbest

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • http://wow.origo.ethz.ch/
The new font class
« Reply #8 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
The new font class
« Reply #9 on: March 17, 2008, 02:12:05 am »
Are you sure your font object is still alive when you're rendering the string ?
Laurent Gomila - SFML developer

dbest

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • http://wow.origo.ethz.ch/
The new font class
« Reply #10 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.. :(

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
The new font class
« Reply #11 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 ?
Laurent Gomila - SFML developer

dbest

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • http://wow.origo.ethz.ch/
The new font class
« Reply #12 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... :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
The new font class
« Reply #13 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.
Laurent Gomila - SFML developer

dbest

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • http://wow.origo.ethz.ch/
The new font class
« Reply #14 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..