コード例 #1
0
        // This gets called on each frame render
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            if (m_Ftime.Count == FpsFrames)
            {
                m_Ftime.RemoveAt(0);
            }

            m_Ftime.Add(m_Stopwatch.ElapsedMilliseconds - m_LastTime);
            m_LastTime = m_Stopwatch.ElapsedMilliseconds;

            if (m_Stopwatch.ElapsedMilliseconds > 1000)
            {
                m_UnitTest.Note = String.Format("String Cache size: {0} Draw Calls: {1} Vertex Count: {2}", m_Renderer.TextCacheSize, m_Renderer.DrawCallCount, m_Renderer.VertexCount);
                m_UnitTest.Fps  = 1000f * m_Ftime.Count / m_Ftime.Sum();

                m_Stopwatch.Restart();

                if (m_Renderer.TextCacheSize > 1000)                 // each cached string is an allocated texture, flush the cache once in a while in your real project
                {
                    m_Renderer.FlushTextCache();
                }
            }

            GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);

            m_Canvas.RenderCanvas();

            SwapBuffers();
        }
コード例 #2
0
        /// <summary>
        /// Add your game rendering code here.
        /// </summary>
        /// <param name="e">Contains timing information.</param>
        /// <remarks>There is no need to call the base implementation.</remarks>
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);
            canvas.RenderCanvas();

            SwapBuffers();
        }
コード例 #3
0
ファイル: Sample.cs プロジェクト: xXSFORTUNEXx/GWEN.Net-Unity
 void OnGUI()
 {
     //GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), guiTex);
     //GUI.DrawTextureWithTexCoords(new Rect(0, 0, 400, 400), skinTex, new Rect(0, 1f - (126f/512f), .2f,126f/512f));
     if (m_Canvas.Width != Screen.width || m_Canvas.Height != Screen.height)
     {
         m_Canvas.SetSize(Screen.width, Screen.height);
     }
     if (m_UnitTest == null)
     {
         //win.Title = "This is a window!";
         // create the unit test control
         m_UnitTest = new UnitTest(m_Canvas);
     }
     if (Event.current.mousePosition.x != mousex || Event.current.mousePosition.y != mousey)
     {
         mousex = Event.current.mousePosition.x;
         mousey = Event.current.mousePosition.y;
         Event tmpevent = new Event();
         tmpevent.type          = EventType.MouseMove;
         tmpevent.mousePosition = Event.current.mousePosition;
         m_Input.ProcessMessage(tmpevent);
     }
     if (Event.current.type == EventType.Repaint)
     {
         m_Canvas.RenderCanvas();
     }
     else if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.ScrollWheel || Event.current.type == EventType.MouseUp || Event.current.type == EventType.KeyDown || Event.current.type == EventType.KeyUp)
     {
         m_Input.ProcessMessage(Event.current);
     }
 }
コード例 #4
0
        void IGLKViewDelegate.DrawInRect(GLKView view, CoreGraphics.CGRect rect)
        {
            if (m_Ftime.Count == FpsFrames)
            {
                m_Ftime.RemoveAt(0);
            }

            m_Ftime.Add(m_Stopwatch.ElapsedMilliseconds - m_LastTime);
            m_LastTime = m_Stopwatch.ElapsedMilliseconds;

            if (m_Stopwatch.ElapsedMilliseconds > 1000)
            {
                m_UnitTest.Note = String.Format("String Cache size: {0} Draw Calls: {1} Vertex Count: {2}", m_Renderer.TextCacheSize, m_Renderer.DrawCallCount, m_Renderer.VertexCount);
                m_UnitTest.Fps  = 1000f * m_Ftime.Count / m_Ftime.Sum();

                m_Stopwatch.Restart();

                if (m_Renderer.TextCacheSize > 1000)                 // each cached string is an allocated texture, flush the cache once in a while in your real project
                {
                    m_Renderer.FlushTextCache();
                }
            }

            GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);

            m_Canvas.RenderCanvas();
        }
コード例 #5
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.MidnightBlue);

            canvas.RenderCanvas();

            base.Draw(gameTime);
        }
コード例 #6
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();

            canvas.RenderCanvas();

            spriteBatch.End();


            base.Draw(gameTime);
        }
コード例 #7
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            if (m_Ftime.Count == FpsFrames)
            {
                m_Ftime.Dequeue();
            }

            m_Ftime.Enqueue(gameTime.ElapsedGameTime.Milliseconds);

            GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.MidnightBlue);

            m_Canvas.RenderCanvas();

            base.Draw(gameTime);
        }
コード例 #8
0
        /// <summary>
        /// Add your game rendering code here.
        /// </summary>
        /// <param name="e">Contains timing information.</param>
        /// <remarks>There is no need to call the base implementation.</remarks>
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);
            m_Stopwatch.Start();
            m_Canvas.RenderCanvas();
            m_Stopwatch.Stop();
            int tts = (int)(1000 / 30 - m_Stopwatch.ElapsedMilliseconds); //30 - требуемое кол-во fps

            if (tts > 0)
            {
                Thread.Sleep(tts);
            }
            m_Stopwatch.Restart();
            SwapBuffers();
        }
コード例 #9
0
        private void glControl_Paint(object sender, PaintEventArgs e)
        {
            ResetViewport();
            Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT | Gl.GL_COLOR_BUFFER_BIT);
            m_canvas.RenderCanvas();

            m_renderContext.CurrentMousePos       = m_mouseLocTransformed;
            m_renderContext.CurrentOrthoTransform = m_cameraTransform;

            m_renderer.Begin();

            PreSceneRender();

            if (m_scene != null)
            {
                m_scene.Render(m_renderContext, m_renderDevice);
            }

            PostSceneRender();

            m_renderer.End();
        }
コード例 #10
0
ファイル: ExampleBase.cs プロジェクト: ming4883/gwen-dotnet
    public void Init(GameWindow gamewindow)
    {
        renderer = new Gwen.Renderer.OpenTK();
        skin = new Gwen.Skin.TexturedBase (renderer, "DefaultSkin.png");
        canvas = new Gwen.Control.Canvas (skin);
        canvas.SetSize (gamewindow.Width, gamewindow.Height);
        canvas.ShouldDrawBackground = true;
        canvas.BackgroundColor = System.Drawing.Color.FromArgb (255, 225, 225, 225);

        input = new Gwen.Input.OpenTK (gamewindow);
        input.Initialize (canvas);

        gamewindow.Keyboard.KeyDown += (s, e) =>
        {
            input.ProcessKeyDown (e);
        };
        gamewindow.Keyboard.KeyUp += (s, e) =>
        {
            input.ProcessKeyUp (e);
        };

        gamewindow.Mouse.ButtonDown += (s, e) =>
        {
            input.ProcessMouseMessage (e);
        };
        gamewindow.Mouse.ButtonUp += (s, e) =>
        {
            input.ProcessMouseMessage (e);
        };
        gamewindow.Mouse.Move += (s, e) =>
        {
            input.ProcessMouseMessage (e);
        };
        gamewindow.Mouse.WheelChanged += (s, e) =>
        {
            input.ProcessMouseMessage (e);
        };

        gamewindow.Load += (s, e) =>
        {
            PreLoad();

            gamewindow.VSync = VSyncMode.On;

            PostLoad();
        };

        gamewindow.Resize += (s, e) =>
        {
            GL.Viewport (0, 0, gamewindow.Width, gamewindow.Height);
            GL.MatrixMode (MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho (0, gamewindow.Width, gamewindow.Height, 0, -1, 1);

            canvas.SetSize (gamewindow.Width, gamewindow.Height);
        };

        gamewindow.UpdateFrame += (s, e) =>
        {
            PreUpdate();

            if (renderer.TextCacheSize > 1000)
                renderer.FlushTextCache();

            PostUpdate();
        };

        gamewindow.RenderFrame += (s, e) =>
        {
            gamewindow.MakeCurrent();

            PreRender();

            canvas.RenderCanvas();

            PostRender();

            gamewindow.SwapBuffers();
        };
    }
コード例 #11
0
 /// <summary>
 /// Add your game rendering code here.
 /// </summary>
 /// <param name="e">Contains timing information.</param>
 /// <remarks>There is no need to call the base implementation.</remarks>
 public static void OnRenderFrame(EventArgs e)
 {
     GL.Disable(EnableCap.AlphaTest);
     canvas.RenderCanvas();
     GL.Enable(EnableCap.AlphaTest);
 }
コード例 #12
0
ファイル: Sample.cs プロジェクト: LawlietRyuuzaki/gwen-dotnet
        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();
        }