SFML community forums
Help => Graphics => Topic started 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.
-
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 ?
-
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.
-
They might look blurrier if you load the font with a character size too low.
-
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 :)
-
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.
-
But to use the same size as the font itself is the best right?
-
Yes, as no stretching will occur ;)
-
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.
//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?
-
Are you sure your font object is still alive when you're rendering the string ?
-
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.. :(
-
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 ?
-
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
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:
#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... :)
-
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.
-
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..
-
It should work. Can you show us your new code ?
-
The code is all over the place.. i hope thats not a problem..
main.cpp
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
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
#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.
-
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 ;)
-
Got it thanks...
fixed it with TextString.SetFont(Font);
in the constructor.
Thanks a lot.. :)