76
DotNet / Sprites become flat squares when renderWindow is re-created
« on: June 07, 2010, 10:13:07 pm »
Here's the code. It works fine in Windows, but shows artifacts in the Linux build.
Code: [Select]
using System;
using SFML;
using SFML.Window;
using SFML.Graphics;
namespace WindowTest
{
public class Game1
{
static void Main()
{
ScreenManager screenManager = new ScreenManager();
screenManager.InitializeScreen(640, 480);
Font serif = new Font(@"accid.ttf", (uint)48);
String2D text = new String2D("Press enter toggle fullscreen", serif, 64);
text.Position = new Vector2(10, 100);
text.Color = Color.Black;
while (screenManager.appWindow.IsOpened())
{
screenManager.appWindow.DispatchEvents();
screenManager.appWindow.Clear(Color.Cyan);
screenManager.appWindow.Draw(text);
screenManager.appWindow.Display();
}
}
public class ScreenManager
{
public RenderWindow appWindow;
bool isFullscreen;
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);
}
void OnKeyPressed(object sender, SFML.Window.KeyEventArgs e)
{
RenderWindow window = (RenderWindow)sender;
if (e.Code == KeyCode.Return)
{
//toggle fullscreen.
isFullscreen = !isFullscreen;
//re-create the window.
InitializeScreen(1024, 768);
}
if (e.Code == KeyCode.Escape)
{
appWindow.Close();
}
}
}
}
}