Пример #1
0
        public bool init(int xpos, int ypos)
        {
            if (this.window == null)
            {
                return(true);
            }

            Base.setVid(this.window.ClientSize.X, this.window.ClientSize.Y);
            VID.NewWindow(this.window.ClientSize.X, this.window.ClientSize.Y);

            return(true);
        }
Пример #2
0
            public virtual void SetBounds(int x, int y, int width, int height)
            {
                int mask = ~0x03;

                if ((width & 0x03) != 0)
                {
                    width &= mask;
                    width += 4;
                }

                base.SetBounds(x, y, width, height);
                Base.SetVid(width, height);
                VID.NewWindow(width, height);
            }
Пример #3
0
        public unsafe int setMode(Size dim, int mode, bool fullscreen)
        {
            var windowSize = new Size();

            VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\n");
            VID.Printf(Defines.PRINT_ALL, $"...setting mode {mode}:");

            if (this.oldDisplayMode == null)
            {
                GLFW.Init();
                var videoMode = GLFW.GetVideoMode(GLFW.GetPrimaryMonitor())[0];

                this.oldDisplayMode =
                    new(videoMode.Width, videoMode.Height, videoMode.RefreshRate, videoMode.RedBits + videoMode.GreenBits + videoMode.BlueBits);
            }

            if (!VID.GetModeInfo(ref windowSize, mode))
            {
                VID.Printf(Defines.PRINT_ALL, " invalid mode\n");

                return(Base.rserr_invalid_mode);
            }

            VID.Printf(Defines.PRINT_ALL, $" {windowSize.Width} {windowSize.Height}{'\n'}");

            if (this.window != null)
            {
                this.shutdown();
            }

            if (fullscreen)
            {
                var displayMode =
                    this.getModeList().FirstOrDefault(displayMode => displayMode.Width == windowSize.Width && displayMode.Height == windowSize.Height)
                    ?? this.oldDisplayMode;

                this.window = new(GameWindowSettings.Default, new()
                {
                    Profile = ContextProfile.Compatability, Size = new(displayMode.Width, displayMode.Height), IsFullscreen = true
                });

                VID.Printf(
                    Defines.PRINT_ALL,
                    $"...setting fullscreen {displayMode.Width}x{displayMode.Height}x{displayMode.BitDepth}@{displayMode.RefreshRate}Hz\n"
                    );
            }
            else
            {
                this.window = new(GameWindowSettings.Default, new()
                {
                    Profile = ContextProfile.Compatability, Size = new(windowSize.Width, windowSize.Height)
                });

                VID.Printf(Defines.PRINT_ALL, $"...setting window {windowSize.Width}x{windowSize.Height}\n");
            }

            this.window.Focus();
            this.window.Closed += OpenTkDriver.QuitOnClose;

            OpenTkKBD.Window        = this.window;
            this.window.KeyDown    += OpenTkKBD.Listener.KeyDown;
            this.window.KeyUp      += OpenTkKBD.Listener.KeyUp;
            this.window.MouseDown  += OpenTkKBD.Listener.MouseDown;
            this.window.MouseUp    += OpenTkKBD.Listener.MouseUp;
            this.window.MouseMove  += OpenTkKBD.Listener.MouseMove;
            this.window.MouseWheel += OpenTkKBD.Listener.MouseWheel;

            Program.UpdateLoop = _ => this.window.Run();

            var initialized = false;

            var updateAccumulator = 0.0;
            var renderAccumulator = 0.0;

            this.window.UpdateFrame += args =>
            {
                updateAccumulator += args.Time * 1000;

                var elapsed = (int)updateAccumulator;

                if (elapsed <= 0)
                {
                    return;
                }

                Qcommon.FrameUpdate(elapsed);
                updateAccumulator -= elapsed;
            };

            this.window.RenderFrame += args =>
            {
                if (!initialized)
                {
                    this.init(0, 0);
                    initialized = true;
                }

                renderAccumulator += args.Time * 1000;

                var elapsed = (int)renderAccumulator;

                if (elapsed <= 0)
                {
                    return;
                }

                Qcommon.FrameRender(elapsed);
                renderAccumulator -= elapsed;
            };

            this.window.Resize += args =>
            {
                Base.setVid(this.window.ClientSize.X, this.window.ClientSize.Y);
                VID.NewWindow(this.window.ClientSize.X, this.window.ClientSize.Y);
            };

            return(Base.rserr_ok);
        }
Пример #4
0
        public virtual int SetMode(Size dim, int mode, bool fullscreen)
        {
            VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\\n");
            VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":");

            unsafe {
                Monitor *device = GLFW.GetPrimaryMonitor();
                if (oldDisplayMode == null)
                {
                    oldDisplayMode = GLFW.GetVideoMode(device)[0];
                }
            }

            if (!VID.GetModeInfo(out var newDim, mode))
            {
                VID.Printf(Defines.PRINT_ALL, " invalid mode\\n");
                return(Base.rserr_invalid_mode);
            }

            VID.Printf(Defines.PRINT_ALL, " " + newDim.Width + " " + newDim.Height + '\\');
            Shutdown();

            var newInstance = (window == null);

            if (!newInstance)
            {
                window.Dispose();
            }

            window = new GameWindow(new GameWindowSettings(), new NativeWindowSettings
            {
                Title        = "Q2Sharp (jogl)",
                Size         = new OpenTK.Mathematics.Vector2i(newDim.Width, newDim.Height),
                StartVisible = false,
                WindowBorder = OpenTK.Windowing.Common.WindowBorder.Fixed,
                IsFullscreen = false
                               //Icon = new OpenTK.Windowing.Common.Input.WindowIcon(new OpenTK.Windowing.Common.Input.Image(32,32,null)),
            });

            window.RenderFrame += (t) => Program.Frame();
            Program.RunWindow  += () => window.Run();

            //ImageIcon icon = new ImageIcon(GetType().GetResource("/icon-small.png"));
            Bitmap bitmap = (Bitmap)Bitmap.FromStream(GetType().Assembly.GetManifestResourceStream("/icon-small.png"));

            byte[] pixels = new byte[bitmap.Width * bitmap.Height];

            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    var color = bitmap.GetPixel(x, y);
                    Array.Copy(new byte[] { color.R, color.G, color.B, color.A }, 0, pixels, (y * bitmap.Width + x) * 4, 4);
                }
            }

            Image icon = new Image(bitmap.Width, bitmap.Height, pixels);

            window.Icon = new WindowIcon(icon);

            window.Minimized += (e) => JOGLKBD.listener.ComponentHidden(e);
            window.Maximized += (e) =>
            {
                JOGLKBD.c = window;
                JOGLKBD.listener.ComponentShown(e);
            };
            window.Move       += (e) => JOGLKBD.listener.ComponentMoved(e);
            window.Closing    += (e) => Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit");
            window.Resize     += (e) => JOGLKBD.listener.ComponentResized(e);
            window.KeyDown    += (e) => JOGLKBD.listener.KeyPressed(e);
            window.KeyUp      += (e) => JOGLKBD.listener.KeyReleased(e);
            window.TextInput  += (e) => JOGLKBD.listener.KeyTyped(e);
            window.MouseEnter += () => JOGLKBD.listener.MouseEntered();
            window.MouseLeave += () => JOGLKBD.listener.MouseExited();
            window.MouseMove  += (e) => JOGLKBD.listener.MouseMoved(e);
            window.MouseDown  += (e) => JOGLKBD.listener.MousePressed(e);
            window.MouseUp    += (e) => JOGLKBD.listener.MouseReleased(e);
            window.MouseWheel += (e) => JOGLKBD.listener.MouseWheelMoved(e);
            //window.drag += ( e ) => JOGLKBD.listener.MouseDragged( e );

            if (fullscreen)
            {
                window.WindowState = OpenTK.Windowing.Common.WindowState.Fullscreen;
                VideoMode VideoMode = FindDisplayMode(newDim);
                newDim.Width       = VideoMode.Width;
                newDim.Height      = VideoMode.Height;
                window.WindowState = WindowState.Fullscreen;
                if (window.IsFullscreen)
                {
                    unsafe
                    {
                        GLFW.SetWindowSize(window.WindowPtr, VideoMode.Width, VideoMode.Height);
                    }
                }
                window.Location = new OpenTK.Mathematics.Vector2i();
                window.Size     = new OpenTK.Mathematics.Vector2i(VideoMode.Width, VideoMode.Height);
                VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + GetModeString(VideoMode) + '\\');
                window.IsVisible = true;
            }
            else
            {
                window.Location  = new OpenTK.Mathematics.Vector2i(window_xpos, window_ypos);
                window.IsVisible = true;
            }

            Base.SetVid(newDim.Width, newDim.Height);
            VID.NewWindow(newDim.Width, newDim.Height);

            return(Base.rserr_ok);
        }
Пример #5
0
        public virtual int SetMode(Size dim, int mode, bool fullscreen)
        {
            VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\\n");
            VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":");
            if (oldDisplayMode == null)
            {
                oldDisplayMode = Display.GetDisplayMode();
            }

            if (!VID.GetModeInfo(out var newDim, mode))
            {
                VID.Printf(Defines.PRINT_ALL, " invalid mode\\n");
                return(Base.rserr_invalid_mode);
            }

            VID.Printf(Defines.PRINT_ALL, " " + newDim.Width + " " + newDim.Height + '\\');
            Shutdown();
            Display.SetTitle("Jake2 (lwjgl)");
            VideoMode VideoMode = FindDisplayMode(newDim);

            newDim.Width  = VideoMode.GetWidth();
            newDim.Height = VideoMode.GetHeight();
            if (fullscreen)
            {
                try
                {
                    Display.SetDisplayMode(VideoMode);
                }
                catch (LWJGLException e)
                {
                    return(Base.rserr_invalid_mode);
                }

                Display.SetLocation(0, 0);
                try
                {
                    Display.SetFullscreen(fullscreen);
                }
                catch (LWJGLException e)
                {
                    return(Base.rserr_invalid_fullscreen);
                }

                VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + GetModeString(VideoMode) + '\\');
            }
            else
            {
                try
                {
                    Display.SetDisplayMode(VideoMode);
                }
                catch (LWJGLException e)
                {
                    return(Base.rserr_invalid_mode);
                }

                try
                {
                    Display.SetFullscreen(false);
                }
                catch (LWJGLException e)
                {
                    return(Base.rserr_invalid_fullscreen);
                }
            }

            Base.SetVid(newDim.width, newDim.height);
            try
            {
                Display.Create();
            }
            catch (LWJGLException e)
            {
                return(Base.rserr_unknown);
            }

            VID.NewWindow(newDim.width, newDim.height);
            return(Base.rserr_ok);
        }