Ejemplo n.º 1
0
        static void Main()
        {
            //try
            {
                const int width  = 1024;
                const int height = 768;

                // Create main window
                m_Window = new RenderWindow(new VideoMode(width, height), "GWEN.Net SFML test", Styles.Titlebar | Styles.Close | Styles.Resize, new ContextSettings(32, 0));

                // Setup event handlers
                m_Window.Closed              += OnClosed;
                m_Window.KeyPressed          += OnKeyPressed;
                m_Window.Resized             += OnResized;
                m_Window.KeyReleased         += window_KeyReleased;
                m_Window.MouseButtonPressed  += window_MouseButtonPressed;
                m_Window.MouseButtonReleased += window_MouseButtonReleased;
                m_Window.MouseWheelMoved     += window_MouseWheelMoved;
                m_Window.MouseMoved          += window_MouseMoved;
                m_Window.TextEntered         += window_TextEntered;

                //m_Window.SetFramerateLimit(60);

                const int   fps_frames = 50;
                List <long> ftime      = new List <long>(fps_frames);
                long        lastTime   = 0;

                // create GWEN renderer
                Renderer.SFML gwenRenderer = new Renderer.SFML(m_Window);

                // Create GWEN skin
                //Skin.Simple skin = new Skin.Simple(GwenRenderer);
                Skin.TexturedBase skin = new Skin.TexturedBase(gwenRenderer, "DefaultSkin.png");

                // set default font
                Font defaultFont = new Font(gwenRenderer)
                {
                    Size = 10, FaceName = "Arial Unicode MS"
                };

                // try to load, fallback if failed
                if (gwenRenderer.LoadFont(defaultFont))
                {
                    gwenRenderer.FreeFont(defaultFont);
                }
                else // try another
                {
                    defaultFont.FaceName = "Arial";
                    if (gwenRenderer.LoadFont(defaultFont))
                    {
                        gwenRenderer.FreeFont(defaultFont);
                    }
                    else // try default
                    {
                        defaultFont.FaceName = "OpenSans.ttf";
                    }
                }

                skin.SetDefaultFont(defaultFont.FaceName);
                defaultFont.Dispose(); // skin has its own

                // Create a Canvas (it's root, on which all other GWEN controls are created)
                m_Canvas = new Canvas(skin);
                m_Canvas.SetSize(width, height);
                m_Canvas.ShouldDrawBackground = true;
                m_Canvas.BackgroundColor      = System.Drawing.Color.FromArgb(255, 150, 170, 170);
                m_Canvas.KeyboardInputEnabled = true;

                // create the unit test control
                m_UnitTest = new UnitTest.UnitTest(m_Canvas);

                // Create GWEN input processor
                m_Input = new Input.SFML();
                m_Input.Initialize(m_Canvas, m_Window);

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                while (m_Window.IsOpen())
                {
                    m_Window.SetActive();
                    m_Window.DispatchEvents();
                    m_Window.Clear();

                    // Clear depth buffer
                    Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT | Gl.GL_COLOR_BUFFER_BIT);

                    if (ftime.Count == fps_frames)
                    {
                        ftime.RemoveAt(0);
                    }

                    ftime.Add(stopwatch.ElapsedMilliseconds - lastTime);
                    lastTime = stopwatch.ElapsedMilliseconds;

                    if (stopwatch.ElapsedMilliseconds > 1000)
                    {
                        m_UnitTest.Fps = 1000f * ftime.Count / ftime.Sum();
                        stopwatch.Restart();
                    }

                    // render GWEN canvas
                    m_Canvas.RenderCanvas();

                    m_Window.Display();
                }

                // we only need to dispose the canvas, it will take care of disposing all its children
                m_Canvas.Dispose();

                // also dispose of these
                skin.Dispose();
                gwenRenderer.Dispose();
            }
            //catch (Exception e)
            //{
            //String msg = String.Format("Exception: {0}\n{1}", e.Message, e.StackTrace);
            //MessageBox.Show(msg);
            //}

            m_Window.Dispose();
        }
Ejemplo n.º 2
0
        static void Main()
        {
            //try
            {
                const int width = 1024;
                const int height = 768;

                // Create main window
                m_Window = new RenderWindow(new VideoMode(width, height), "GWEN.Net SFML test", Styles.Titlebar|Styles.Close|Styles.Resize, new ContextSettings(32, 0));

                // Setup event handlers
                m_Window.Closed += OnClosed;
                m_Window.KeyPressed += OnKeyPressed;
                m_Window.Resized += OnResized;
                m_Window.KeyReleased += window_KeyReleased;
                m_Window.MouseButtonPressed += window_MouseButtonPressed;
                m_Window.MouseButtonReleased += window_MouseButtonReleased;
                m_Window.MouseWheelMoved += window_MouseWheelMoved;
                m_Window.MouseMoved += window_MouseMoved;
                m_Window.TextEntered += window_TextEntered;

                //m_Window.SetFramerateLimit(60);

                const int fps_frames = 50;
                List<long> ftime = new List<long>(fps_frames);
                long lastTime = 0;

                // create GWEN renderer
                Renderer.SFML gwenRenderer = new Renderer.SFML(m_Window);

                // Create GWEN skin
                //Skin.Simple skin = new Skin.Simple(GwenRenderer);
                Skin.TexturedBase skin = new Skin.TexturedBase(gwenRenderer, "DefaultSkin.png");

                // set default font
                Font defaultFont = new Font(gwenRenderer) {Size = 10, FaceName = "Arial Unicode MS"};
                
                // try to load, fallback if failed
                if (gwenRenderer.LoadFont(defaultFont))
                {
                    gwenRenderer.FreeFont(defaultFont);
                }
                else // try another
                {
                    defaultFont.FaceName = "Arial";
                    if (gwenRenderer.LoadFont(defaultFont))
                    {
                        gwenRenderer.FreeFont(defaultFont);
                    }
                    else // try default
                    {
                        defaultFont.FaceName = "OpenSans.ttf";
                    }
                }

                skin.SetDefaultFont(defaultFont.FaceName);
                defaultFont.Dispose(); // skin has its own

                // Create a Canvas (it's root, on which all other GWEN controls are created)
                m_Canvas = new Canvas(skin);
                m_Canvas.SetSize(width, height);
                m_Canvas.ShouldDrawBackground = true;
                m_Canvas.BackgroundColor = System.Drawing.Color.FromArgb(255, 150, 170, 170);
                m_Canvas.KeyboardInputEnabled = true;

                // create the unit test control
                m_UnitTest = new UnitTest.UnitTest(m_Canvas);

                // Create GWEN input processor
                m_Input = new Input.SFML();
                m_Input.Initialize(m_Canvas, m_Window);

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                while (m_Window.IsOpen())
                {
                    m_Window.SetActive();
                    m_Window.DispatchEvents();
                    m_Window.Clear();

                    // Clear depth buffer
                    Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT | Gl.GL_COLOR_BUFFER_BIT);

                    if (ftime.Count == fps_frames)
                        ftime.RemoveAt(0);

                    ftime.Add(stopwatch.ElapsedMilliseconds - lastTime);
                    lastTime = stopwatch.ElapsedMilliseconds;

                    if (stopwatch.ElapsedMilliseconds > 1000)
                    {
                        m_UnitTest.Fps = 1000f * ftime.Count / ftime.Sum();
                        stopwatch.Restart();
                    }

                    // render GWEN canvas
                    m_Canvas.RenderCanvas();

                    m_Window.Display();
                }

                // we only need to dispose the canvas, it will take care of disposing all its children
                m_Canvas.Dispose();
                
                // also dispose of these
                skin.Dispose();
                gwenRenderer.Dispose();
            }
            //catch (Exception e)
            //{
                //String msg = String.Format("Exception: {0}\n{1}", e.Message, e.StackTrace);
                //MessageBox.Show(msg);
            //}

            m_Window.Dispose();
        }