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

Author Topic: [SOLVED] Black lines on vertex array  (Read 1682 times)

0 Members and 1 Guest are viewing this topic.

FoundSomething

  • Newbie
  • *
  • Posts: 2
    • View Profile
[SOLVED] Black lines on vertex array
« on: June 30, 2017, 08:43:51 pm »
Currently, I'm trying to generate white noise using a vertex array of points to display the pixels. The size of the output is 200 by 200 pixels. However, when I run the code, black vertical lines appear in the noise. When I resize the window, it fixes the problem, but I don't understand why, as I presume my sizes for the vertex array and window are correct.

Here is the code that I'm running:
#include <SFML/Graphics.hpp>
#include <time.h>

using namespace sf;

int main(int argc, char** argv) {
    srand(time(NULL));
    RenderWindow window(VideoMode(200, 200), "");
    VertexArray noise(Points, 200 * 200);
    int value = 0;
       
    for (int i = 0; i < 200 * 200; i++) {
        noise[i].position = Vector2f(i % 200, i / 200);
        value = rand() % 256;
        noise[i].color = Color(value, value, value);
    }
       
    while (window.isOpen()) {
        Event event;
        while (window.pollEvent(event)) {
            if (event.type == Event::Closed)
                window.close();
        }
       
        window.draw(noise);
        window.display();
    }
    return 0;
}

All the values regarding the size of the window are set to 200, though I still get some empty space.
« Last Edit: July 01, 2017, 05:42:09 pm by FoundSomething »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Black lines on vertex array
« Reply #1 on: July 01, 2017, 03:03:52 pm »
I run your code as-is and got the result you are probably hoping for/expecting:


I tried resizing the window and it can cause the lines you seem to be describing.
Have your tried adding a half to each vertex's position member? A point, in theory, should be in the middle of a pixel otherwise it's on the corner of four pixels and could choose any of those.
noise[i].position = Vector2f((i % 200) + 0.5f, (i / 200) + 0.5f)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

FoundSomething

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Black lines on vertex array
« Reply #2 on: July 01, 2017, 05:41:47 pm »
Yes, your solution works. Thank you.