16
Graphics / Pointer to Rectangle
« on: December 20, 2010, 10:10:36 pm »Quote from: "Laurent"
If all you did is storing the shape in a variable, and get a lower framerate, you certainly did something wrong
Perhaps I did. Would you mind taking a look at my code and telling me what I could do to get my desired results? :]
Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;
int main()
{
// Create main window
sf::RenderWindow App(sf::VideoMode(640, 480), "SFML Graphics",
sf::Style::Fullscreen);
int pointCounter = 0;
int randX, randY, r, g, b;
sf::Clock pointTimer;
sf::Shape rect = sf::Shape::Rectangle(0, 0, 1, 1, sf::Color(0, 0, 0));
App.Clear();
pointTimer.Reset();
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
randX = sf::Randomizer::Random(0, 640);
randY = sf::Randomizer::Random(0, 480);
r = sf::Randomizer::Random(0, 255);
g = sf::Randomizer::Random(0, 255);
b = sf::Randomizer::Random(0, 255);
rect.SetPosition(randX, randY);
rect.SetColor(sf::Color(r, g, b));
App.Draw(rect);
pointCounter += 1;
if (pointTimer.GetElapsedTime() >= 10)
{
cout << "Points Drawn 10 Sec: " << pointCounter << endl;
return EXIT_SUCCESS;
}
// Finally, display the rendered frame on screen
App.Display();
}
return EXIT_SUCCESS;
}
Thank ya, sir. :]