예제 #1
0
        protected override void OnStartRunning()
        {
            base.OnStartRunning();

            if (!initialized)
            {
                throw new InvalidOperationException("GLFW wasn't initialized");
            }

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

            if (config.width <= 0 || config.height <= 0)
            {
                Debug.LogError($"GLFW: configuration entity DisplayInfo has width or height <= 0! ({config.width} {config.height}).  Is it being created properly?");
                throw new InvalidOperationException("Bad DisplayInfo, window can't be opened");
            }

            // no-op if the window is already created
            var ok = GLFWNativeCalls.create_window(config.width, config.height);

            if (!ok)
            {
                throw new InvalidOperationException("Failed to Open GLFW Window!");
            }
            GLFWNativeCalls.show_window(1);

            GLFWNativeCalls.getWindowSize(out int winw, out int winh);
            GLFWNativeCalls.getScreenSize(out int sw, out int sh);
            config.focused           = true;
            config.visible           = true;
            config.orientation       = winw >= winh ? ScreenOrientation.Landscape : ScreenOrientation.Portrait;
            config.frameWidth        = winw;
            config.frameHeight       = winh;
            config.screenWidth       = sw;
            config.screenHeight      = sh;
            config.width             = winw;
            config.height            = winh;
            config.framebufferWidth  = winw;
            config.framebufferHeight = winh;
            env.SetConfigData(config);

            frameTime = GLFWNativeCalls.time();

            windowOpen = true;
        }
예제 #2
0
        protected override void OnStartRunning()
        {
            base.OnStartRunning();

            if (!initialized)
            {
                throw new InvalidOperationException("GLFW wasn't initialized");
            }

            // setup window
            var displayInfo = GetSingleton <DisplayInfo>();

            if (displayInfo.width <= 0 || displayInfo.height <= 0)
            {
                Debug.LogError($"GLFW: configuration entity DisplayInfo has width or height <= 0! ({displayInfo.width} {displayInfo.height}).  Is it being created properly?");
                throw new InvalidOperationException("Bad DisplayInfo, window can't be opened");
            }

            // no-op if the window is already created
            if (GLFWNativeCalls.create_window(displayInfo.width, displayInfo.height) == 0)
            {
                throw new InvalidOperationException("Failed to Open GLFW Window!");
            }
            GLFWNativeCalls.show_window(1);

            GLFWNativeCalls.getWindowSize(out int winw, out int winh);
            GLFWNativeCalls.getScreenSize(out int sw, out int sh);
            displayInfo.focused           = true;
            displayInfo.visible           = true;
            displayInfo.orientation       = winw >= winh ? ScreenOrientation.Landscape : ScreenOrientation.Portrait;
            displayInfo.frameWidth        = winw;
            displayInfo.frameHeight       = winh;
            displayInfo.screenWidth       = sw;
            displayInfo.screenHeight      = sh;
            displayInfo.width             = winw;
            displayInfo.height            = winh;
            displayInfo.framebufferWidth  = winw;
            displayInfo.framebufferHeight = winh;
            displayInfo.screenDpiScale    = 1.0f;
            SetSingleton(displayInfo);

            windowOpen = true;
        }