SFML community forums

Help => Graphics => Topic started by: ViktorKozlov on November 24, 2016, 07:45:35 pm

Title: Problem with VertexArray
Post by: ViktorKozlov on November 24, 2016, 07:45:35 pm
Hello,

I want to draw rhombus with sf::VertexArray class

sf::VertexArray polygonImage2;
polygonImage2.clear();
polygonImage2.setPrimitiveType (sf::LinesStrip);
polygonImage2.resize (5);

float c = 1.0f;

polygonImage2[0] = {sf::Vector2f {62.5f * c, 55.0f * c}, sf::Color::Black};
polygonImage2[1] = {sf::Vector2f {70.0f * c, 62.5f * c}, sf::Color::Black};
polygonImage2[2] = {sf::Vector2f {62.5f * c, 70.0f * c}, sf::Color::Black};
polygonImage2[3] = {sf::Vector2f {55.0f * c, 62.5f * c}, sf::Color::Black};
polygonImage2[4] = {sf::Vector2f {62.5f * c, 55.0f * c}, sf::Color::Black};

theWindow.draw (polygonImage2);

but result shape is interrupted in the bottom. How can I solve this problem?
Title: Problem with VertexArray
Post by: eXpl0it3r on November 24, 2016, 07:58:17 pm
Why/how did you pick these coordinate values? Can't test right now, but you might have to use 0.5f for both x and y to center it on the specific pixel.
Title: Re: Problem with VertexArray
Post by: ViktorKozlov on November 24, 2016, 08:04:36 pm
This is simplified case which demonstrates the problem. I think that VertexArray with LineStrip mode must be continuous, because each next line begins from the last point of previous.
Title: Re: Problem with VertexArray
Post by: Laurent on November 24, 2016, 08:27:13 pm
Works for me. So either you're doing something else that you don't show, or your graphics driver behaves incorrectly.
Title: Re: Problem with VertexArray
Post by: FRex on November 24, 2016, 08:30:18 pm
Works for me too.
Title: Re: Problem with VertexArray
Post by: ViktorKozlov on November 24, 2016, 09:45:44 pm
Thanks for an answers.

This is a small program, where nothing is excess.

#include <windows.h>
#include "SFML/Graphics/RenderWindow.hpp"
#include "SFML/Graphics/VertexArray.hpp"

int WINAPI WinMain (HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR LpCmdLine, int nCmdShow)
{
        sf::RenderWindow myWindow;
        myWindow.create (sf::VideoMode (1024, 768), "DM", sf::Style::Titlebar | sf::Style::Close);

        while (myWindow.isOpen())
        {
                myWindow.clear(sf::Color::White);

                sf::VertexArray polygonImage2;
                polygonImage2.clear();
                polygonImage2.setPrimitiveType (sf::LinesStrip);
                polygonImage2.resize (5);

                float c = 1.0f;

                polygonImage2[0] = {sf::Vector2f {62.5f * c, 55.0f * c}, sf::Color::Black};
                polygonImage2[1] = {sf::Vector2f {70.0f * c, 62.5f * c}, sf::Color::Black};
                polygonImage2[2] = {sf::Vector2f {62.5f * c, 70.0f * c}, sf::Color::Black};
                polygonImage2[3] = {sf::Vector2f {55.0f * c, 62.5f * c}, sf::Color::Black};
                polygonImage2[4] = {sf::Vector2f {62.5f * c, 55.0f * c}, sf::Color::Black};

                myWindow.draw (polygonImage2);
                myWindow.display();
        }
        return 0;
}

And it still give me the same result with interrupt lines. I'm using 2.3.2 version of SFML. Is it problem with graphic driver? Is there any possible ways to resolve it?
Title: Re: Problem with VertexArray
Post by: ViktorKozlov on November 25, 2016, 11:06:24 pm
I tested it on other computer and result is correct. Apparently, the problem in the graphic driver. But even in correct image I see, that horizontal length of rhombus is 15 pixels, but vectical length is 16 pixels, although coordinates is symmetric in both sides (from 55.0 to 70.0). Is there a way to correct it?