Пример #1
0
            /// <summary>
            /// Default constructor.
            /// </summary>
            public NativeWindow(int x, int y, uint width, uint height)
            {
                try {
                    // Open display
                    if ((_Display = Glx.XOpenDisplay(IntPtr.Zero)) == IntPtr.Zero)
                    {
                        throw new InvalidOperationException("unable to connect to X server");
                    }

                    Glx.XVisualInfo visual;
                    IntPtr          config;

                    int[] attributes = new int[] {
                        Glx.DRAWABLE_TYPE, (int)Glx.WINDOW_BIT,
                        Glx.RENDER_TYPE, (int)Glx.RGBA_BIT,
                        Glx.DOUBLEBUFFER, unchecked ((int)Glx.DONT_CARE),
                        Glx.RED_SIZE, 1,
                        Glx.GREEN_SIZE, 1,
                        Glx.BLUE_SIZE, 1,
                        0
                    };

                    int screen = Glx.XDefaultScreen(_Display);

                    // Get basic visual
                    unsafe {
                        int[] choosenConfigCount = new int[1];

                        IntPtr *choosenConfigs = Glx.ChooseFBConfig(_Display, screen, attributes, choosenConfigCount);
                        if (choosenConfigCount[0] == 0)
                        {
                            throw new InvalidOperationException("unable to find basic visual");
                        }
                        config = *choosenConfigs;
                        KhronosApi.LogComment("Choosen config is 0x{0}", config.ToString("X8"));

                        visual = Glx.GetVisualFromFBConfig(_Display, config);
                        KhronosApi.LogComment("Choosen visual is {0}", visual);

                        Glx.XFree((IntPtr)choosenConfigs);

                        _InternalConfig = config;
                        _InternalVisual = visual;
                    }

                    Glx.XSetWindowAttributes setWindowAttrs = new Glx.XSetWindowAttributes();
                    IntPtr rootWindow         = Glx.XRootWindow(_Display, screen);
                    ulong  setWindowAttrFlags = /* CWBorderPixel | CWColormap | CWEventMask*/ (1L << 3) | (1L << 13) | (1L << 11);

                    setWindowAttrs.border_pixel = IntPtr.Zero;
                    setWindowAttrs.event_mask   = /* StructureNotifyMask	*/new IntPtr(1L << 17);
                    setWindowAttrs.colormap     = Glx.XCreateColormap(_Display, rootWindow, visual.visual, /* AllocNone */ 0);

                    if ((_Handle = Glx.XCreateWindow(_Display, rootWindow, x, y, (int)width, (int)height, 0, visual.depth, /* InputOutput */ 0, visual.visual, new UIntPtr(setWindowAttrFlags), ref setWindowAttrs)) == IntPtr.Zero)
                    {
                        throw new InvalidOperationException("unable to create window");
                    }

                    // Assign FB configuration to window: essential to make CreateContext(IntPtr) working
                    _GlxHandle = Glx.CreateWindow(_Display, config, _Handle, null);
                } catch {
                    Dispose();
                    throw;
                }
            }