public override void Dispose() { Glx.glXMakeCurrent(display, visual, IntPtr.Zero); Glx.glXDestroyContext(display, handle); }
public override void CreateContext(IntPtr wnd_handle, IntPtr drawable, OpenGLContext share) { // Force loading of OpenGL library // This is later used by the OpenGL class to implement extensions. //linker = GetLinker(); display = API.OpenDisplay(IntPtr.Zero); if (display == IntPtr.Zero) { throw new InvalidOperationException("Cannot connect to X server"); } wnd = wnd_handle; int[] attr = { Glx.GLX_X_RENDERABLE, 1, Glx.GLX_DRAWABLE_TYPE, Glx.GLX_WINDOW_BIT, Glx.GLX_RENDER_TYPE, Glx.GLX_RGBA_BIT, Glx.GLX_X_VISUAL_TYPE, Glx.GLX_TRUE_COLOR, Glx.GLX_RED_SIZE, 8, Glx.GLX_GREEN_SIZE, 8, Glx.GLX_BLUE_SIZE, 8, Glx.GLX_ALPHA_SIZE, 0, Glx.GLX_DEPTH_SIZE, 16, //Glx.GLX_STENCIL_SIZE , 8, Glx.GLX_DOUBLEBUFFER, 1, 0, 0 }; API.MapWindow(display, wnd); int def_screen = API.DefaultScreen(display); Console.WriteLine("Display: 0x" + display.ToString("x")); Console.WriteLine("Deault screen: 0x" + def_screen.ToString("x")); int[] elems = new int[] { 0 }; //IntPtr fb = Glx.glXChooseFBConfig(display, def_screen, attr, elems); //if (fb == IntPtr.Zero) //throw new InvalidOperationException("Could not retrieve framebuffer configuration"); Console.WriteLine(elems[0]); //var info_ptr = Glx.glXGetVisualFromFBConfig(display, Marshal.ReadIntPtr(fb)); attr = new int[] { GLX_RGBA, GLX_DEPTH_SIZE, 32, GLX_DOUBLEBUFFER, 0 }; //IntPtr info_ptr = Glx.glXChooseVisual(display, def_screen, attr); var info_ptr = API.DefaultVisual(display, def_screen); if (info_ptr == IntPtr.Zero) { throw new NotSupportedException("OpenGL is not supported."); } VisualInfo info = new VisualInfo(); Marshal.PtrToStructure(info_ptr, info); visual = info_ptr; handle = Glx.glXCreateContext(display, visual, IntPtr.Zero, true); if (handle == IntPtr.Zero) { throw new InvalidOperationException("Unable to create OpenGL context"); } Glx.glXMakeCurrent(display, visual, handle); int[] parameters = new int[] { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 2, 0 }; glXCreateContextAttribsARB = GetProc <XCreateContextAttribsARBProc>("glXCreateContextAttribsARB"); if (glXCreateContextAttribsARB == null) { throw new NotSupportedException("OpenGL 3.0 not supported."); } IntPtr new_handle = glXCreateContextAttribsARB(display, info_ptr, share.Handle, true, parameters); if (new_handle == IntPtr.Zero) { throw new NotSupportedException("OpenGL 3.0 not supported."); } Glx.glXMakeCurrent(display, visual, IntPtr.Zero); Glx.glXDestroyContext(display, handle); Glx.glXMakeCurrent(display, visual, new_handle); handle = new_handle; Console.WriteLine("glX Initialization succeded."); }