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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - kaiserMKII

Pages: [1]
1
Well I said I was studying the library so I didn't want to lose time deleting the all the rectangles(Yes I know it's not hard sue me :D)I thought I would just go with what I made previously :D and get on with it :D.Yes I know it's a messy code(I did say it at the beginning) because I'm challenging myself everytime I complete a task and use what I made from that task for my next challenge and on and on :D.
Still thank you for your honesty you made me laugh with that :D.
I will take your advice.

2
But you're the admin and why won't you help?At least tell so I can can be at peace  and figure it on my own :D

3
Try this simpler code to see double buffering in action:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML double buffer");

    window.clear(sf::Color::Green);
    window.display();
    window.clear(sf::Color::Red);
    window.display();

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
            if (event.type == sf::Event::KeyPressed)
                window.display();
    }

    return 0;
}

And, while it's always a good thing to understand what's behind the scenes, keep in mind that it is an implementation detail that may not be used on all platforms.

Yes this is the result I was and still am trying to achieve.
but what is the difference between mine and yours?
I mean shouldn't mine worked the same way as yours?
If not then where's my mistake?
Thanks!

4
Quote
to my suprise the previous drawing from the previous buffer is not present after flipping the window
What do you expect to see, and what are you seeing instead?

And you should really use consistent indentation, your code is so hard to read.

Well it's a double buffer correct?So what ever I'm drawing it is drawn at the back buffer and when I call display it switches the back buffer with the front buffer.So after resizing the window I get resized drawing and whatever was left is now at the back waiting to be cleared and re-drawn.

Instead I only see the resized drawing and a blank buffer when I press F.

And my question is why does that happen?

Quote
So if you already knew that - why don't you do that? You call display only on getting resize event

Curiosity and studying how the library works.

5
Thank you for the advice.I guess?
But I already knew that and I'm currently studying this library.
And how does that answer my question?

6
Window / Why doesn't the window display function work the way I intended?
« on: November 25, 2017, 02:30:46 pm »
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!

Pages: [1]
anything