1
Graphics / 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.
Help needed :/
#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);
}}
}
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 :/