示例#1
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 (Globals.appletMode && container == null)
            //{
            //    container = (Container)Globals.applet;
            //}

            if (device == null)
            {
                GraphicsEnvironment env = GraphicsEnvironment.GetLocalGraphicsEnvironment();
                device = env.GetDefaultScreenDevice();
            }

            if (oldDisplayMode == null)
            {
                oldDisplayMode = device.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 + '\\');
            if (!Globals.appletMode)
            {
                if (window != null)
                {
                    Shutdown();
                }
                window    = new Frame("Jake2 (jsr231)");
                container = window;
                ImageIcon icon = new ImageIcon(GetType().GetResource("/icon-small.png"));
                window.SetIconImage(icon.GetImage());
                window.SetLayout(new GridBagLayout());
                window.AddWindowListener(new AnonymousWindowAdapter(this));
            }

            if (Globals.appletMode)
            {
                Shutdown();
                fullscreen = false;
                JOGLKBD.Init(container);
            }

            Display canvas = new Display(new GLCapabilities());

            canvas.SetFocusTraversalKeysEnabled(false);
            canvas.SetSize(newDim.Width, newDim.Height);
            GridBagConstraints gbc = new GridBagConstraints();

            gbc.fill    = GridBagConstraints.BOTH;
            gbc.weightx = gbc.weighty = 1;
            container.AddComponentListener(JOGLKBD.listener);
            canvas.AddKeyListener(JOGLKBD.listener);
            canvas.AddMouseListener(JOGLKBD.listener);
            canvas.AddMouseMotionListener(JOGLKBD.listener);
            canvas.AddMouseWheelListener(JOGLKBD.listener);
            if (fullscreen)
            {
                container.Add(canvas, gbc);
                VideoMode VideoMode = FindDisplayMode(newDim);
                newDim.Width  = VideoMode.GetWidth();
                newDim.Height = VideoMode.GetHeight();
                window.SetUndecorated(true);
                window.SetResizable(false);
                device.SetFullScreenWindow(window);
                if (device.IsFullScreenSupported())
                {
                    device.SetDisplayMode(VideoMode);
                }
                window.SetLocation(0, 0);
                window.SetSize(VideoMode.GetWidth(), VideoMode.GetHeight());
                canvas.SetSize(VideoMode.GetWidth(), VideoMode.GetHeight());
                VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + GetModeString(VideoMode) + '\\');
            }
            else
            {
                if (!Globals.appletMode)
                {
                    container.Add(canvas, gbc);
                    Frame f2 = window;
                    try
                    {
                        EventQueue.InvokeAndWait(new AnonymousRunnable(this));
                    }
                    catch (Exception e)
                    {
                        e.PrintStackTrace();
                    }
                }
                else
                {
                    Display fd = canvas;
                    try
                    {
                        EventQueue.InvokeAndWait(new AnonymousRunnable1(this));
                    }
                    catch (Exception e)
                    {
                        e.PrintStackTrace();
                    }
                }
            }

            if (!Globals.appletMode)
            {
                while (!canvas.IsDisplayable() || !window.IsDisplayable())
                {
                    try
                    {
                        Thread.Sleep(100);
                    }
                    catch (InterruptedException e)
                    {
                    }
                }
            }

            canvas.RequestFocus();
            this.display = canvas;
            SetGL(display.GetGL());
            Init(0, 0);
            return(Base.rserr_ok);
        }