SFML community forums

Help => Graphics => Topic started by: Wander on August 14, 2010, 11:13:35 am

Title: Won't Display Polygon
Post by: Wander on August 14, 2010, 11:13:35 am
I'm trying to draw a polygon here, but the points I put in won't display.


Code: [Select]
#include <iostream>
#include <SFML/Graphics.hpp>


using namespace std;

int main()
{
    sf::RenderWindow App(sf::VideoMode::GetMode(0), "Laz's Interactive Map :: The Wrath... :: PvP Created");

    // Creates the PE map :: 7000x3000
    sf::Shape Map;
    Map.AddPoint(0,100,sf::Color(100,100,200));
    Map.AddPoint(100,100,sf::Color(100,100,200));
    Map.EnableFill(true);
    Map.EnableOutline(false);
    //Map.Rotate(45);
    //Map.Move(0,354);

    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        float ElapsedTime = App.GetFrameTime();

        App.Clear();

        App.Draw(Map);

        App.Display();

    }



    return 0;
}
Title: Won't Display Polygon
Post by: Laurent on August 14, 2010, 11:30:27 am
Your "polygon" has two points, don't expect to see anything ;)
Title: Won't Display Polygon
Post by: Wander on August 15, 2010, 03:03:38 am
Oh okay, well if you can't make it display lines like that, how can I make it display points? Like single dots.
Title: Won't Display Polygon
Post by: Walker on August 15, 2010, 04:21:45 am
You'll have to make a rectangle or use sf::Shape::Line, I'm pretty sure that's a rectangle as well, just with a handy method for creating it.

If you want to draw individual pixels you may be better served by manipulating an image. Otherwise you'll just have to make really small polygons.
Title: Won't Display Polygon
Post by: Wander on August 15, 2010, 04:22:35 am
So there is not way to actually draw single points?
Title: Won't Display Polygon
Post by: Walker on August 15, 2010, 06:50:35 am
I'm not entirely sure what you mean by single points. You should be able to make an sf::Shape the size of one pixel. If not, or if that's not suitable, you can play with individual pixels on an sf::Image (through LoadFromMemory and an array) that you use like a buffer that you draw to before actually drawing it to your window (with a sprite).
Title: Won't Display Polygon
Post by: Wander on August 15, 2010, 06:52:47 am
Oh okay. Thank you very much.
Title: Won't Display Polygon
Post by: general sirhc on August 17, 2010, 04:01:10 pm
or a couple of if statements =)

if (points==1)
draw_rectangle of 1pixel
if (points==2)
draw a line
if (points>2)
draw polygon