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

Author Topic: Drawing primitives break drawing sprite  (Read 1661 times)

0 Members and 1 Guest are viewing this topic.

castro12321

  • Newbie
  • *
  • Posts: 4
    • View Profile
Drawing primitives break drawing sprite
« on: December 07, 2012, 09:55:15 pm »
Hello,

When i press left mouse button, program draws a circle in left upper corner. After this sprite fills with only 1 colour forever. (see attached images - can't attach images)
Before: http://puu.sh/1yeve
After: http://puu.sh/1yew4

In the second scenario where I have box2 and/or box3, When i press left mouse button, sprite behaves same as in first but if I release mouse button, sprite draws it's texture properly again


Simplified code as much as I can
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\System.hpp>

#include <iostream>
#include <vector>

int main()
{
        std::vector<sf::Drawable*> drawables;

        sf::RenderWindow App(sf::VideoMode(800, 600), "cWar");

        // setup mouse
        sf::CircleShape mouse(5); // 5 is radius
        mouse.setFillColor(sf::Color::Cyan);

        // green rectangle
        sf::Vector2f shapeSize(500, 10); // Width, Height
        sf::RectangleShape *shape = new sf::RectangleShape(shapeSize);
        shape->setFillColor(sf::Color::Green);
        shape->setPosition(50, 500);
        drawables.push_back(shape); // IF WE COMMENT THIS, PROBLEM IS "SOLVED"

        // box
        sf::Texture tex1;
        tex1.loadFromFile("sprite.png");
        sf::Sprite* spr1 = new sf::Sprite(tex1);
        spr1->setPosition(50, 50);

        // box2
        sf::Texture tex2;
        tex2.loadFromFile("sprite2.png");
        sf::Sprite* spr2 = new sf::Sprite(tex2);
        spr2->setPosition(300, 50);

        // box3
        sf::Texture tex3;
        tex3.loadFromFile("sprite.png");
        sf::Sprite* spr3 = new sf::Sprite(tex1);
        spr3->setPosition(200, 200);

        drawables.push_back(spr1);
        //drawables.push_back(spr2); // if we uncomment these, first sprite gets back it's texture
        //drawables.push_back(spr3);

        // main loop
        sf::Event Event;
        bool isRunning = true;
        while(isRunning)
        {
                while (App.pollEvent(Event))
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                                isRunning = false;

                App.clear(sf::Color::White);
                for (size_t i = 0; i < drawables.size(); ++i)
                        App.draw((*drawables[i]));
                /*
                 * If we simplify loop to these 2 draw calls it is still same
                App.draw(*spr1);
                App.draw(*shape);
                */


                if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
                        App.draw(mouse); // this line breaks first sprite
                App.display();
        }


        return 0;
}
 

This problem only refers to first sprite. spr2 and spr3 don't lost it's texture
If i remove drawing circle or rectangle or both, problem seems to be fixed
When i tested program on my laptop, it worked fine.

Laptop: Win7 64bit, AMD Radeon HD6370M
Computer: Win7 64bit, AMD Radeon HD 7770
I used SFML downloaded today from Github (so the most recent version)
« Last Edit: December 07, 2012, 09:57:09 pm by castro12321 »

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile

castro12321

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Drawing primitives break drawing sprite
« Reply #2 on: December 08, 2012, 09:11:08 am »
Oh, my bad, sorry :(

 

anything