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

Author Topic: White sprite  (Read 5671 times)

0 Members and 1 Guest are viewing this topic.

maehze

  • Newbie
  • *
  • Posts: 4
    • View Profile
White sprite
« on: November 15, 2012, 09:47:40 pm »
Problem: When mCity->getEntities is > 1 or mWindow->draw() is called twice the background is just white.
What the code does: It renders a grid once into gridSprite. Then every time gridSprite is drawed, after that some circles are drawed on this.
Code:
void CityGridViewer::paintCity()
{  
    // 1. Render grid if necessary
    static bool targetReady=false;
    static sf::Texture gridTex;
    static sf::Sprite gridSprite;

    if (!targetReady)
    {
        sf::RectangleShape cell;
        cell.setSize(sf::Vector2f(5,5));
        cell.setOutlineColor(sf::Color::Black);
        cell.setOutlineThickness(1);
        City::GridCellType const*const grid = mCity->getCityGrid(); // it returns a copy of the grid
        for(unsigned int x=0; x < mCity->getGridSize().x; ++x)
            for(unsigned int y=0; y < mCity->getGridSize().y; ++y)
            {
                cell.setFillColor(sf::Color::Red);
                cell.setPosition(x*scale, y*scale);
                mWindow->draw(cell);
            }

        sf::Image gridImage = mWindow->capture();
        gridTex.loadFromImage(gridImage);
        gridSprite.setTexture(gridTex);
        targetReady=true;
    }
    mWindow->draw( gridSprite );

    // 2. Render entities
    sf::CircleShape entity;
    entity.setFillColor(sf::Color::Red);
    entity.setRadius( 5 );
    for (auto& e : mCity->getEntities())
    {
        entity.setPosition( e.position.x, e.position.y );
        mWindow->draw(entity);
    }
}

Does anyone has an idea?
Additionally, i'm using win7 x64 and compile with msvc11 x86. I tested it on a x64 linux with gcc4.7 x64 and it worked...
« Last Edit: November 15, 2012, 11:13:26 pm by maehze »

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: White sprite
« Reply #1 on: November 15, 2012, 10:03:07 pm »
Quote
 for(unsigned int y=0; y < mCity->getGridSize().y; ++y)
            {
                cell.setFillColor(sf::Color::Red); break;
                cell.setPosition(x*scale, y*scale);
                mWindow->draw(cell);
            }

Shouldn't that break be conditional?

Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

maehze

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: White sprite
« Reply #2 on: November 15, 2012, 11:14:07 pm »
Quote
 for(unsigned int y=0; y < mCity->getGridSize().y; ++y)
            {
                cell.setFillColor(sf::Color::Red); break;
                cell.setPosition(x*scale, y*scale);
                mWindow->draw(cell);
            }

Shouldn't that break be conditional?

Well... it should not be there ;-)
I cleaned up the code before i posted it here and forgot this litte "break".
Original code:

                switch(grid[x + mCity->getGridSize().x * y])
                {
                    case(City::GridCellType::Free): cell.setFillColor(sf::Color::White); break;
                    case(City::GridCellType::PublicPlace): cell.setFillColor(sf::Color::Green); break;
                    case(City::GridCellType::PoliceStation): cell.setFillColor(sf::Color::Blue); break;
                    case(City::GridCellType::Building): cell.setFillColor(sf::Color::Black); break;
                    default: cell.setFillColor(sf::Color::Red); break;
                }
« Last Edit: November 15, 2012, 11:20:03 pm by Laurent »

eigenbom

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: White sprite
« Reply #3 on: November 16, 2012, 12:34:07 am »
i think its because you need to call display() before capture(), BUT, you should use a rendertexture instead of capture() to do this sort of thing.

Quote
Image sf::RenderWindow::capture() const
Copy the current contents of the window to an image.

This is a slow operation, whose main purpose is to make screenshots of the application. If you want to update an image with the contents of the window and then use it for drawing, you should rather use a sf::Texture and its update(Window&) function. You can also draw things directly to a texture with the sf::RenderTexture class.

from http://www.sfml-dev.org/documentation/2.0/classsf_1_1RenderWindow.php#a9bd8655d0bac83145bfc329ea7a6d538

maehze

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: White sprite
« Reply #4 on: November 16, 2012, 07:52:13 pm »
[...], BUT, you should use a rendertexture instead of capture() to do this sort of thing. [...]
I use the current version of SFML (1.6). sf::RenderTexture::capture() does only exist in 2.0.
Calling "display()" before "capture()" did not help, but now the background is black instead of white.

I can see the right background for a very short moment on startup.

eigenbom

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: White sprite
« Reply #5 on: November 16, 2012, 11:22:08 pm »
hmm, well upgrading to 2.0 may be the first step towards resolving this :)

maehze

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: White sprite
« Reply #6 on: November 17, 2012, 08:55:15 pm »
hmm, well upgrading to 2.0 may be the first step towards resolving this :)

I want to use a stable version of SFML.

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: White sprite
« Reply #7 on: November 17, 2012, 08:56:05 pm »
SFML 2.0 RC is less buggy and more stable than 1.6.

eigenbom

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: White sprite
« Reply #8 on: November 17, 2012, 11:11:06 pm »
SFML 2.0 RC is less buggy and more stable than 1.6.

yeah and unfortunately this isn't posted on the front of the website, leading a lot of people to use 1.6.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: White sprite
« Reply #9 on: November 19, 2012, 10:24:55 am »
That's true, probably the version 2.0 RC should appear before 1.6 on the download page. Same for tutorials and documentation ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: White sprite
« Reply #10 on: November 19, 2012, 09:40:17 pm »
I started with 1.6 due to that, I guess this should be brought properly in the website forum.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: White sprite
« Reply #11 on: November 19, 2012, 10:43:09 pm »
I hope to be able to release SFML 2 and the new website soon enough. The current website is like SFML 1.6: still the latest official "release", but totally unmaintained ;D
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11028
    • View Profile
    • development blog
    • Email
Re: White sprite
« Reply #12 on: November 20, 2012, 12:58:28 am »
I hope to be able to release SFML 2 and the new website soon enough. The current website is like SFML 1.6: still the latest official "release", but totally unmaintained ;D
I'll believe it only when it actually has happened and even then I'll verify it at least one hundred times. ;D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: White sprite
« Reply #13 on: November 20, 2012, 01:25:46 am »
Laurent: So it's safe to assume 2.0 is safe, stable and efficient and should be used over 1.6?
Quote
I'll verify it at least one hundred times. ;D
In before release postponed for another 3 years..
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: White sprite
« Reply #14 on: November 20, 2012, 08:01:51 am »
Quote
Laurent: So it's safe to assume 2.0 is safe, stable and efficient and should be used over 1.6?
Sure!
Laurent Gomila - SFML developer