SFML community forums

Help => General => Topic started by: NaCl on November 03, 2014, 01:30:40 am

Title: GWEN Text gets cut off
Post by: NaCl on November 03, 2014, 01:30:40 am
Hi!
I use GWEN for GUI rendering because it's the only library I somehow like to use, (I'm not used to code in html and css in a C++ app, thats kindof really ugly) but I really don't like how it is internally. :-\
The problem is, that text gets cut off for specific fonts at some point. For me its now the bottom and all letters which go down, like 'y' or 'g', get the under part cut off.
To render text it does this:
Code: [Select]
sf::Text sfStr(text, *pSFFont, pFont->realsize);
sfStr.move( pos.x, pos.y );
sfStr.setColor( m_Color );
m_Target.draw( sfStr );
So I think that it's Label class uses some kind of buffer to render the text into, as this code is totally fine with the same font just without GWEN.
Does somebody now a fix? I'm searching inside its source but its really hard to get through.
Title: Re: GWEN Text gets cut off
Post by: FRex on November 03, 2014, 02:29:07 am
What exactly is the problem (what widgets setup etc.) and where did you get your GWEN from?
Title: Re: GWEN Text gets cut off
Post by: NaCl on November 03, 2014, 02:51:45 am
Any kind of text displaying object, label, button, gwen Windowtitles, ...., suffers from not displaying some glyphs completly. Got an SFML2 Render and a simple canvas, just like in the example, but not with the UnitTest of course I added some Object which has the canvas as parent.
Pulled GWEN from its git repo two days ago.
Title: Re: GWEN Text gets cut off
Post by: dabbertorres on November 03, 2014, 03:29:39 am
My guess is that GWEN is setup using an outdated sfml version. And due to the changes in text rendering, the issue stems from there. Though, that all depends on what version of SFML NaCl is using.
Title: AW: GWEN Text gets cut off
Post by: eXpl0it3r on November 03, 2014, 07:39:09 am
This is a pure GWEN issue, why don't you ask the guys over a GWEN itself?
It simply sounds like they wrongly calculate the hight.
Title: Re: GWEN Text gets cut off
Post by: texus on November 03, 2014, 07:52:21 am
This may not necessarily be an issue in GWEN.
I had several people reporting this bug about the bottom part being cropped on the TGUI forum as well.

The issue for these users was that they were using SFML 2.1. There is a bug in this version which causes text.getLocalBounds().height to be wrong. If you rely on the return of this function to do clipping then the bottom part of the text will be dropped. This bug is not in SFML 2.0 and it has already been fixed in the github version of SFML a long time ago.

So if you are using SFML 2.1 you might want to try the github version.
Title: AW: GWEN Text gets cut off
Post by: eXpl0it3r on November 03, 2014, 08:08:15 am
Well true, I often jump to the conclusion that people use master when experiencing issues. :D
Title: Re: GWEN Text gets cut off
Post by: NaCl on November 03, 2014, 03:03:30 pm
@eXpl0it3r: I don't ask them because they seem to be dead...  Sry for asking it here instead :-[

I compiled GWEN again to be 100% sure it uses the current SFML version I have installed, which seems to be indeed 2.1, (debian packages) but I don't get why the text will render correct if I don't use GWEN. Same font, same size, same sf::String initialization-stuff as it is in GWEN, and it renders fine.
Thats whats making me curious. I might try another version.
Title: Re: GWEN Text gets cut off
Post by: FRex on November 03, 2014, 03:14:58 pm
Quote
Pulled GWEN from its git repo two days ago.
This one? https://github.com/garrynewman/GWEN

You might want to compile own SFML from latest github version and then rebuild GWEN on that and see if it helps.
Also, can you post your font and example code that causes the problem? Gwen does clipping on some things it renders via few pure GL calls, maybe that's causing the issue.
Title: Re: GWEN Text gets cut off
Post by: NaCl on November 03, 2014, 04:12:29 pm
Quote
This one? https://github.com/garrynewman/GWEN (https://github.com/garrynewman/GWEN)
Yes.

Quote
Gwen does clipping on some things it renders via few pure GL calls, maybe that's causing the issue.
I think thats the issue. I don't want to use another font... :(

It's this font here (https://github.com/theleagueof/raleway).
Code: [Select]
//constructor
: _guiRenderer(&renderTarget),
  _guiSkin(&_guiRenderer)
{
    _guiSkin.Init(/*guiskinpath*/);

    _guiSkin.SetDefaultFont(/*fontpath*/, 24);
    _guiSkin.GetDefaultFont()->bold = true;

    _guiCanvas = std::move(std::unique_ptr<Gwen::Controls::Canvas>(new Gwen::Controls::Canvas(&_guiSkin)));
    _guiCanvas->SetSize(/**/);
    _guiCanvas->SetDrawBackground(true);
    sf::Color tmp = _config.getAmbient();
    _guiCanvas->SetBackgroundColor({tmp.r, tmp.g, tmp.b, tmp.a});

    _button = std::move(std::unique_ptr<Gwen::Controls::Button>(new Gwen::Controls::Button(_guiCanvas.get())));
    _button->SetText(/**/);
    _button->SetBounds(/**/);
}
//rendering
{
    canvas->RenderCanvas();
}
Title: Re: GWEN Text gets cut off
Post by: FRex on November 03, 2014, 04:19:48 pm
I meant a small main.cpp file that exhibits the problem that I (or anyone else who has GWEN and SFML installed) could test (see http://sscce.org/ ), not a copy paste of part of your project.
Title: AW: GWEN Text gets cut off
Post by: eXpl0it3r on November 03, 2014, 04:23:22 pm
First rebuild SFML from source though. There have many sf::Text changes after 2.1
Title: Re: GWEN Text gets cut off
Post by: NaCl on November 03, 2014, 04:40:18 pm
Code: [Select]
#include <SFML/Graphics.hpp>
#include <cmath>

#include "Gwen/Renderers/SFML2.h"
#include "Gwen/Input/SFML.h"

#include "Gwen/Skins/Simple.h"
#include "Gwen/Skins/TexturedBase.h"
#include "Gwen/Controls.h"

int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600), "test");
Gwen::Renderer::SFML2 GwenRenderer(App);

Gwen::Skin::TexturedBase skin(&GwenRenderer);
skin.Init("DefaultSkin.png");
skin.SetDefaultFont(L"Raleway Thin.ttf", 24);

Gwen::Controls::Canvas* pCanvas = new Gwen::Controls::Canvas(&skin);

pCanvas->SetSize(App.getSize().x, App.getSize().y);
pCanvas->SetDrawBackground(true);
pCanvas->SetBackgroundColor(Gwen::Color(150, 170, 170, 255));

Gwen::Controls::Button* pButton = new Gwen::Controls::Button(&pCanvas);
pButton->SetText(L"yyggjjppqq");
pButton->SetBounds(400, 200, 200, 200);

Gwen::Input::SFML GwenInput;
GwenInput.Initialize(pCanvas);
while(App.isOpen())
{
sf::Event Event;
while(App.pollEvent(Event))
{
if((Event.type == sf::Event::Closed))
{
App.close();
break;
}
else if(Event.type == sf::Event::Resized)
{
pCanvas->SetSize(Event.size.width, Event.size.height);
}

GwenInput.ProcessMessage(Event);
}

        App.clear();
pCanvas->RenderCanvas();
    App.display();
}

return 0;
}
Much like the GWEN SFML2 example.
I don't see any need to rebuild SFML as it works totally fine if I use SFML directly...
Title: Re: GWEN Text gets cut off
Post by: FRex on November 03, 2014, 06:29:05 pm
I've forgotten how much fun GWEN is... ;D

I was right, it's SFML2.cpp renderer issue: it clips using GL scissors and it measures text like that:
if ( pSFFont ) {
        sf::Text sfStr;
        sfStr.setString( text );
        sfStr.setFont( *pSFFont );
        sfStr.setCharacterSize( pFont->realsize );
        return Gwen::Point( sfStr.getLocalBounds().width, pSFFont->getLineSpacing( pFont->realsize ) );
    }

This is obviosuly wrong because it just chopped off the tails in your font. :P
The actual height of the text (measured from 0, 0) is top + height, not line spacing (nor just 'height', since bounds can start at non 0 y).

Changing the return to this worked for me:
return Gwen::Point( sfStr.getLocalBounds().width, sfStr.getLocalBounds().top + sfStr.getLocalBounds().height);
But feel free to experiment or research more about sf::Text and sf::Font and text measurements.
Title: Re: GWEN Text gets cut off
Post by: eXpl0it3r on November 03, 2014, 06:38:45 pm
The measurements were slightly off in SFML 2.1 as well, so even if you fix it, they might still not be how it should be, thus my recommendation for using master, but I guess you have to know it better...
Title: Re: GWEN Text gets cut off
Post by: FRex on November 03, 2014, 07:33:46 pm
Who are you talking to?
I am always using rather late SFML builds of my own and I compiled latest one just before working this out to be 100% sure it's not an old SFML bug.
Title: Re: GWEN Text gets cut off
Post by: eXpl0it3r on November 03, 2014, 07:40:41 pm
Not to you obviously...
Title: Re: GWEN Text gets cut off
Post by: NaCl on November 03, 2014, 07:44:20 pm
(http://abload.de/img/dropboxes-2014-11-03_90usm.png)
I tried this before I posted here. One issue at GWENs repo has some other functions. None works.
What SFML version did you use, FRex? He talked to me.
Okay, then I'll compile sfml master, need to install libudev-dev first at will try it with that.
So GWEN does cut the rendering using getLocalBounds and SFML internally does not? Why does it work with my depreciated version without GWEN?
Title: Re: GWEN Text gets cut off
Post by: FRex on November 03, 2014, 07:52:40 pm
Quote
Not to you obviously...
How should I know, I'm a programmer, not a clairvoyant. :P
I admit, the line between the two is often blurry.

Quote
So GWEN does cut the rendering using getLocalBounds and SFML internally does not? Why does it work with my depreciated version without GWEN?
GWEN uses GL_SCISSOR_TEST (https://www.opengl.org/sdk/docs/man2/xhtml/glScissor.xml) to limit rendering of stuff to the right areas (that for text it calculates wrong...), SFML never does anything like that.
Title: Re: GWEN Text gets cut off
Post by: NaCl on November 03, 2014, 11:06:01 pm
Thank you, I switched to current commit, sadly, as I'm a friend of packages lol, but everything is fine now.
(http://abload.de/img/dropboxes-2014-11-03_zfpfn.png)