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

Author Topic: Text appears gigantic and pixellated? (SFML 2)  (Read 2662 times)

0 Members and 1 Guest are viewing this topic.

chasemeadors

  • Newbie
  • *
  • Posts: 4
    • View Profile
Text appears gigantic and pixellated? (SFML 2)
« on: December 27, 2011, 01:15:50 am »
(This is using SFML 2)

I've encountered a problem drawing SFML Text. In my application, I use views as a sort of coordinate system for my application. Thus, a typical view would be 10 x 10 or 20 x 20. All my normal drawing functions work fine, when drawing primitives and lines, etc., and the relevant code doesn't have to know about the coordinate system - it just draws things to scale assuming the view is measured in meters.

However, when I tried to draw text to the screen, I found that it appeared gigantic. When I reduced the font size drastically, it appeared extremely blurry and pixellated, as if it were trying to render to GIANT pixels that are 1x1 in my view. I used the following code, my current view at the time is sf::View(-10, 7.5, 20, -15) (a typical graphing coordinate system)

Code: [Select]
sf::Text t(s, sf::Font::GetDefaultFont(), 5);
t.SetColor(sf::Color(0, 0, 0));
t.SetPosition(-8, -4);


Is there a way to draw text with a standard font size, in a way that it won't be affected by the view? Ideally, my text would width/size-wise on any view? Is there a way I can accomplish this?

Thanks for any input!

(P.S., I'm using SFML 2.0, for reference)
Code: [Select]

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Text appears gigantic and pixellated? (SFML 2)
« Reply #1 on: December 27, 2011, 01:27:25 am »
You can imagine the sf::View metric to consist of units (the values you specify at creation). A unit corresponds to a single pixel in the default view. This changes with custom views, your view for example contains 17.5 units in width, while a single unit covers multiple pixels.

The sf::Text with normal character size (= character height in sf::View units*) exceeds the size of your tiny sf::View. You can scale the text or (maybe simpler in the long term) abandon the use of meters.

It's not the best explanation, but I hope you still understand it ;)

____
* It's actually not the height of the whole character, rather measured from the baseline. I'm not sure though, there are documents explaining font metrics in detail.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

chasemeadors

  • Newbie
  • *
  • Posts: 4
    • View Profile
Text appears gigantic and pixellated? (SFML 2)
« Reply #2 on: December 27, 2011, 04:15:58 am »
What I don't understand is, if I create a sf::Shape primitive, say, rectangle, and tell it to have a size measured in view units, it still "fills" every pixel within the box described.

For example, if I'm in the default view (800 x 600 px), and draw a square of size 100x100 at the origin (which would be pixels), then I "zoom in" on that square, by setting the view to (0, 0, 200, 200), the square is still "continuous" on the new view, it "fills" every pixel.

However, let's say I create an sf::Text of say font size 40, and display it along with with the square. It looks normal, but when I zoom in, the text is blurred, as if it simply stretched the image.

In other words, text only looks right in a true pixel == unit view. Is sf::Text not vector graphics like other Shapes?

chasemeadors

  • Newbie
  • *
  • Posts: 4
    • View Profile
Text appears gigantic and pixellated? (SFML 2)
« Reply #3 on: December 27, 2011, 05:00:28 am »
Also, as another illustration:

800 x 600 pixel view (default):

Code: [Select]
sf::Text("Hello", sf::Font::GetDefaultFont(), 40);

now switch to a 200 x 150 view (one fourth):

Code: [Select]
sf::Text("Hello", sf::Font::GetDefaultFont(), 10);

(font size is one fourth as well)

The text fills the exact same area on the screen - as it should, because the ratio is the same (fourth size view, fourth size font size)

However, the only difference in the second version is that the text is blurry!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Text appears gigantic and pixellated? (SFML 2)
« Reply #4 on: December 27, 2011, 08:02:23 am »
Text is stretched. Glyphs are pre-rendered to a texture and then mapped on quads. So basically, a text is like a sprite.

The solution to your problem is simple: don't use your custom view to draw text, use the default one.
Laurent Gomila - SFML developer

chasemeadors

  • Newbie
  • *
  • Posts: 4
    • View Profile
Text appears gigantic and pixellated? (SFML 2)
« Reply #5 on: December 27, 2011, 10:38:22 am »
Hi Laurent, Thanks for the response.

I didn't realize until your suggestion that I'm free to change the view whenever I like in my drawing code - as long as I change it back before Display(). That does indeed solve my issue. Nice to know, though, that text behaves like a Sprite.

 

anything