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

Author Topic: GWEN Text gets cut off  (Read 7299 times)

0 Members and 1 Guest are viewing this topic.

NaCl

  • Newbie
  • *
  • Posts: 18
    • View Profile
GWEN Text gets cut off
« 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.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: GWEN Text gets cut off
« Reply #1 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?
Back to C++ gamedev with SFML in May 2023

NaCl

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: GWEN Text gets cut off
« Reply #2 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.

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: GWEN Text gets cut off
« Reply #3 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: GWEN Text gets cut off
« Reply #4 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: GWEN Text gets cut off
« Reply #5 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.
TGUI: C++ SFML GUI

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: GWEN Text gets cut off
« Reply #6 on: November 03, 2014, 08:08:15 am »
Well true, I often jump to the conclusion that people use master when experiencing issues. :D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

NaCl

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: GWEN Text gets cut off
« Reply #7 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.
« Last Edit: November 03, 2014, 03:05:01 pm by NaCl »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: GWEN Text gets cut off
« Reply #8 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.
« Last Edit: November 03, 2014, 03:17:29 pm by FRex »
Back to C++ gamedev with SFML in May 2023

NaCl

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: GWEN Text gets cut off
« Reply #9 on: November 03, 2014, 04:12:29 pm »
Quote
This one? 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.
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();
}
« Last Edit: November 03, 2014, 04:14:07 pm by NaCl »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: GWEN Text gets cut off
« Reply #10 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.
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: GWEN Text gets cut off
« Reply #11 on: November 03, 2014, 04:23:22 pm »
First rebuild SFML from source though. There have many sf::Text changes after 2.1
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

NaCl

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: GWEN Text gets cut off
« Reply #12 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...

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: GWEN Text gets cut off
« Reply #13 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.
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: GWEN Text gets cut off
« Reply #14 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...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything