Hello!
As the title suggests I want to know how does window display function actually work?
I mean I did read the guide but still I don't get it.
I know it's a form double buffering but still I don't get it.
I was playing with the window and basically I wanted to redraw not resize the rectangles I had drawn everytime I resize the window.And it works!
But the thing that inspired me to ask this question is after resizing I decided to flip the Window and to my suprise the previous drawing from the previous buffer is not present after flipping the window.
My question is why?
Here's the code
#include <SFML/Graphics.hpp>
#include <time.h>
#include <stdlib.h>
#include <iostream>
const float width=1024,height=768;
const float pi=3.1415926;
const int k=6;
int i=1;
int main()
{
sf::RenderWindow window(sf::VideoMode(width,height), "SFML works!");
const sf::Vector2f rectsize(25.f,100.f);
sf::RectangleShape rect[k];
window.clear();
for(int i=0;i<k;i++)
{
rect[i].setSize(rectsize);
switch(i)
{
case 0:
rect[i].setFillColor(sf::Color::Magenta);
break;
case 1:
rect[i].setFillColor(sf::Color::Cyan);
break;
case 2:
rect[i].setFillColor(sf::Color::Yellow);
break;
case 3:
rect[i].setFillColor(sf::Color::Red);
break;
case 4:
rect[i].setFillColor(sf::Color::Green);
break;
case 5:
rect[i].setFillColor(sf::Color::Blue);
break;
}
rect[i].setPosition(10+i*rectsize.x,10);
if(i>2)
{
rect[i].setPosition(10+((i-k/2)%k)*rectsize.x,10+rectsize.y);
}
window.draw(rect[i]);
}
window.display();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::Resized:
for(int i=0;i<k;i++)
{
rect[i].setSize(rectsize);
switch(i)
{
case 0:
rect[i].setFillColor(sf::Color::Magenta);
break;
case 1:
rect[i].setFillColor(sf::Color::Cyan);
break;
case 2:
rect[i].setFillColor(sf::Color::Yellow);
break;
case 3:
rect[i].setFillColor(sf::Color::Red);
break;
case 4:
rect[i].setFillColor(sf::Color::Green);
break;
case 5:
rect[i].setFillColor(sf::Color::Blue);
break;
}
rect[i].setPosition(10+i*rectsize.x,10);
if(i>2)
{
rect[i].setPosition(10+((i-k/2)%k)*rectsize.x,10+rectsize.y);
}
window.draw(rect[i]);
}
window.display();
break;
case sf::Event::KeyPressed:
if(event.key.code==sf::Keyboard::F) window.display();
break;
}
}
}
return 0;
}
I know it's a messy code and I'm sorry I tried to make it more tighty.But I am exploring the library and all of it's content and trying to figure out what most the things do on my own and try not ask questions.
Sadly in this case I can't find an answer.
Thank you for your time and answers!