Hey guys, I've recently started trying to get
my game (which is developed using C# and SFML.NET) to run on Macs. I've followed
this guide 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:
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:
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.