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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Dr Spaceman

Pages: [1]
1
Graphics / Re: Can't get vertex array to draw when I use a class
« on: June 22, 2013, 01:26:54 am »
Ah I see now, I tried calling every m_verticies as you did but it didn't work because I forgot to call it again.

Thanks for the help :)

2
Graphics / Re: Can't get vertex array to draw when I use a class
« on: June 21, 2013, 10:06:18 pm »
Ah I thought that might be the case.

I tried replacing the  m_vertices with triangles but it doesn't seem to work, I'm a bit of a newbie with this stuff don't suppose you could quickly amend my code so I can see how it should be done?


3
Graphics / Can't get vertex array to draw when I use a class
« on: June 21, 2013, 03:05:29 am »
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.

Pages: [1]