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

Author Topic: sf::Shape rendering seems to break sf::Text rendering (2.0RC)  (Read 21430 times)

0 Members and 1 Guest are viewing this topic.

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #15 on: November 01, 2012, 08:28:55 pm »
I'm using a Radion HD 5750 (and version 12.10 of the drivers,) and I experience the same problem using the latest source.  Well, not quite the latest -- I haven't updated for the static library fix.  While playing around with the code Kylotan provided to show the issue, I found that changing either of the background or outline alpha settings to 0 (or setting the outline thickness to 0) caused the text to display properly.  I also noticed that drawing the rectangle elsewhere on the screen still seems to screw up the display of the text.

When I put together some code to test multiple scenarios in one run, that behavior disappeared, so I suspect it had something do with the initial state of the graphics subsystem.

This was the code for reference:
#include <SFML/Graphics.hpp>

struct Scenario {
    sf::Color background ;

    sf::Color box_fill ;
    sf::Color box_outline ;
    sf::Vector2f box_position ;
    sf::Vector2f box_size ;
    float box_outline_thickness ;

    sf::Text text ;
};

void doScenario(sf::RenderWindow& window, const Scenario& s) ;

int main()
{
    sf::RenderWindow window(sf::VideoMode(150, 150), "Test");

    sf::Font font ;
    font.loadFromFile("sketchflow.ttf") ;
   
    sf::Text text("abcdefgh", font) ;
    text.setPosition(sf::Vector2f(10.0f,10.0f)) ;
    text.setCharacterSize(20) ;

    const sf::Color bg(10, 30, 10) ;
    const sf::Vector2f offTextPos(10.0f, 100.0f) ;
    const sf::Vector2f throughTextPos(10.0f, 25.0f) ;
    const sf::Vector2f onTextPos ( 10.0f, 10.0f ) ;

    const sf::Color fill_alphaOff(128, 128, 128, 0) ;
    const sf::Color fill_alphaOn(128, 128, 128, 255) ;
    const sf::Color fill_alphaMid(128, 128, 128, 128) ;

    const sf::Color outline_alphaOff(255, 255, 255, 0 ) ;
    const sf::Color outline_alphaOn(255, 255, 255, 255) ;
    const sf::Color outline_alphaMid(255, 255, 255, 128) ;

    const float thicknessOn = 2.0f ;
    const float thicknessOff = 0.0f ;
   
    const sf::Vector2f rectSize(100, 30) ;

    Scenario scenarios[] =
    {
        // bg color, box_fill, box_outline, box_position, box_size, box_outline_thickness
        { bg, fill_alphaOn, outline_alphaOn, onTextPos, rectSize, thicknessOn, text },
        { bg, fill_alphaOn, outline_alphaOn, throughTextPos, rectSize, thicknessOn, text },
        { bg, fill_alphaOn, outline_alphaOn, offTextPos, rectSize, thicknessOn, text },

        { bg, fill_alphaOn, outline_alphaOn, offTextPos, rectSize, thicknessOff, text },
        { bg, fill_alphaOff, outline_alphaOn, offTextPos, rectSize, thicknessOn, text },
        { bg, fill_alphaOn, outline_alphaOff, offTextPos, rectSize, thicknessOn, text },

        // text shows correctly only for these two cases:
        { bg, fill_alphaOff, outline_alphaOn, offTextPos, rectSize, thicknessOff, text },
        { bg, fill_alphaOff, outline_alphaOff, offTextPos, rectSize, thicknessOn, text }
    };

    for ( unsigned i=0 ; i<sizeof(scenarios)/sizeof(scenarios[0]); ++i )
        doScenario(window, scenarios[i]) ;
}

bool processEvents( sf::RenderWindow & window )
{
    bool continueProcessing = true ;
    sf::Event event ;
    while ( window.pollEvent(event) )
    {
        switch (event.type)
        {
        case sf::Event::Closed:
            continueProcessing = false ;
            window.close() ;
            break ;

        case sf::Event::KeyReleased:
            continueProcessing = false ;
            break ;
        }
    }
    return continueProcessing ;
}

void doScenario( sf::RenderWindow& window, const Scenario& s )
{
    sf::RectangleShape rect ;

    rect.setPosition(s.box_position) ;
    rect.setSize(s.box_size) ;
    rect.setFillColor(s.box_fill) ;
    rect.setOutlineColor(s.box_outline) ;
    rect.setOutlineThickness(s.box_outline_thickness) ;

    const sf::Text & t = s.text ;

    while ( window.isOpen() && processEvents(window) )
    {
        window.clear(s.background);
        window.draw(rect) ;
        window.draw(t) ;
        window.display() ;
    }
}
 

Result:

Kylotan

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #16 on: November 01, 2012, 09:08:36 pm »
He asked because in the latest sources there's no more default font, and you said you used the latest sources ;)
Ok, I'd rebuilt against the new headers, but forgot to copy the new DLLs over. Now I've done that, as you would expect, the text doesn't render at all - but once I add in a font and load a TTF into it, I get the same problem as I did before.

I guess Cire has shown that it's not just my system though, for which I'm thankful!

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #17 on: November 01, 2012, 09:17:23 pm »
Try setting shapes texture to something not white(ie 512x512 magenta image) to see if it'll affect the white quads of text.
Back to C++ gamedev with SFML in May 2023

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #18 on: November 01, 2012, 09:44:33 pm »
The only thing that affects the color of the quads is the text color.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #19 on: November 01, 2012, 09:50:07 pm »
That's supposed to happen. Does drawing vertex array instead of shape break text? Do sprites draw ok after drawing shape? Seems like it 'forgets' to set the font texture.
Back to C++ gamedev with SFML in May 2023

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #20 on: November 01, 2012, 09:53:21 pm »
Actually, if you load a texture for rect, the text does display correctly.  I typo'd the texture's file name and didn't notice it.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #21 on: November 01, 2012, 10:01:04 pm »
Do sprites render ok after untextured shape? Does text render badly after untextured vertex array?
It seems like it can't distunguish between no texture and font texture. Also try: create few textures(sf::Texture dummy1; way, don't do anything with them) and then create shape, font instance and text and try that.
Back to C++ gamedev with SFML in May 2023

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #22 on: November 01, 2012, 10:22:35 pm »
Sprites do not render correctly after an untextured shape. (I get the shape of the sprite with the general color of the texture, unless the rectangle is not rendered due to alpha settings, in which case the sprite renders normally.)

Using a default constructed texture for the rectangle, there is no change rendering text from not using a texture at all.  For the sprite, nothing is rendered at all, even in the cases where the rectangle is not rendered due to alpha settings.

Just creating a texture (or textures) has no effect at all, as one would expect.

When drawing all 3, as long as the sprite is rendered after the text, it is always rendered correctly, and the same is true of the text, if the sprite is rendered prior to it.  The only thing that seems to be affected is what's rendered directly after an untextured (or default-textured) shape.
« Last Edit: November 01, 2012, 10:25:55 pm by cire »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #23 on: November 01, 2012, 10:43:13 pm »
It's late and my tired brain is unable to decode your last post. Could you please write a very small code that shows the simplest scenario that fails?

Thanks ;D
Laurent Gomila - SFML developer

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #24 on: November 01, 2012, 11:43:08 pm »
Sure.

#include <SFML/Graphics.hpp>

const sf::Vector2f box_size(100.0f, 30.0f) ;
const sf::Vector2f box_pos(10.0f, 100.0f) ;
const sf::Vector2f text_pos(10.0f, 10.0f) ;

sf::Text text ;

void waitForEnter( sf::RenderWindow& w)
{
    bool waiting = true ;
    while ( waiting )
    {
        sf::Event event ;
        if ( w.pollEvent(event) && event.type == sf::Event::KeyPressed )
            if ( event.key.code == sf::Keyboard::Return )
                waiting = false ;
    }
}

int main()
{
   sf::RenderWindow window(sf::VideoMode(150, 150), "Test");
   sf::RectangleShape box(box_size) ;
   box.setPosition(box_pos) ;

   box.setOutlineThickness(2.0f) ;  /* REQUIRED FOR RENDERING FAILURE */

   sf::Font font ;
   font.loadFromFile("sketchflow.ttf") ;
   text.setString("abcdefgh") ;
   text.setFont(font) ;

   // rendered correctly.
   window.clear() ;
   window.draw(box) ;
   window.draw(text) ;
   window.display() ;

   waitForEnter(window) ;

   // not rendered correctly.
   window.clear() ;
   window.draw(box) ;
   window.draw(text) ;
   window.display() ;

   waitForEnter(window) ;
}

If I run this as-is I see:


If I substitue a sprite for the sf::Text object, I see:


If I never set the outline thickness, everything would render correctly.
« Last Edit: November 01, 2012, 11:47:14 pm by cire »

thisdyingsoul

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #25 on: November 02, 2012, 04:20:21 am »
Well...
if you comment this:
//box.setOutlineThickness(2.0f) ;  /* REQUIRED FOR RENDERING FAILURE */
and change the first draw order:

// window.draw(box) ;
// window.draw(text) ;  
   window.draw(text) ;
   window.draw(box) ;

You get the error again.. in the second draw o.O.

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #26 on: November 02, 2012, 04:23:53 am »
The error was occuring in the second draw.  If you parse the images from left to right, the order matches that shown in the code.  Thus the "// not rendered correctly" comment in the code.

Although, I didn't try the reverse order without setting the thickness.

[edit:  Nope.  Everything renders correctly no matter which order is used if the thickness isn't set for me. ]
« Last Edit: November 02, 2012, 04:31:23 am by cire »

Kylotan

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #27 on: November 02, 2012, 04:28:57 pm »
Hey, I just want to say thanks to you all for the effort put in to examining this problem.

I can confirm that I see Cire's results with his test code. With the code as posted, I get the blocky text on the second rendering. If I comment out the setOutlineThickness call, the text is fine both times.

I can also confirm thisdyingsoul's results: if I comment out the setOutlineThickness call, AND swap the order of the first 2 draw calls, the second text rendering is broken.

However, if I swap both sets of draw calls (ie. so it's text before box, both times), leaving setOutlineThickness commented out - then the text is fine both times.

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #28 on: November 02, 2012, 05:28:55 pm »
Mm..  when I made the change to test, I didn't notice he specified only changing the first draw order and not the second.  If I only change the first draw order and comment out the thickness change, I do, indeed, also get the goofed up rendering.

Kylotan

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: sf::Shape rendering seems to break sf::Text rendering (2.0RC)
« Reply #29 on: November 06, 2012, 01:27:12 am »
Anybody got any idea what can be done about this? A workaround maybe?

 

anything