I wrapped the Font object with the Using keyword, but it didn't seem to have any effect. I also tried wrapping the string2D in a Using keyword, but it didn't seem to do anything.
Update: I found a fix. After changing to fullscreen or the resolution, I need to re-load the Font and the String2D.public class ScreenManager
{
public RenderWindow appWindow;
bool isFullscreen;
Font serif;
String2D text;
// this function is called whenever the screen resolution or fullscreen state changes.
public void InitializeScreen(uint width, uint height)
{
//only close the renderwindow after its first initialization.
if (appWindow != null)
appWindow.Close();
Styles windowStyle = isFullscreen ? Styles.Fullscreen : Styles.Titlebar;
appWindow = new RenderWindow(new VideoMode(width, height, 32), "Window test", windowStyle);
appWindow.KeyPressed += new EventHandler<SFML.Window.KeyEventArgs>(OnKeyPressed);
//re-load the font. if we don't call this, then the letters become flat squares.
InitializeFont();
}
private void InitializeFont()
{
serif = new Font(@"accid.ttf", (uint)48);
text = new String2D("Press enter toggle fullscreen", serif, 64);
text.Position = new Vector2(10, 100);
text.Color = Color.Black;
}
public void Draw()
{
appWindow.Draw(text);
}
void OnKeyPressed(object sender, SFML.Window.KeyEventArgs e)
{
if (e.Code == KeyCode.Return)
{
//toggle fullscreen.
isFullscreen = !isFullscreen;
//re-create the window.
InitializeScreen(1024, 768);
}
if (e.Code == KeyCode.Escape)
{
appWindow.Close();
}
}
}