Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sprites become flat squares when renderWindow is re-created  (Read 5440 times)

0 Members and 1 Guest are viewing this topic.

Brendon

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
    • http://blendogames.com
I'm using SFML with Mono. I have the PC build working fine, and now I'm porting it over to Linux.  I'm really loving SFML's ease of use - I'm definitely looking toward to continuing using it for future projects.

I noticed a quirk in the Linux build.  I'm not sure if it's SFML or Mono or something else, but I'd like to float it here to see if anyone has seen this before.

Here is how the screen initially looks:


After I change resolution or switch to fullscreen, this happens:


It seems to be triggered whenever I re-create the RenderWindow:
Code: [Select]
this.app.Close();

this.app = new RenderWindow(new VideoMode(optionsData.VideoWidth, (uint)optionsData.VideoHeight, 32), Resource.MenuTitle, windowStyle);


I'm using SFML v1.6 for everything except the graphics component (v1.5 for the graphics).  I'm running on 64-bit Windows7, with Ubuntu 10.04 on VirtualBox.

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
Sprites become flat squares when renderWindow is re-created
« Reply #1 on: June 07, 2010, 09:37:32 am »
I highly suggest grabbing the latest version of 2.0 from the SVN repo. 2.0 is far more stable (in my opinion), and the latest version supports .NET very well.

If its still an issue in 2.0, I'll check it out more thoroughly.

Brendon

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
    • http://blendogames.com
Sprites become flat squares when renderWindow is re-created
« Reply #2 on: June 07, 2010, 07:30:06 pm »
I was under the impression there currently isn't a Mac osx build for SFML2. If so, I'd prefer to stick with 1.x, solely for the Mac osx support.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprites become flat squares when renderWindow is re-created
« Reply #3 on: June 07, 2010, 08:37:42 pm »
It is supposed to work, even in SFML 1.6 (which is far more stable than the current SFML 2.0).

Can you provide a complete and minimal example that reproduces this problem,n so that I can test it quickly on my computer?
Laurent Gomila - SFML developer

Brendon

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
    • http://blendogames.com
Sprites become flat squares when renderWindow is re-created
« Reply #4 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();
                }
            }
        }
    }
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprites become flat squares when renderWindow is re-created
« Reply #5 on: June 07, 2010, 11:05:13 pm »
It looks ok.

Is there a way to check if your Font object is collected by the GC before the end of the program? Can you try with the "using" keyword to control the lifetime of the Font object?
Laurent Gomila - SFML developer

Brendon

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
    • http://blendogames.com
Sprites become flat squares when renderWindow is re-created
« Reply #6 on: June 08, 2010, 05:58:06 pm »
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.
Code: [Select]
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();
                }
            }
        }