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!