SFML community forums

Bindings - other languages => DotNet => Topic started by: SriK on July 08, 2016, 07:37:10 pm

Title: Odd behavior using backbuffer on OSX
Post by: SriK on July 08, 2016, 07:37:10 pm
Hey guys, I've recently started trying to get my game (https://twitter.com/steelassault) (which is developed using C# and SFML.NET) to run on Macs. I've followed this guide (http://en.sfml-dev.org/forums/index.php?topic=16397.0) and gotten it to the point where it compiles and displays things onscreen, but the game is a flickery glitchy mess, which sprites and tiles rapidly appearing and disappearing, etc.

After some investigation trying to create a minimal example, I found that this code (which doesn't use a backbuffer) renders perfectly:

Code: [Select]
using SFML.Graphics;
using SFML.Window;
using SFML.System;

namespace TestSFML {
class MainClass {
public static void Main(string[] args) {
// initialize window
RenderWindow window = new RenderWindow(new VideoMode(640, 480, 32), "SFML Test", Styles.Close);
window.SetVerticalSyncEnabled(true);
window.Clear(Color.Black);
window.Display();

double sqrX = 20, sqrY = 20;

// game loop
while (window.IsOpen) {
window.DispatchEvents();

sqrX += 0.5;
sqrY += 0.5;

window.Clear();
Color rectangleColor = new Color(255, 0, 0);
RectangleShape r = new RectangleShape {
Size = new Vector2f(200, 200),
Position = new Vector2f((float)sqrX, (float)sqrY),
FillColor = rectangleColor,
OutlineColor = rectangleColor,
OutlineThickness = 1
};
window.Draw(r);

window.Display();
}

window.Close();
}
}
}

...but this code (which uses a backbuffer RenderTexture) is unresponsive and glitchy:

Code: [Select]
using SFML.Graphics;
using SFML.Window;
using SFML.System;

namespace TestSFML {
class MainClass {
public static void Main(string[] args) {
// initialize window
RenderWindow window = new RenderWindow(new VideoMode(640, 480, 32), "SFML Test", Styles.Close);
window.SetVerticalSyncEnabled(true);
window.Clear(Color.Black);
window.Display();

// create backbuffer image and sprite
RenderTexture backbuffer = new RenderTexture(640, 480);
Sprite bufferSprite = new Sprite {
Texture = backbuffer.Texture,
TextureRect = new IntRect(0, 480, 640, -480)
};
backbuffer.Clear();

double sqrX = 20, sqrY = 20;

// game loop
while (window.IsOpen) {
window.DispatchEvents();

sqrX += 0.5;
sqrY += 0.5;

backbuffer.Clear();
Color rectangleColor = new Color(255, 0, 0);
RectangleShape r = new RectangleShape {
Size = new Vector2f(200, 200),
Position = new Vector2f((float)sqrX, (float)sqrY),
FillColor = rectangleColor,
OutlineColor = rectangleColor,
OutlineThickness = 1
};
backbuffer.Draw(r);

window.Draw(bufferSprite);
window.Display();
}

backbuffer.Dispose();
bufferSprite.Dispose();
window.Close();
}
}
}

(Both programs are just rendering a red square which moves down and to the right every frame, with VSync on.)

Does anyone know why this could be happening? I'm not getting this issue with the second example on Windows.

I'm using CSFML 2.3.0 and SFML 2.3.2, with SFML.Net 2.2 (so the latest versions of everything). In addition, this is running on a Mac Mini with an Intel HD Graphics 4000 graphics card.

Thanks for your time, guys!
Sri

EDIT: Just tried using SFML 2.3.0 instead (to match CSFML's version number), nothing changed.
Title: Re: Odd behavior using backbuffer on OSX
Post by: eXpl0it3r on July 09, 2016, 01:12:04 pm
You never call display on the render texture.
Title: Re: Odd behavior using backbuffer on OSX
Post by: SriK on July 12, 2016, 03:02:27 am
Thanks so much, that was it. I had no idea I had to do that first... I'm glad it was something this simple to fix.

What do you think was causing this code to work on Windows but not on Mac?
Title: Re: Odd behavior using backbuffer on OSX
Post by: eXpl0it3r on July 12, 2016, 03:09:53 am
Probably due to different drivers and maybe also due to different OpenGL versions used. In the end it doesn't really matter. ;)