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

Author Topic: Background not displayed properly with multiple shapes  (Read 3546 times)

0 Members and 1 Guest are viewing this topic.

Nameless

  • Newbie
  • *
  • Posts: 3
    • View Profile
Background not displayed properly with multiple shapes
« on: December 23, 2012, 06:33:32 pm »
Hello everyone,

I'm new to the SFML lib, using it since two weeks or so. Very nice lib, fast and simple to understand and use.
Today I've found something weird when I try to display multiple shapes with a full background drawing.

Here is a simple piece of code to reproduce the issue:

static void Main(string[] args)
        {
            RenderWindow window = new RenderWindow(new VideoMode(512, 512), "SFML Background Test");
            window.KeyPressed += new EventHandler<SFML.Window.KeyEventArgs>(OnKeyPressed);
            window.Closed += new EventHandler(OnClose);
            window.Position = new Vector2i(0, 0);
            window.SetVerticalSyncEnabled(true);

            // Some circles
            Random tRand = new Random();
            CircleShape[] tCircles = new CircleShape[10];
            for (int i = 0; i < tCircles.Length; i++)
            {
                tCircles[i] = new CircleShape(20, 20);
                tCircles[i].FillColor = Color.Blue;
                tCircles[i].Position = new Vector2f(tRand.Next(0, (int)window.Size.X), tRand.Next(0, (int)window.Size.Y));
            }

            // Full Background buffer
            byte[] tBuffer = new byte[window.Size.X * window.Size.Y * 4];
            tRand.NextBytes(tBuffer);
            for (int i = 0; i < tBuffer.Length; i += 4)
                tBuffer[i + 3] = 255;
            Texture tTexture = new Texture(window.Size.X, window.Size.Y);
            Sprite tBackground = new Sprite(tTexture);

            while (window.IsOpen())
            {
                // Moving circles
                for (int i = 0; i < tCircles.Length; i++)
                    tCircles[i].Position = new Vector2f(tCircles[i].Position.X + (float)tRand.NextDouble() - 0.5f,
                                                        tCircles[i].Position.Y + (float)tRand.NextDouble() - 0.5f);

                // Changing background pixels
                for (int i = 0; i < tBuffer.Length; i += 4)
                {
                    tBuffer[i]++;
                    tBuffer[i + 1]++;
                    tBuffer[i + 2]++;
                }

                // Updating texture
                tTexture.Update(tBuffer);

                // Drawing
                window.DispatchEvents();
                window.Clear();
                window.Draw(tBackground);
                for (int i = 0; i < 1; i++) // <-- Drawing more than one == buggy background
                    window.Draw(tCircles[i]);
                window.Display();
            }
        }
 

In the previous code, if I try to display more than one circle, the background display is not correct, showing only a single color instead of a bunch of pixels.
I also noticed that if a outline is added to the circle, the background is always buggy, even with one circle only.

I'm using the latest 2.0 and know that it's still a work in progress. Should I switch to the previous released version?

Again, thank you for your amazing work!
« Last Edit: December 23, 2012, 07:42:00 pm by Nameless »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Background not displayed properly with multiple shapes
« Reply #1 on: December 23, 2012, 08:44:15 pm »
If you have an ATI graphics card, try the beta 12.11 drivers.
Laurent Gomila - SFML developer

Nameless

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Background not displayed properly with multiple shapes
« Reply #2 on: December 23, 2012, 10:47:03 pm »
Tried three times, no way to install the latest beta driver. Always got an error in the install log.
Guess I have to wait until the 12.11 final release...

By the way, is the use of a buffer and then Texture.Update the fastest way to fill the whole screen with custom pixels? It's still a bit slow on 1650x1080...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Background not displayed properly with multiple shapes
« Reply #3 on: December 23, 2012, 10:55:49 pm »
By the way, is the use of a buffer and then Texture.Update the fastest way to fill the whole screen with custom pixels? It's still a bit slow on 1650x1080...
Yes. SFML wasn't created for fast pixel manipulation...

If you only have to apply some stuff, you might want to use a shader to do the whole thing, which will give you the highest possible performance. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nameless

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Background not displayed properly with multiple shapes
« Reply #4 on: December 24, 2012, 12:03:24 am »
Thank you for your answer.
I've just took a look at the shader example and it looks amazing!
One more stuff to learn! ^^