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

Author Topic: Something wrong with sfml::Text ?  (Read 1621 times)

0 Members and 2 Guests are viewing this topic.

larta

  • Newbie
  • *
  • Posts: 4
    • View Profile
Something wrong with sfml::Text ?
« on: July 05, 2013, 04:25:26 pm »
Hi all
I'm actually having a little (but really anoying) problem.

I have my own class to draw a sprite on sceen, instead of using the sf::Sprite. This works pretty fine.
I wanted to add some text on my screen, so i simply created a sfml::Text object then drew it, as i do with other drawables items.

This works, no problem. But i wanted to add something else :
Moving my scene. I working in a 2D scene (i mean, i don't use gluOrtho or whatever to draw in 2D, i just use the draw method of sf::RenderWindow)
So, to move the scene, i use glTranslatef(), wich works pretty fine, as far as i don't draw the text on the screen.
Well, it's a little bit hard to explain what's happening.

In one of my function, i first draw my sprite, then some text over it. Simply drawing the text after my own sprite makes glTranslatef do nothing.
And the most strange thing is that if i draw the text before my sprite, glTranslatef() works fine, and the world is moving (but the text is under my sprite so it doesn't appear)

What the hell ?

Here is the draw() function of my sprite class :
void                    FixedSprite::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
  if (_texture)
    {
        states.texture = _texture;
        states.transform *= getTransform();
        target.draw(_vertex, 4, sf::Quads, states);
    }
}
 
I have _texture wich is a pointer on a texture i load before.
_vertex is an array of 4 sf::Vertex

Do you have any idea why drawing the text after drawing the sprite make glTranslatef() do nothing ?
Or do you have a better way to move the whole scene, without having to go through all my objects and moving'em one by one ?

Thanks.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Something wrong with sfml::Text ?
« Reply #1 on: July 05, 2013, 04:43:50 pm »
Use an sf::View! :o
Take a look at the views tutorial. (and its doc)
« Last Edit: July 05, 2013, 04:49:59 pm by G. »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Something wrong with sfml::Text ?
« Reply #2 on: July 05, 2013, 04:54:18 pm »
Also read the OpenGL tutorial, it explains how to correctly mix SFML and OpenGL calls.
Laurent Gomila - SFML developer

 

anything