OK here's what I've got. It's using SFML.Net but I think it gets the point across.
Spike source code:
https://github.com/nathanchere/Spikes_SfmlRenderTextureCompiled version if you just want to see the shiny:
https://dl.dropboxusercontent.com/u/14432582/sfmlRenderTextureSpike.7zMain code for the really lazy:
private void RenderWorking
() { window
.Clear(Color
.Black); textureOne
.Clear(Color
.White); textureOne
.Display(); var renderSprite
= new Sprite
(textureOne
.Texture); // Note #2 // renderSprite.Position = new Vector2f(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y); renderSprite
.Draw(window, RenderStates
.Default); // Note #1 // window.Display(); } private void RenderBuggy
() { shapeTwo
.Position = new Vector2f
(Mouse
.GetPosition(window
).X, Mouse
.GetPosition(window
).Y); textureTwo
.Clear(); textureTwo
.Draw(shapeTwo
); textureTwo
.Display(); window
.Clear(); var renderSprite
= new Sprite
(textureTwo
.Texture); window
.Draw(renderSprite
); } private void RenderMoreBuggy
() { textureThree
.Clear(new Color
( (byte) (DateTime
.Now.Millisecond%128
),
(byte) (DateTime
.Now.Millisecond%64
),
(byte) (DateTime
.Now.Millisecond%255
) )); textureThree
.Display(); shapeThree
.Position = new Vector2f
(Mouse
.GetPosition(window
).X, Mouse
.GetPosition(window
).Y); shapeThree
.Rotation = 0
.36f
*DateTime
.Now.Millisecond; textureThree
.Draw(shapeThree
); window
.Clear(); var renderSprite
= new Sprite
(textureThree
.Texture); window
.Draw(renderSprite
); } So basically RenderWorking is doing the white-square-in-corner thing, RenderBuggy is the red-square-following-mouse thing, and RenderMoreBuggy is intended to display the issue better.
Use: press 1 2 and 3 to toggle render mode, Space to toggle displaying text over the top.
Huh? What's the point of the text? Read on...
Observations:
- the white square test works fine, although it's a bad test. Gives a false positive that it's working OK because nothing is changing or moving
- Uncomment the window.Display() call at Note #1 and you reproduce the flickering someone mentioned earlier in the thread - make sure you're not calling Display on the main render target multiple times in a row?
- the red square demo replicates the expected buggy result. Main difference with this and the white square demo is that the whole drawing area is a RenderTexture, not just the white square, and there is movement
- The third demo tries to better highlight how RenderTexture regions which aren't being drawn over do not get updated, even when you use Clear()
The interesting part for me is the main loop:
while (window.IsOpen())
{
window.DispatchEvents();
Render();
if(DisplayText) window.Draw(Text); // Note #3
window.Display();
}
Render() calls whichever one of the three afore described functions is currently selected. Behaviour is as already described. When drawing text is enabled, suddenly the buggy drawing goes away.
Example:
I'm now more inclined to believe yes it really is a bug and not just people "doing it wrong".
{edit} disregard; issue identified will be fixed in SFML 2.2.