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

Author Topic: Problem with VertexArray  (Read 2152 times)

0 Members and 1 Guest are viewing this topic.

ViktorKozlov

  • Newbie
  • *
  • Posts: 4
    • View Profile
Problem with VertexArray
« 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Problem with VertexArray
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ViktorKozlov

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Problem with VertexArray
« Reply #2 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with VertexArray
« Reply #3 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.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Problem with VertexArray
« Reply #4 on: November 24, 2016, 08:30:18 pm »
Works for me too.
Back to C++ gamedev with SFML in May 2023

ViktorKozlov

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Problem with VertexArray
« Reply #5 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?
« Last Edit: November 24, 2016, 09:48:01 pm by ViktorKozlov »

ViktorKozlov

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Problem with VertexArray
« Reply #6 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?