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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - edd

Pages: [1]
1
more info :

I don't understand why crash in first exemple. When i test sf::Font / sf::Text in simple game loop for reproduct my problem, all is fine with two load operation on same ttf file.

[...]
sf::Font font1, font2;

font1.loadFromFile("file.ttf")
font2.loadFromFile("file.ttf")

sf::Text text1, text2;

text1.setFont(font1);
text2.setFont(font2);

window.clear();
window.draw(text1);
window.draw(text2);
window.display();
 


2
Graphics / Re: Problem to draw 2 drawable on a renderWindow
« on: May 20, 2013, 02:15:49 pm »
ok, i found !

in SFML, i think you can't load two time a font file.

In a previous screen (screen menu) i load a font for display menu entries, and in game screen a load again same file for display test text in info box.

So i just implement a font collection class, for use sames font in all my project and perform uniq load for my fonts.

3
Graphics / Problem to draw 2 drawable on a renderWindow [Solved]
« on: May 20, 2013, 01:43:15 pm »
hello,

i have a little project with two class inherit drawable and transformable, and a screen class for event loop and draw instructions.

  • a class map implement a tilemap with vertex array.
  • a class info try to implement an information box.
  • a screen class contain event loop and draw call.

I want display a box on same screen than my map with some information updated when user click on map.

theses two class implement a virtual function draw like explain in tutorial


class Map : public sf::Transformable, public sf::Drawable
{
 
public:
  Map();
  void setFilename(std::string filename);
  void load(sf::Vector2u tileSize);
 
protected :
  void initVertex();
   
private :
  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
 
  sf::Vector2u tileSize;
  sf::VertexArray m_secondary_vertices;
  sf::VertexArray m_vertices;
  std::string filename;
};


void Map::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
  states.transform *= getTransform();
 
  states.texture = tilesetCollection.get("tiles"); // give tileset texture
 
  target.draw(m_vertices, states);
  target.draw(m_secondary_vertices, states); // for square need a second texture (like coast i.e)
}
 


class Info  : public sf::Transformable, public sf::Drawable
{
  public :
    Info();
    int init();
   
  private :
    virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
    sf::Text test;
};

int Info::init()
{
  sf::Font font;
 
  if ( !font.loadFromFile("../Resources/Dustismo.ttf"))
  {
     std::cout << "Error loading font" << std::endl;
     return -1;
  }
 
  test.setFont(font);
  test.setCharacterSize(30);
  test.setPosition(0,0);
  test.setString("hello");
  test.setColor(sf::Color::Red);
}

void Info::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
  states.transform *= getTransform();
  target.draw(test, states); // Crash on this instruction.
}
 

The screen class is build in this way :


int ScreenGame::Run(sf::RenderWindow &window)
{
  map.setFilename("../Maps/default.map");
  map.load(tilesize); // init all vertices
  info.init(); // init sf::Text object

  viewMap.setSize(800,600);
  viewMap.setCenter(400,300);

 bool Running = true;
 
  while ( Running )
  {
    sf::Event event;
    while (App.pollEvent(event))
    {
      [...]
    }
    window.setView(viewMap);
    window.clear(sf::Color::Black);
    window.draw(map);
    window.draw(info); // without this call, all work perfect.
    window.display();
  }
}
 

When a run this project with only map draw instruction, work well, my map is correctly draw on my screen. But when i add info draw instruction, project crash with return code 0.

Someone could help me ?

Pages: [1]