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

Author Topic: sf::RenderTexture / sf::VertexArra: doesn't show vertices with zero y coordinate  (Read 1243 times)

0 Members and 1 Guest are viewing this topic.

vkovalev

  • Newbie
  • *
  • Posts: 1
    • View Profile
Hi, I'm wondering if coordinates in `sf::VertexArray` are zero based or not?

Simple example: let's create a `sf::RenderTexture` and fill it with vertices in a way they represent two horizontal lines: one with `0` y coordinate, second with `textureHeight` y coordinate.

        // 100x100 render texture
        sf::RenderTexture renderTex;
        renderTex.create(100, 100);

        // 100 points. Each line has 50 points
        sf::VertexArray points(sf::PrimitiveType::Points, 100);

        // Draw first (top) horizontal line. Note 0 y coord
        int counter = 0;
        for (int i = 0; i < 100; i += 2)
        {
            sf::Vertex v;
            v.color = sf::Color::White;
            v.position.x = i;
            v.position.y = 0;
            points[counter++] = v;
        }

        // Draw second (bottom) horizontal line.
        for (int i = 0; i < 100; i += 2)
        {
            sf::Vertex v;
            v.color = sf::Color::Red;
            v.position.x = i;
            v.position.y = 99;
            points[counter++] = v;
        }

        renderTex.clear();
        renderTex.draw(points);
        renderTex.display();

        auto tex = renderTex.getTexture();

        ...

        sf::RectangleShape rect;
        rect.setSize({ 200, 200 });
        rect.setPosition(10, 10);
        rect.setTexture(&tex);
        m_mainWindow.draw(rect);
 

Here's the result:


But if I change this line

v.position.y = 0;
 

to

v.position.y = 1;
 

I get the expected result:



What am I doing wrong? Thanks in advance.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
There are multiple threads on this topic in the forum, for example this one. :)

Try to do a full search on the forum if you need more info (click on search in the menu first, otherwise you'll just search this thread).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything