I apologise in advance about the title, couldn't think of anything suitable.
Okay, so I'm not sure if this is a bug, or some error on my part, but considering the method, I'm pretty sure it's SFML.
So I have a vector of points, and I add all the points into a sf::Shape, then I set the properties such as colour, outline, etc.
Now, when I draw the polygon, I get some weird results;
Can you see where the outline doesn't match the sudden straight line of colour?
Now, the outline is definitely correct, but that random stretch of gray isn't.
Considering that the outline is draw with the polygon itself, it can't be an error on my part because I'm not manually drawing them seperately.
Unless I'm a total idiot and missing something, I'm not entirely sure what it is.
It is a tiny bit of a problem obviously, because it's plain as day in some generations.
Here's the code; (Please be warned that alot of it is debug code, it was me just messing around with some ideas and fractal generation)
#include <SFML\Graphics.hpp>
#include <time.h>
#include <Vector>
sf::VideoMode VMode(800, 600,32);
sf::RenderWindow Window(VMode, "ProcGen");
void Generate();
void Draw();
void Clear();
static const float w = float(Window.GetWidth());
static const float h = float(Window.GetHeight());
float Displacement;
float MidPoint;
int Split;
sf::Shape Polygon;
std::vector<sf::Vector2f> Points;
int main()
{
srand(time(0));
Clear();
Generate();
while (Window.IsOpened())
{
sf::Event Event;
while (Window.PollEvent(Event))
{
switch (Event.Type)
{
case sf::Event::Closed:
Window.Close();
break;
case sf::Event::KeyPressed:
Clear();
Generate();
break;
default:
break;
}
}
Window.Clear(sf::Color(0, 255, 255));
Draw();
Window.Display();
}
return 0;
}
void Generate()
{
std::vector<sf::Vector2f>::iterator It;
int j;
for (int i = 0; i < 7; i++)
{
Split = Split/2;
for(It = Points.begin(), j = 0; It != (Points.end() - 1); It++, j++)
{
sf::Vector2f Temp((Points[j].x+Points[j+1].x)/2,(Points[j].y+Points[j+1].y)/2);
Temp.y = Temp.y - (rand() % (Split*2) - Split);
Points.insert(It+1, Temp);
It = Points.begin();
for (int k = 0; k <= j; k++)
It++;
j++;
}
}
sf::Shape temp;
for (unsigned int i = 0; i < Points.size(); i++)
temp.AddPoint(Points[i]);
temp.SetColor(sf::Color(128,128,128));
temp.SetOutlineThickness(2.0f);
Polygon = temp;
}
void Draw()
{
//for (unsigned int i = 0; i < Points.size()-1; i++)
// Window.Draw(sf::Shape::Line(Points[i], Points[i+1], 2.0f, sf::Color::Black));
Window.Draw(Polygon);
}
void Clear()
{
Displacement = rand() % 200 + 300;
MidPoint = Displacement/2;
Split = MidPoint;
Points.clear();
Points.push_back(sf::Vector2f(0,h));
Points.push_back(sf::Vector2f(rand() % 400 + 200,h-Displacement));
Points.push_back(sf::Vector2f(w,h));
}