예제 #1
0
        protected override void OnStartRunning()
        {
            base.OnStartRunning();
            if (initialized)
            {
                return;
            }

            // setup window
            Debug.Log("GLFW Window init.");

            var env    = World.TinyEnvironment();
            var config = env.GetConfigData <DisplayInfo>();

            try
            {
                initialized = GLFWNativeCalls.init(config.width, config.height);
            }
            catch
            {
                Debug.Log("  Excepted (Is lib_unity_tiny_glfw.dll missing?).");
                initialized = false;
            }
            if (!initialized)
            {
                Debug.Log("  Failed.");
                World.QuitUpdate = true;
            }
            int winw = 0, winh = 0;

            GLFWNativeCalls.getWindowSize(ref winw, ref winh);
            config.focused     = true;
            config.visible     = true;
            config.orientation = winw >= winh ? DisplayOrientation.Horizontal : DisplayOrientation.Vertical;
            config.frameWidth  = winw;
            config.frameHeight = winh;
            int sw = 0, sh = 0;

            GLFWNativeCalls.getScreenSize(ref sw, ref sh);
            config.screenWidth  = sw;
            config.screenHeight = sh;
            config.width        = winw;
            config.height       = winh;
            int fbw = 0, fbh = 0;

            GLFWNativeCalls.getFramebufferSize(ref fbw, ref fbh);
            config.framebufferWidth  = fbw;
            config.framebufferHeight = fbh;
            env.SetConfigData(config);
            frameTime = GLFWNativeCalls.time();
        }
예제 #2
0
        protected override void OnUpdate()
        {
            if (!initialized)
            {
                return;
            }
            GLFWNativeCalls.swapBuffers();
            var env = World.TinyEnvironment();
            var config = env.GetConfigData <DisplayInfo>();
            int winw = 0, winh = 0;

            GLFWNativeCalls.getWindowSize(ref winw, ref winh);
            if (winw != config.width || winh != config.height)
            {
                if (config.autoSizeToFrame)
                {
                    config.width       = winw;
                    config.height      = winh;
                    config.frameWidth  = winw;
                    config.frameHeight = winh;
                    int fbw = 0, fbh = 0;
                    GLFWNativeCalls.getFramebufferSize(ref fbw, ref fbh);
                    config.framebufferWidth  = fbw;
                    config.framebufferHeight = fbh;
                    env.SetConfigData(config);
                }
                else
                {
                    GLFWNativeCalls.resize(config.width, config.height);
                }
            }
            if (!GLFWNativeCalls.messagePump())
            {
                Debug.Log("GLFW message pump exit.");
                GLFWNativeCalls.shutdown(1);
                World.QuitUpdate = true;
                initialized      = false;
                return;
            }
#if DEBUG
            GLFWNativeCalls.debugClear();
#endif
            double newFrameTime = GLFWNativeCalls.time();
            env.StepWallRealtimeFrame(newFrameTime - frameTime);
            frameTime = newFrameTime;
        }