Wow! Two posts in one day, that must be a record!
Today I've been learning a little about Vertex Arrays and in my testing I came across something I've noticed before, but narrowed it down to a minimal example so I can ask what it's all about (it has nothing to do with Vertex Arrays though).
Here's some code:
#include <SFML\Graphics.hpp>
#include "Random.h"
int main()
{
sf::RenderWindow App(sf::VideoMode(1024, 768, 32), "SFML");
App.EnableVerticalSync(true);
//App.SetFramerateLimit(60);
const unsigned int NOOF_DOTS = 128;
sf::VertexArray dots(sf::Quads, NOOF_DOTS * 4);
for (int i=0; i<NOOF_DOTS*4; i+=4)
{
Random gen;
float x = gen.randomF(0,1024);
float y = gen.randomF(0,768);
dots[i] .Position = sf::Vector2f( x, y );
dots[i+1].Position = sf::Vector2f( x, y+2 );
dots[i+2].Position = sf::Vector2f( x+2, y+2 );
dots[i+3].Position = sf::Vector2f( x+2, y );
}
while (App.IsOpen())
{
sf::Event Event;
while (App.PollEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();
App.Draw (dots);
App.Display();
}
return EXIT_SUCCESS;
}
NOTE 1: The 'Random' thing is just a little class I made to replace the old 1.6 Randomizer, it isn't really necessary.
NOTE 2: Running SFML2 from the Release .exe
NOTE 3: The snapshot I'm using is one just prior to the naming convention change.
The purpose of this test is simply to throw lots of tiny squares on the screen as a prelude to using this new aspect of SFML2 in a particle system I'm planning to re-create.
I noticed however (something I've seen before), some odd readings from the CPU.
With Vsync enabled and running 128 dots, CPU is low.
Change up by one to 129 dots and it leaps up to 25%.
Removing Vsync and using just frame limiting at 60, I can nearly white-out the screen with thousands of dots and the CPU appears to be yawning at 0%! Naturally, I'd prefer the VSync for smoothness, but I find this behaviour a little strange and it has confused me for some time now.
What exactly is it here that I'm not understanding correctly?
*Edit - changed title for future searches