3
« on: October 13, 2020, 09:54:40 am »
Hi! So I'm a java developer, trying to slowly rip off the garbage collection training wheels by moving to some languages closer to C, so forgive me If I'm doing something incredibly stupid. I'm trying to write a fluid dynamics simulation (Google Mike Ash fluid dynamics, he wrote this crazy article detailing the process)
Long story short; I'm trying to draw the cells to the screen with their density being the alpha channel of the color like this:
sf::RenderWindow window(sf::VideoMode(N*SCALE, N*SCALE), "Fluid");
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) window.close();
}
step(fs);
window.clear(sf::Color::Black);
sf::RectangleShape square(sf::Vector2f(SCALE, SCALE));
square.setFillColor(sf::Color(125, 0, 255));
int x = 0;
int y = 0;
for (float d : fs.density) {
square.setPosition(x*SCALE,y*SCALE);
float alpha = d * 255;
square.setFillColor(sf::Color(125, 0, 255, alpha));
window.draw(square);
x++;
if (x % N == 0) {
x = 0;
y++;
}
}
window.display();
changing the color of the square for some reason results in that crash "exited with code -1073741571" that normally happens when the window gets destroyed in some ungraceful fashion. I should note that that array is 65536 (256^2) elements big, so I'm sure I should probably be doing something completely differently here, I'm just at a loss as to what.