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

Author Topic: SFML 2.0 Drawing random colored shape  (Read 10514 times)

0 Members and 1 Guest are viewing this topic.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: SFML 2.0 Drawing random colored shape
« Reply #15 on: October 11, 2013, 01:31:44 am »
Works fine here, you must be doing something wrong or something you didn't tell us. Also make sure you graphics card driver is up to date! :)

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    const sf::Color colorArray[5]={sf::Color::Cyan, sf::Color::Blue, sf::Color::Green, sf::Color::Red, sf::Color::Yellow };
    srand(time(NULL));
    sf::RenderWindow window(sf::VideoMode(200, 200), "Blocks");
    sf::RectangleShape block(sf::Vector2f(16, 16));
    std::cout << rand()%5;
    block.setFillColor(colorArray[rand()%5]);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

       window.clear();
       block.setPosition(0, 0);
       window.draw(block);
       window.display();
    }
}
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Vladislav

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: SFML 2.0 Drawing random colored shape
« Reply #16 on: October 12, 2013, 03:17:56 pm »
No, it doesn't work:( And i have latest version of videodriver (Intel HD 3000).

Vladislav

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: SFML 2.0 Drawing random colored shape
« Reply #17 on: October 12, 2013, 04:27:58 pm »
I just removed system("pause"), and it works fine.
« Last Edit: October 12, 2013, 05:03:19 pm by Vladislav »

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: SFML 2.0 Drawing random colored shape
« Reply #18 on: October 12, 2013, 07:16:37 pm »
what?! didn't you tried the code i posted? it already had that removed.
i suggest not to use system("anything"). in last case, set a simple breakpoint through the debugger.
these commands are a bad habit, often cause bugs, kills the portability of your code, among other things...
Visit my game site (and hopefully help funding it? )
Website | IndieDB