private static void Create() { OnGuiContextCreating(EventArgs.Empty); //Create the global GwenRenderer and Canvas _renderer = new Gwen.Renderer.SFML(WindowContext.Window); WindowContext.Window.KeyPressed += KeyPressed; WindowContext.Window.KeyReleased += KeyReleased; WindowContext.Window.MouseButtonPressed += MouseButtonPressed; WindowContext.Window.MouseButtonReleased += MouseButtonReleased; WindowContext.Window.MouseWheelMoved += MouseWheelMoved; WindowContext.Window.MouseMoved += MouseMoved; WindowContext.Window.TextEntered += TextEntered; Gwen.Font font = new Gwen.Font(_renderer, _gameConfiguration.SkinFont, 12); _renderer.LoadFont(font); _skin = new Gwen.Skin.TexturedBase(_renderer, _gameConfiguration.Skin); _skin.SetDefaultFont(font.FaceName); font.Dispose(); Canvas canvas = new Canvas(_skin); canvas.SetBounds(0, 0, _virtualResolution.Width, _virtualResolution.Height); canvas.ShouldDrawBackground = false; canvas.KeyboardInputEnabled = true; Canvas = canvas; _input = new Gwen.Input.SFML(); _input.Initialize(canvas, WindowContext.Window); OnGuiContextCreated(EventArgs.Empty); }
static void Main() { //try { // Create main window m_Window = new RenderWindow(new VideoMode((uint)width, (uint)height), "GalaxyConquest", Screen_Settings.fullScreen ? Styles.Fullscreen : (Styles.Close | Styles.Resize) | Styles.Titlebar, 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); // Create a sprite for the background Sprite background = new Sprite(new global::SFML.Graphics.Texture("background.jpg")); background.Texture.Repeated = true; // Disable lighting Gl.glDisable(Gl.GL_LIGHTING); // Configure the viewport (the same size as the window) Gl.glViewport(0, 0, (int)m_Window.Size.X, (int)m_Window.Size.Y); const int fps_frames = 50; List <long> ftime = new List <long>(fps_frames); long lastTime = 0; // create GWEN renderer Gwen.Renderer.SFML.GwenRenderer gwenRenderer = new Gwen.Renderer.SFML.GwenRenderer(m_Window); // Create GWEN skin //Skin.Simple skin = new Skin.Simple(GwenRenderer); Gwen.Skin.TexturedBase skin = new Gwen.Skin.TexturedBase(gwenRenderer, "DefaultSkin.png"); // set default font Gwen.Font defaultFont = new Gwen.Font(gwenRenderer) { Size = 10, FaceName = "OpenSans.ttf" }; // try to load, fallback if failed if (gwenRenderer.LoadFont(defaultFont)) { gwenRenderer.FreeFont(defaultFont); } 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; m_Canvas.ShouldDrawBackground = false; m_Canvas.DrawDebugOutlines = false; // Create GWEN input processor m_Input = new Gwen.Input.SFML.GwenInput(m_Window, m_Canvas); fontLogo = new Gwen.Font(gwenRenderer); fontLogo.FaceName = "OpenSans.ttf"; fontLogo.Size = 35; fontText = new Gwen.Font(gwenRenderer); fontText.FaceName = "OpenSans.ttf"; fontText.Size = 15; fontButtonLabels = new Gwen.Font(gwenRenderer); fontButtonLabels.FaceName = "OpenSans.ttf"; fontButtonLabels.Size = 25; /*Gwen.Control.StatusBar m_StatusBar; * m_StatusBar = new Gwen.Control.StatusBar(m_Canvas); * m_StatusBar.Dock = Gwen.Pos.Bottom; */ double Fps = 0.0; // fps to display screenManager = new ScreenManager(m_Canvas); screenManager.LoadScreen("mainmenu"); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (m_Window.IsOpen() && !quitFlag) { m_Window.SetActive(); m_Window.DispatchEvents(); m_Window.Clear(); m_Window.Draw(background); ///////////////////////// Gl.glClearColor(0f, 0f, 0f, 0f); Gl.glBegin(Gl.GL_QUADS); float x = 100.0f; float y = 100.0f; Gl.glVertex2f(x + 0f, y + 0f); Gl.glVertex2f(x + 0f, y + 1f); Gl.glVertex2f(x + 1f, y + 1f); Gl.glVertex2f(x + 1f, y + 0f); Gl.glEnd(); //m_Window.SwapBuffers(); if (ftime.Count == fps_frames) { ftime.RemoveAt(0); } ftime.Add(stopwatch.ElapsedMilliseconds - lastTime); lastTime = stopwatch.ElapsedMilliseconds; if (stopwatch.ElapsedMilliseconds > 1000) { Fps = 1000f * ftime.Count / ftime.Sum(); stopwatch.Restart(); } //m_StatusBar.Text = "GalaxyConquest v.0.1 - " + Math.Round(Fps, 2).ToString() + " fps"; // render GWEN canvas m_Canvas.RenderCanvas(); m_Window.Display(); } fontLogo.Dispose(); fontText.Dispose(); fontButtonLabels.Dispose(); // we only need to dispose the canvas, it will take care of disposing all its children // and current game screen 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(); }