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 - Max Power

Pages: [1]
1
Graphics / Re: Strange behavior when I draw a chequered design
« on: April 24, 2014, 03:41:53 pm »
Thanks!
Now it work just fine!

2
Graphics / Re: Strange behavior when I draw a chequered design
« on: April 24, 2014, 02:02:01 pm »
So how can I resize the "video mode"?

3
Graphics / Re: Strange behavior when I draw a chequered design
« on: April 24, 2014, 01:17:02 pm »
No, I don´t. Should I handle it?
I got always the correct size of the window by the target argument given in the draw function so I thought I don´t have to handle it.

4
Graphics / Re: Strange behavior when I draw a chequered design
« on: April 24, 2014, 01:11:57 pm »
What do you do, when you resize your window?

I dragged the corner of the window. Nothing else.

5
Graphics / Re: Strange behavior when I draw a chequered design
« on: April 24, 2014, 12:02:18 pm »
I already solved the "wiggly" part. But when I resize the window there´s an another problem:
If I make it bigger, the board is "cutted". So you can´t see the whole board.
If I make it smaller, there´s a big border arround the board.

I use Code::Blocks 13.12 with MinGW and a self-compiled SFML library. May is this responsible for the problem?

6
Graphics / Re: Strange behavior when I draw a chequered design
« on: April 23, 2014, 09:31:46 pm »
Unfortenaly it isn´t.
Ironically my code works if I the window is given since the beiginning. Even if it´s not a square.
But as soon as I resize the window it looks as shown on the images.

But here´s a minimal and complete example that produces the problem:
#include <SFML/Graphics.hpp>

int main()
{
    sf::Color boxes[64];
    bool white = true;

    for (int n = 0; n < 64; n++)
    {
        white = (n % 8) == 0 ? white : !white;
        boxes[n] = white ? sf::Color::White : sf::Color::Black;
    }

    sf::RenderWindow window(sf::VideoMode(800, 600), "Chess");

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

        window.clear(sf::Color::Blue);

        //Relevant Code:
        sf::Vector2u wsize = window.getSize();

        int length = (wsize.x < wsize.y) ? (wsize.x - (wsize.x % 8)) / 8 : (wsize.y - (wsize.y % 8)) / 8;
        int offsetx = (wsize.x - (length * 8)) / 2;
        int posy = (wsize.y - (length * 8)) / 2;
        int posx = offsetx;

        int n = 0;
        while (n < 64)
        {
            sf::RectangleShape box(sf::Vector2f(length, length));
            box.setFillColor(boxes[n]);
            box.setPosition(posx, posy);
            window.draw(box);

            n++;

            if (n % 8 == 0)
            {
                posx = offsetx;
                posy += length;
            }
            else
            {
                posx += length;
            }

        }
        //Relevant Code End

        window.display();
    }
}
 

7
Graphics / Re: Strange behavior when I draw a chequered design
« on: April 23, 2014, 12:54:26 pm »
At first I had a for loop but the first square on the board is kind of special.
If I calculate the position first it didn´t worked. So i had to calculate it after the drawing the first square.
But also I had to increment n before I calculate the new position. I would to have use flags if I had used a for loop. So I think this while loop is a little bit convenient than a for loop with flags.

What do you mean with minimal and complete example?

So here´re some screenshots:
Big Window:


Tiny window:


EDIT:
I found the problem with the wiggly first row:
I forgot to add the offset to posx in each new row.

I updated the code in the first post.

8
Graphics / Strange behavior when I draw a chequered design
« on: April 22, 2014, 11:11:40 pm »
Hello,

At the moment I´m programming a chess game with sfml. But when I tried to draw a chessboard I got strange results. If the window was not a square the chessboard was wiggly.
I can´t figure out where I made the mistake and I´m searching for it for hours.
I hope you guys will find it.

And sorry for my bad english.

So heres my Code:

void Chessboard::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    sf::Vector2u wsize = target.getSize();

    //Size
    int length = (wsize.x < wsize.y) ? (wsize.x - (wsize.x % 8)) / 8 : (wsize.y - (wsize.y % 8)) / 8;

    //Offset
    int xoffset = (wsize.x - (length * 8)) / 2;
    int posx = xoffset;
    int posy = (wsize.y - (length * 8)) / 2;

    //Draw boxes
    int n = 0;
    while (n < 64)
    {

        sf::RectangleShape box(sf::Vector2f(length, length));
        box.setFillColor(boxes[n]); //sf::Color boxes[64]
        box.setPosition(posx, posy);

        //Draw box
        target.draw(box, states);

        n++;

        if (n % 8 == 0)
        {
            posx = xoffset;
            posy += length;
        }
        else
        {
            posx += length;
        }
    }
}
 

Pages: [1]
anything