I have small code to render Mandelbrot set. The actual set rendering, and image are correct (I saved it on HDD, and it displayed correct). My problem however is, that for some reason, when resizing window, the image behaves weirdly. Firstly if I do nothing with the scale (which should be automatic if I understand correctly), the image scales different rate than window (although a new image has been generated to match the new window size). If I do handle the scale, bottom part and left side of the set is cropped out as black (if I save the image, the bottom part is there). What am I doing wrong?
Main file, where pretty much everything happens:
int main()
{
int windowWidth = 1500, windowHeight = 800;
sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "Mandelbrot");
window.setFramerateLimit(60);
sf::Texture texture;
std::cout << "create MB \n";
sf::Image MB = createMBPicture(windowWidth, windowHeight);
texture.loadFromImage(MB, sf::IntRect());
sf::Sprite sprite;
sprite.setTexture(texture);
int i = 0;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::Resized){
windowWidth = event.size.width;
windowHeight = event.size.height;
std::cout << "W: " << windowWidth << "H: " << windowHeight << " \n";
MB = createMBPicture(windowWidth, windowHeight);
MB.saveToFile("E:\\Mandelbrot.jpg");
//Problem somewhere near here.
texture.loadFromImage(MB, sf::IntRect());
sprite.setTexture(texture);
sprite.setScale(1500.0f/(float)windowWidth, 800.0f/(float)windowHeight); //Scaling handling here
std::cout << "W: " << sprite.getScale().x << "H: " << sprite.getScale().y << " \n";
}
}
window.clear();
window.draw(sprite);
window.display();
}
return 0;
}