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

Author Topic: Trying to draw outside of main  (Read 1374 times)

0 Members and 1 Guest are viewing this topic.

kiko298

  • Newbie
  • *
  • Posts: 1
    • View Profile
Trying to draw outside of main
« on: October 03, 2016, 02:10:04 pm »
I really cant understand why my code doesnt work! Why function Teste doesnt show anything.
#include <SFML/Graphics.hpp>
void teste(sf::RenderWindow &thatwindow);
void DesenhaMapa(sf::RenderWindow &window);



int main()
{
    sf::RenderWindow window(sf::VideoMode(600, 700), "SFML works!");
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        teste(window);
        //DesenhaMapa(window);
        window.clear();
        window.display();
    }

    return 0;
}

void teste(sf::RenderWindow &thatwindow)
{
        sf::CircleShape shape(100.f);
        shape.setPosition(10, 10);
    shape.setFillColor(sf::Color::Green);
    thatwindow.draw(shape);
}

void DesenhaMapa(sf::RenderWindow &window)
{
    for(int largura = 0;largura<30;largura++){
        for(int altura = 0;altura<30;altura++){
        sf::RectangleShape retangulo;
        retangulo.setFillColor(sf::Color::Blue);
        retangulo.setSize(sf::Vector2f(10, 10));
        retangulo.setOutlineColor(sf::Color::Red);
        retangulo.setOutlineThickness(5);
        retangulo.setPosition(sf::Vector2f(largura, altura));
        window.draw(retangulo);
        }}

}
 

Help needed :/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Trying to draw outside of main
« Reply #1 on: October 03, 2016, 02:15:58 pm »
        teste(window);
        window.clear();
        window.display();

What do you expect to happen when you do: draw shape, clear the whole window with one color, display? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything