1
Graphics / sf::RenderTexture / sf::VertexArra: doesn't show vertices with zero y coordinate
« on: January 08, 2018, 08:28:25 pm »
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.
Here's the result:
But if I change this line
to
I get the expected result:
What am I doing wrong? Thanks in advance.
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);
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.