I'm very sure this is a very simple answer but i'm still trying to get to grips with things.
What i'm trying to do is just make a class where I define a triangle and then I want to draw that class to the window. I have been following the tutorial and i'm currently as the bit where it shows the particle example, hence why some of the code is copy pasted.
When I run it I just get a black screen and i'm really not sure why.
#include <SFML/Graphics.hpp>
#include "Event.hpp"
#include "Transformable.hpp"
#include "Transform.hpp"
class test : public sf::Drawable , public sf::Transformable
{
public:
void triangles()
{
// create an array of 3 vertices that define a triangle primitive
sf::VertexArray triangle(sf::Triangles, 3);
// define the position of the triangle's points
triangle[0].position = sf::Vector2f(10, 10);
triangle[1].position = sf::Vector2f(100, 10);
triangle[2].position = sf::Vector2f(100, 100);
// define the color of the triangle's points
triangle[0].color = sf::Color::Red;
triangle[1].color = sf::Color::Blue;
triangle[2].color = sf::Color::Green;
}
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
// apply the entity's transform -- combine it with the one that was passed by the caller
states.transform *= getTransform(); // getTransform() is defined by sf::Transformable
// apply the texture
states.texture = NULL;
// you may also override states.shader or states.blendMode if you want
// draw the vertex array
target.draw(m_vertices, states);
}
sf::VertexArray m_vertices;
};
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "My window",sf::Style::Default);
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
test shape;
window.draw(shape);
window.display();
}
return 0;
}
I'm sure there is lots wrong with this but i'm still new so any help would be appreciated, thanks.