public static Gdk.Visual GetBestWithDepth(int depth) { IntPtr raw_ret = gdk_visual_get_best_with_depth(depth); Gdk.Visual ret = GLib.Object.GetObject(raw_ret) as Gdk.Visual; return(ret); }
public static Gdk.Visual GetBestWithBoth(int depth, Gdk.VisualType visual_type) { IntPtr raw_ret = gdk_visual_get_best_with_both(depth, (int)visual_type); Gdk.Visual ret = GLib.Object.GetObject(raw_ret) as Gdk.Visual; return(ret); }
public Context(Gdk.Screen screen, Context share_list, int [] attr) { IntPtr xdisplay = GdkUtils.GetXDisplay(screen.Display); IntPtr visual_info = IntPtr.Zero; // Be careful about the first glx call and handle the exception // with more grace. try { visual_info = glXChooseVisual(xdisplay, screen.Number, attr); } catch (DllNotFoundException e) { throw new GlxException("Unable to find OpenGL libarary", e); } catch (EntryPointNotFoundException enf) { throw new GlxException("Unable to find Glx entry point", enf); } if (visual_info == IntPtr.Zero) { throw new GlxException("Unable to find matching visual"); } XVisualInfo xinfo = (XVisualInfo)Marshal.PtrToStructure(visual_info, typeof(XVisualInfo)); HandleRef share = share_list != null ? share_list.Handle : new HandleRef(null, IntPtr.Zero); IntPtr tmp = glXCreateContext(xdisplay, visual_info, share, true); if (tmp == IntPtr.Zero) { throw new GlxException("Unable to create context"); } handle = new HandleRef(this, tmp); visual = GdkUtils.LookupVisual(screen, xinfo.visualid); if (visual_info != IntPtr.Zero) { XFree(visual_info); } }
public Gdk.Colormap GetColormap(Gdk.Screen screen, ) { DrawableFormat template = new DrawableFormat(); template.Color = new ColorFormat(); FormatMask mask = FormatMask.None; int num = screen.Number; IntPtr dformat = GlitzAPI.glitz_glx_find_window_format(GdkUtils.GetXDisplay(screen.Display), num, mask, ref template, 0); visual_info = GlitzAPI.glitz_glx_get_visual_info_from_format(dpy, scr, dformat); Gdk.Visual visual = new Gdk.Visual(gdkx_visual_get(XVisualIDFromVisual(vinfo))); new Gdk.Colormap(visual, true); * / }
void HandleRealized(object sender, EventArgs eventArgs) { if (renderingContextHandle.Handle != IntPtr.Zero) { return; } switch (platformID) { case PlatformID.Win32NT: case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.WinCE: LoadLibrary("opengl32.dll"); IntPtr windowHandle = gdk_win32_drawable_get_handle(GdkWindow.Handle); IntPtr deviceContext = GetDC(windowHandle); PIXELFORMATDESCRIPTOR pixelFormatDescriptor = new PIXELFORMATDESCRIPTOR(); pixelFormatDescriptor.nSize = (short)System.Runtime.InteropServices.Marshal.SizeOf(pixelFormatDescriptor); pixelFormatDescriptor.nVersion = 1; pixelFormatDescriptor.iPixelType = PFD_TYPE_RGBA; pixelFormatDescriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; if (doubleBuffer) { pixelFormatDescriptor.dwFlags |= PFD_DOUBLEBUFFER; } pixelFormatDescriptor.cColorBits = colorBits; pixelFormatDescriptor.cAlphaBits = alphaBits; pixelFormatDescriptor.cDepthBits = depthBits; pixelFormatDescriptor.cStencilBits = stencilBits; int pixelFormat = ChoosePixelFormat(deviceContext, ref pixelFormatDescriptor); if (!SetPixelFormat(deviceContext, pixelFormat, ref pixelFormatDescriptor)) { throw new Exception("Cannot SetPixelFormat!"); } IntPtr renderingContext = wglCreateContext(deviceContext); renderingContextHandle = new HandleRef(this, renderingContext); ReleaseDC(windowHandle, deviceContext); break; case PlatformID.Unix: default: int[] attributeList = new int[24]; int attributeIndex = 0; attributeList[attributeIndex++] = GLX_RGBA; if (doubleBuffer) { attributeList[attributeIndex++] = GLX_DOUBLEBUFFER; } attributeList[attributeIndex++] = GLX_RED_SIZE; attributeList[attributeIndex++] = 1; attributeList[attributeIndex++] = GLX_GREEN_SIZE; attributeList[attributeIndex++] = 1; attributeList[attributeIndex++] = GLX_BLUE_SIZE; attributeList[attributeIndex++] = 1; if (alphaBits != 0) { attributeList[attributeIndex++] = GLX_ALPHA_SIZE; attributeList[attributeIndex++] = 1; } if (depthBits != 0) { attributeList[attributeIndex++] = GLX_DEPTH_SIZE; attributeList[attributeIndex++] = 1; } if (stencilBits != 0) { attributeList[attributeIndex++] = GLX_STENCIL_SIZE; attributeList[attributeIndex++] = 1; } attributeList[attributeIndex++] = GLX_NONE; IntPtr xDisplay = gdk_x11_display_get_xdisplay(Screen.Display.Handle); IntPtr visualIntPtr = IntPtr.Zero; try { visualIntPtr = glXChooseVisual(xDisplay, Screen.Number, attributeList); } catch (DllNotFoundException e) { throw new Exception("OpenGL dll not found!", e); } catch (EntryPointNotFoundException enf) { throw new Exception("Glx entry point not found!", enf); } if (visualIntPtr == IntPtr.Zero) { throw new Exception("Visual"); } XVisualInfo xVisualInfo = (XVisualInfo)Marshal.PtrToStructure(visualIntPtr, typeof(XVisualInfo)); IntPtr xRenderingContext = IntPtr.Zero; xRenderingContext = glXCreateContext(xDisplay, visualIntPtr, new HandleRef(null, IntPtr.Zero), true); if (xRenderingContext == IntPtr.Zero) { throw new Exception("Unable to create rendering context"); } renderingContextHandle = new HandleRef(this, xRenderingContext); visual = (Gdk.Visual)GLib.Object.GetObject(gdk_x11_screen_lookup_visual(Screen.Handle, xVisualInfo.visualid)); if (visualIntPtr != IntPtr.Zero) { XFree(visualIntPtr); } break; } }
public Gdk.Colormap GetColormap (Gdk.Screen screen, ) { DrawableFormat template = new DrawableFormat (); template.Color = new ColorFormat (); FormatMask mask = FormatMask.None; int num = screen.Number; IntPtr dformat = GlitzAPI.glitz_glx_find_window_format (GdkUtils.GetXDisplay (screen.Display), num, mask, ref template, 0); visual_info = GlitzAPI.glitz_glx_get_visual_info_from_format (dpy, scr, dformat); Gdk.Visual visual = new Gdk.Visual (gdkx_visual_get (XVisualIDFromVisual (vinfo))); new Gdk.Colormap (visual, true); */ }
public Context (Gdk.Screen screen, Context share_list, int [] attr) { IntPtr xdisplay = GdkUtils.GetXDisplay (screen.Display); IntPtr visual_info = IntPtr.Zero; // Be careful about the first glx call and handle the exception // with more grace. try { visual_info = glXChooseVisual (xdisplay, screen.Number, attr); } catch (DllNotFoundException e) { throw new GlxException ("Unable to find OpenGL libarary", e); } catch (EntryPointNotFoundException enf) { throw new GlxException ("Unable to find Glx entry point", enf); } if (visual_info == IntPtr.Zero) throw new GlxException ("Unable to find matching visual"); XVisualInfo xinfo = (XVisualInfo) Marshal.PtrToStructure (visual_info, typeof (XVisualInfo)); HandleRef share = share_list != null ? share_list.Handle : new HandleRef (null, IntPtr.Zero); IntPtr tmp = glXCreateContext (xdisplay, visual_info, share, true); if (tmp == IntPtr.Zero) throw new GlxException ("Unable to create context"); handle = new HandleRef (this, tmp); visual = GdkUtils.LookupVisual (screen, xinfo.visualid); if (visual_info != IntPtr.Zero) XFree (visual_info); }
void HandleRealized(object sender, EventArgs eventArgs) { if (renderingContextHandle.Handle != IntPtr.Zero) return; switch (platformID) { case PlatformID.Win32NT: case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.WinCE: LoadLibrary("opengl32.dll"); IntPtr windowHandle = gdk_win32_drawable_get_handle(GdkWindow.Handle); IntPtr deviceContext = GetDC(windowHandle); PIXELFORMATDESCRIPTOR pixelFormatDescriptor = new PIXELFORMATDESCRIPTOR(); pixelFormatDescriptor.nSize = (short)System.Runtime.InteropServices.Marshal.SizeOf(pixelFormatDescriptor); pixelFormatDescriptor.nVersion = 1; pixelFormatDescriptor.iPixelType = PFD_TYPE_RGBA; pixelFormatDescriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; if (doubleBuffer) pixelFormatDescriptor.dwFlags |= PFD_DOUBLEBUFFER; pixelFormatDescriptor.cColorBits = colorBits; pixelFormatDescriptor.cAlphaBits = alphaBits; pixelFormatDescriptor.cDepthBits = depthBits; pixelFormatDescriptor.cStencilBits = stencilBits; int pixelFormat = ChoosePixelFormat(deviceContext, ref pixelFormatDescriptor); if (!SetPixelFormat(deviceContext, pixelFormat, ref pixelFormatDescriptor)) throw new Exception("Cannot SetPixelFormat!"); IntPtr renderingContext = wglCreateContext(deviceContext); renderingContextHandle = new HandleRef(this, renderingContext); ReleaseDC(windowHandle, deviceContext); if (sharedContextWidget != null) { GLWidget primaryWidget = sharedContextWidget; while (primaryWidget.sharedContextWidget != null) primaryWidget = primaryWidget.sharedContextWidget; if (primaryWidget.RenderingContextHandle.Handle != IntPtr.Zero) { wglShareLists(primaryWidget.RenderingContextHandle.Handle, RenderingContextHandle.Handle); } else { this.sharedContextWidget = null; primaryWidget.sharedContextWidget = this; } } break; case PlatformID.Unix: default: int[] attributeList = new int[24]; int attributeIndex = 0; attributeList[attributeIndex++] = GLX_RGBA; if (doubleBuffer) attributeList[attributeIndex++] = GLX_DOUBLEBUFFER; attributeList[attributeIndex++] = GLX_RED_SIZE; attributeList[attributeIndex++] = 1; attributeList[attributeIndex++] = GLX_GREEN_SIZE; attributeList[attributeIndex++] = 1; attributeList[attributeIndex++] = GLX_BLUE_SIZE; attributeList[attributeIndex++] = 1; if (alphaBits != 0) { attributeList[attributeIndex++] = GLX_ALPHA_SIZE; attributeList[attributeIndex++] = 1; } if (depthBits != 0) { attributeList[attributeIndex++] = GLX_DEPTH_SIZE; attributeList[attributeIndex++] = 1; } if (stencilBits != 0) { attributeList[attributeIndex++] = GLX_STENCIL_SIZE; attributeList[attributeIndex++] = 1; } attributeList[attributeIndex++] = GLX_NONE; IntPtr xDisplay = gdk_x11_display_get_xdisplay(Screen.Display.Handle); IntPtr visualIntPtr = IntPtr.Zero; try { visualIntPtr = glXChooseVisual(xDisplay, Screen.Number, attributeList); } catch (DllNotFoundException e) { throw new Exception("OpenGL dll not found!", e); } catch (EntryPointNotFoundException enf) { throw new Exception("Glx entry point not found!", enf); } if (visualIntPtr == IntPtr.Zero) { throw new Exception("Visual"); } XVisualInfo xVisualInfo = (XVisualInfo)Marshal.PtrToStructure(visualIntPtr, typeof(XVisualInfo)); IntPtr xRenderingContext = IntPtr.Zero; if (sharedContextWidget != null) { GLWidget primaryWidget = sharedContextWidget; while (primaryWidget.sharedContextWidget != null) primaryWidget = primaryWidget.sharedContextWidget; if (primaryWidget.RenderingContextHandle.Handle != IntPtr.Zero) { xRenderingContext = glXCreateContext(xDisplay, visualIntPtr, primaryWidget.RenderingContextHandle, true); } else { xRenderingContext = glXCreateContext(xDisplay, visualIntPtr, new HandleRef(null, IntPtr.Zero), true); this.sharedContextWidget = null; primaryWidget.sharedContextWidget = this; } } else { xRenderingContext = glXCreateContext(xDisplay, visualIntPtr, new HandleRef(null, IntPtr.Zero), true); } if (xRenderingContext == IntPtr.Zero) { throw new Exception("Unable to create rendering context"); } renderingContextHandle = new HandleRef(this, xRenderingContext); visual = (Gdk.Visual)GLib.Object.GetObject(gdk_x11_screen_lookup_visual(Screen.Handle, xVisualInfo.visualid)); if (visualIntPtr != IntPtr.Zero) { XFree(visualIntPtr); } break; } }