Provides methods to create and control an opengl context on the X11 platform. This class supports OpenTK, and is not intended for use by OpenTK programs.
Inheritance: DesktopGraphicsContext
Exemplo n.º 1
0
        /// <summary>
        /// Opens a new render window with the given DisplayMode.
        /// </summary>
        /// <param name="mode">The DisplayMode of the render window.</param>
        /// <remarks>
        /// Creates the window visual and colormap. Associates the colormap/visual
        /// with the window and raises the window on top of the window stack.
        /// <para>
        /// Colormap creation is currently disabled.
        /// </para>
        /// </remarks>
        public void CreateWindow(DisplayMode mode, out IGLContext glContext)
        {
            if (exists)
                throw new ApplicationException("Render window already exists!");

            Debug.Print("Creating GameWindow with mode: {0}", mode != null ? mode.ToString() : "default");
            Debug.Indent();

            glContext = new X11GLContext();
            (glContext as IGLContextCreationHack).SelectDisplayMode(mode, window);
            if (glContext == null)
                throw new ApplicationException("Could not create GLContext");
            Debug.Print("Created GLContext");
            window.VisualInfo = ((X11.WindowInfo)((IGLContextInternal)glContext).Info).VisualInfo;
            //window.VisualInfo = Marshal.PtrToStructure(Glx.ChooseVisual(window.Display, window.Screen, 

            // Create a window on this display using the visual above
            Debug.Write("Opening render window... ");

            XSetWindowAttributes attributes = new XSetWindowAttributes();
            attributes.background_pixel = IntPtr.Zero;
            attributes.border_pixel = IntPtr.Zero;
            attributes.colormap =
                API.CreateColormap(window.Display, window.RootWindow, window.VisualInfo.visual, 0/*AllocNone*/);
            window.EventMask =
                EventMask.StructureNotifyMask | EventMask.SubstructureNotifyMask | EventMask.ExposureMask |
                EventMask.KeyReleaseMask | EventMask.KeyPressMask |
                    EventMask.PointerMotionMask | /* Bad! EventMask.PointerMotionHintMask | */
                    EventMask.ButtonPressMask | EventMask.ButtonReleaseMask;
            attributes.event_mask = (IntPtr)window.EventMask;

            uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask |
                (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel;

            window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow,
                0, 0, mode.Width, mode.Height, 0, window.VisualInfo.depth/*(int)CreateWindowArgs.CopyFromParent*/,
                (int)CreateWindowArgs.InputOutput, window.VisualInfo.visual, (UIntPtr)mask, ref attributes);

            if (window.Handle == IntPtr.Zero)
                throw new ApplicationException("XCreateWindow call failed (returned 0).");

            // Set the window hints
            XSizeHints hints = new XSizeHints();
            hints.x = 0;
            hints.y = 0;
            hints.width = mode.Width;
            hints.height = mode.Height;
            hints.flags = (IntPtr)(XSizeHintsFlags.USSize | XSizeHintsFlags.USPosition);
            Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints);

            // Register for window destroy notification
            IntPtr wm_destroy_atom = Functions.XInternAtom(window.Display,
                "WM_DELETE_WINDOW", true);
            XWMHints hint = new XWMHints();
            Functions.XSetWMProtocols(window.Display, window.Handle, new IntPtr[] { wm_destroy_atom }, 1);

            Top = Left = 0;
            Right = Width;
            Bottom = Height;

            //XTextProperty text = new XTextProperty();
            //text.value = "OpenTK Game Window";
            //text.format = 8;
            //Functions.XSetWMName(window.Display, window.Handle, ref text);
            //Functions.XSetWMProperties(display, window, name, name, 0,  /*None*/ null, 0, hints);

            Debug.Print("done! (id: {0})", window.Handle);

            (glContext as IGLContextCreationHack).SetWindowHandle(window.Handle);

            API.MapRaised(window.Display, window.Handle);
            mapped = true;

            glContext.CreateContext(true, null);

            driver = new X11Input(window);

            Debug.Unindent();
            Debug.WriteLine("GameWindow creation completed successfully!");
            exists = true;
        }
Exemplo n.º 2
0
        public X11GLNative(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device)
        {
            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
            }
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");
            }

            Debug.Print("Creating X11GLNative window.");
            // Open a display connection to the X server, and obtain the screen and root window.
            window.Display    = API.DefaultDisplay;
            window.Screen     = API.XDefaultScreen(window.Display);             //API.DefaultScreen;
            window.RootWindow = API.XRootWindow(window.Display, window.Screen); // API.RootWindow;

            Debug.Print("Display: {0}, Screen {1}, Root window: {2}", window.Display, window.Screen, window.RootWindow);
            RegisterAtoms(window);
            XVisualInfo info = new XVisualInfo();

            mode = X11GLContext.SelectGraphicsMode(mode, out info);
            window.VisualInfo = info;
            // Create a window on this display using the visual above
            Debug.Print("Opening render window... ");

            XSetWindowAttributes attributes = new XSetWindowAttributes();

            attributes.background_pixel = IntPtr.Zero;
            attributes.border_pixel     = IntPtr.Zero;
            attributes.colormap         = API.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0 /*AllocNone*/);
            window.EventMask            = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask |
                                          EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask |
                                          EventMask.PointerMotionMask | EventMask.FocusChangeMask |
                                          EventMask.ButtonPressMask | EventMask.ButtonReleaseMask |
                                          EventMask.EnterWindowMask | EventMask.LeaveWindowMask |
                                          EventMask.PropertyChangeMask;
            attributes.event_mask = (IntPtr)window.EventMask;

            uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask |
                        (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel;

            window.WindowHandle = API.XCreateWindow(window.Display, window.RootWindow,
                                                    x, y, width, height, 0, window.VisualInfo.Depth /*(int)CreateWindowArgs.CopyFromParent*/,
                                                    (int)CreateWindowArgs.InputOutput, window.VisualInfo.Visual, (IntPtr)mask, ref attributes);

            if (window.WindowHandle == IntPtr.Zero)
            {
                throw new ApplicationException("XCreateWindow call failed (returned 0).");
            }

            if (title != null)
            {
                API.XStoreName(window.Display, window.WindowHandle, title);
            }

            // Set the window hints
            SetWindowMinMax(_min_width, _min_height, -1, -1);

            XSizeHints hints = new XSizeHints();

            hints.base_width  = width;
            hints.base_height = height;
            hints.flags       = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition);
            API.XSetWMNormalHints(window.Display, window.WindowHandle, ref hints);
            // Register for window destroy notification
            API.XSetWMProtocols(window.Display, window.WindowHandle, new IntPtr[] { wm_destroy }, 1);

            // Set the initial window size to ensure X, Y, Width, Height and the rest
            // return the correct values inside the constructor and the Load event.
            XEvent e = new XEvent();

            e.ConfigureEvent.x      = x;
            e.ConfigureEvent.y      = y;
            e.ConfigureEvent.width  = width;
            e.ConfigureEvent.height = height;
            RefreshWindowBounds(ref e);

            Debug.Print("X11GLNative window created successfully (id: {0}).", Handle);
            SetupInput();
            exists = true;
        }
Exemplo n.º 3
0
        public X11Window(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device)
        {
            Debug.Print("Creating X11GLNative window.");
            // Open a display connection to the X server, and obtain the screen and root window.
            Debug.Print("Display: {0}, Screen {1}, Root window: {2}",
                        API.DefaultDisplay, API.DefaultScreen, API.RootWindow);

            RegisterAtoms();
            VisualInfo = X11GLContext.SelectGraphicsMode(mode);
            // Create a window on this display using the visual above
            Debug.Print("Opening render window... ");

            XSetWindowAttributes attributes = new XSetWindowAttributes();

            attributes.colormap = API.XCreateColormap(API.DefaultDisplay, API.RootWindow, VisualInfo.Visual, 0 /*AllocNone*/);

            eventMask = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask |
                        EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask |
                        EventMask.PointerMotionMask | EventMask.FocusChangeMask |
                        EventMask.ButtonPressMask | EventMask.ButtonReleaseMask |
                        EventMask.EnterWindowMask | EventMask.LeaveWindowMask |
                        EventMask.PropertyChangeMask;
            attributes.event_mask = (IntPtr)eventMask;

            uint mask =
                (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask |
                (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel;

            WinHandle = API.XCreateWindow(API.DefaultDisplay, API.RootWindow,
                                          x, y, width, height, 0, VisualInfo.Depth /*(int)CreateWindowArgs.CopyFromParent*/,
                                          (int)CreateWindowArgs.InputOutput, VisualInfo.Visual, (IntPtr)mask, ref attributes);

            if (WinHandle == IntPtr.Zero)
            {
                throw new ApplicationException("XCreateWindow call failed (returned 0).");
            }

            if (title != null)
            {
                API.XStoreName(API.DefaultDisplay, WinHandle, title);
            }

            XSizeHints hints = new XSizeHints();

            hints.base_width  = width;
            hints.base_height = height;
            hints.flags       = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition);
            API.XSetWMNormalHints(API.DefaultDisplay, WinHandle, ref hints);
            // Register for window destroy notification
            API.XSetWMProtocols(API.DefaultDisplay, WinHandle, new IntPtr[] { wm_destroy }, 1);

            // Set the initial window size to ensure X, Y, Width, Height and the rest
            // return the correct values inside the constructor and the Load event.
            XEvent e = new XEvent();

            e.ConfigureEvent.x      = x;
            e.ConfigureEvent.y      = y;
            e.ConfigureEvent.width  = width;
            e.ConfigureEvent.height = height;
            RefreshWindowBounds(ref e);

            Debug.Print("X11GLNative window created successfully (id: {0}).", WinHandle);
            // Request that auto-repeat is only set on devices that support it physically.
            // This typically means that it's turned off for keyboards (which is what we want).
            // We prefer this method over XAutoRepeatOff/On, because the latter needs to
            // be reset before the program exits.
            bool supported;

            API.XkbSetDetectableAutoRepeat(API.DefaultDisplay, true, out supported);
            Exists = true;
        }