static void Main(string[] args) { try { // Initialization GLUTWrapper.Init(1280, 720, "NoesisGUI Integration Sample"); Log.LogCallback += (level, channel, message) => { if (channel == "") { // [TRACE] [DEBUG] [INFO] [WARNING] [ERROR] string[] prefixes = new string[] { "T", "D", "I", "W", "E" }; string prefix = (int)level < prefixes.Length ? prefixes[(int)level] : " "; Console.WriteLine("[NOESIS/" + prefix + "] " + message); } }; GUI.Init(); // Setup embedded resource providers EmbeddedXaml[] xamls = new EmbeddedXaml[] { new EmbeddedXaml { filename = "Reflections.xaml", resource = "Reflections" } }; GUI.SetXamlProvider(new EmbeddedXamlProvider(xamls, Properties.Resources.ResourceManager)); // Data loading { var content = (Noesis.Grid)Noesis.GUI.LoadXaml("Reflections.xaml"); _view = Noesis.GUI.CreateView(content); RenderDevice device = new RenderDeviceGL(); _renderer = _view.Renderer; _renderer.Init(device); } // Attach to Application events GLUTWrapper.Close += OnClose; GLUTWrapper.Tick += OnTick; GLUTWrapper.PreRender += OnPreRender; GLUTWrapper.PostRender += OnPostRender; GLUTWrapper.Resize += OnResize; GLUTWrapper.MouseMove += OnMouseMove; GLUTWrapper.MouseDown += OnMouseDown; GLUTWrapper.MouseUp += OnMouseUp; _eventsAttached = true; // Main Loop GLUTWrapper.Run(); } catch (Exception e) { LogError(e.Message); OnClose(); } }
public override void Init(IntPtr display, IntPtr window, uint samples, bool vsync, bool sRGB) { _display = eglGetDisplay(display); int ma = 0, mi = 0; eglInitialize(_display, ref ma, ref mi); do { int[] attrs = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BUFFER_SIZE, 32, EGL_STENCIL_SIZE, 8, EGL_SAMPLE_BUFFERS, samples > 1 ? 1 : 0, EGL_SAMPLES, (int)(samples > 1 ? samples : 0), EGL_NONE }; IntPtr[] cs = { IntPtr.Zero }; int num = 0; eglChooseConfig(_display, attrs, cs, 1, ref num); if (num != 0) { _config = cs[0]; } else { samples >>= 1; } } while (_config == IntPtr.Zero && samples != 0); int[] attribs = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; _context = eglCreateContext(_display, _config, EGL_NO_CONTEXT, attribs); SetWindow(window); eglSwapInterval(_display, vsync ? 1 : 0); _device = new RenderDeviceGL(); }
public override void Init(IntPtr display, IntPtr window, uint samples, bool vsync, bool sRGB) { _display = display; _window = window; NSOpenGLPixelFormatAttribute[] attrs = { NSOpenGLPixelFormatAttribute.OpenGLProfile, (NSOpenGLPixelFormatAttribute)NSOpenGLProfile.Version3_2Core, NSOpenGLPixelFormatAttribute.DoubleBuffer, NSOpenGLPixelFormatAttribute.Accelerated, NSOpenGLPixelFormatAttribute.ColorSize, (NSOpenGLPixelFormatAttribute)24, NSOpenGLPixelFormatAttribute.Multisample, NSOpenGLPixelFormatAttribute.SampleBuffers, (NSOpenGLPixelFormatAttribute)(samples > 1 ? 1 : 0), NSOpenGLPixelFormatAttribute.Samples, (NSOpenGLPixelFormatAttribute)samples, NSOpenGLPixelFormatAttribute.AlphaSize, (NSOpenGLPixelFormatAttribute)0, NSOpenGLPixelFormatAttribute.DepthSize, (NSOpenGLPixelFormatAttribute)0, NSOpenGLPixelFormatAttribute.StencilSize, (NSOpenGLPixelFormatAttribute)0, (NSOpenGLPixelFormatAttribute)0 }; NSOpenGLPixelFormat pixelFormat = new NSOpenGLPixelFormat(attrs); if (pixelFormat == null) { attrs[1] = (NSOpenGLPixelFormatAttribute)NSOpenGLProfile.VersionLegacy; pixelFormat = new NSOpenGLPixelFormat(attrs); } _context = new NSOpenGLContext(pixelFormat, null); _context.SwapInterval = vsync ? true : false; NSView view = (NSView)ObjCRuntime.Runtime.GetNSObject(window); CALayer layer = new CALayer(); view.Layer = layer; _context.View = view; _context.MakeCurrentContext(); _device = new RenderDeviceGL(); }
public override void Init(IntPtr display, IntPtr window, uint samples, bool vsync, bool sRGB) { _display = display; _window = window; // Dummy window and context to get ARB wgl func pointers PIXELFORMATDESCRIPTOR pfd = new PIXELFORMATDESCRIPTOR(); pfd.nSize = (ushort)System.Runtime.InteropServices.Marshal.SizeOf(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cStencilBits = 8; int pf = ChoosePixelFormat(_display, ref pfd); SetPixelFormat(_display, pf, ref pfd); IntPtr hglrc = wglCreateContext(_display); wglMakeCurrent(_display, hglrc); wglGetExtensionsStringARB = GetProcAddress <GetExtensionsStringARB>("wglGetExtensionsStringARB"); wglChoosePixelFormatARB = GetProcAddress <ChoosePixelFormatARB>("wglChoosePixelFormatARB"); wglCreateContextAttribsARB = GetProcAddress <CreateContextAttribsARB>("wglCreateContextAttribsARB"); wglSwapIntervalEXT = GetProcAddress <SwapIntervalEXT>("wglSwapIntervalEXT"); wglMakeCurrent(IntPtr.Zero, IntPtr.Zero); wglDeleteContext(hglrc); IntPtr extensionStringPtr = wglGetExtensionsStringARB(_display); string extensionString = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(extensionStringPtr); string[] extensions = extensionString.Split(' '); if (Array.IndexOf(extensions, "WGL_ARB_pixel_format") >= 0 && Array.IndexOf(extensions, "WGL_ARB_multisample") >= 0) { do { int[] attribs = { WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, WGL_SUPPORT_OPENGL_ARB, GL_TRUE, WGL_DOUBLE_BUFFER_ARB, GL_TRUE, WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB, WGL_COLOR_BITS_ARB, 24, WGL_STENCIL_BITS_ARB, 8, WGL_SAMPLE_BUFFERS_ARB, samples > 1 ? 1 : 0, WGL_SAMPLES_ARB, samples > 1 ? (int)samples : 0, 0 }; int[] pixelFormats = { 0 }; uint n = 0; if (!wglChoosePixelFormatARB(_display, attribs, null, 1, pixelFormats, ref n) || n == 0) { pf = 0; samples >>= 1; } else { pf = pixelFormats[0]; } }while (pf == 0 && samples != 0); } if (pf == 0) { pf = ChoosePixelFormat(_display, ref pfd); } DescribePixelFormat(_display, pf, (uint)System.Runtime.InteropServices.Marshal.SizeOf(pfd), ref pfd); SetPixelFormat(_display, pf, ref pfd); if (Array.IndexOf(extensions, "WGL_ARB_create_context") >= 0) { int[] versions = { 46, 45, 44, 43, 42, 41, 40, 33 }; int flags = 0; #if DEBUG flags |= WGL_CONTEXT_DEBUG_BIT_ARB; #else if (Array.IndexOf(extensions, "WGL_ARB_create_context_no_error") >= 0) { flags |= WGL_CONTEXT_OPENGL_NO_ERROR_ARB; } #endif for (int i = 0; i < versions.Length && _context == IntPtr.Zero; i++) { int[] attribs = { WGL_CONTEXT_FLAGS_ARB, flags, WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, WGL_CONTEXT_MAJOR_VERSION_ARB, versions[i] / 10, WGL_CONTEXT_MINOR_VERSION_ARB, versions[i] % 10, 0 }; _context = wglCreateContextAttribsARB(_display, IntPtr.Zero, attribs); } } if (_context == IntPtr.Zero) { _context = wglCreateContext(_display); } wglMakeCurrent(_display, _context); if (Array.IndexOf(extensions, "WGL_EXT_swap_control") >= 0) { wglSwapIntervalEXT(vsync ? 1 : 0); } glBindFramebuffer = GetProcAddress <BindFramebuffer>("glBindFramebuffer"); _device = new RenderDeviceGL(); }
public override void Init(IntPtr display, IntPtr window, uint samples, bool vsync, bool sRGB) { _display = display; _window = window; int ma = 0, mi = 0; glXQueryVersion(display, ref ma, ref mi); int screen = 0;//DefaultScreen(display); IntPtr extensionStringPtr = glXQueryExtensionsString(display, screen); string extensionString = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(extensionStringPtr); string[] extensions = extensionString.Split(' '); IntPtr config = IntPtr.Zero; if (samples > 1 && Array.IndexOf(extensions, "GLX_ARB_multisample") >= 0) { do { int[] attrs = { GLX_X_RENDERABLE, GL_TRUE, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DOUBLEBUFFER, GL_TRUE, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_STENCIL_SIZE, 8, GLX_SAMPLE_BUFFERS, samples > 1 ? 1 : 0, GLX_SAMPLES, (int)(samples > 1 ? samples : 0), GL_NONE, }; int num = 0; IntPtr ptr = glXChooseFBConfig(display, screen, attrs, ref num); if (num != 0) { IntPtr[] cs = new IntPtr[num]; System.Runtime.InteropServices.Marshal.Copy(ptr, cs, 0, num); config = cs[0]; } else { samples >>= 1; } XFree(ptr); } while (config == IntPtr.Zero && samples != 0); } else { int[] attrs = { GLX_X_RENDERABLE, GL_TRUE, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DOUBLEBUFFER, GL_TRUE, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_STENCIL_SIZE, 8, GL_NONE, }; int num = 0; IntPtr ptr = glXChooseFBConfig(display, screen, attrs, ref num); IntPtr[] cs = new IntPtr[num]; System.Runtime.InteropServices.Marshal.Copy(ptr, cs, 0, num); config = cs[0]; XFree(ptr); } IntPtr visual = glXGetVisualFromFBConfig(display, config); IntPtr c = glXCreateContext(display, visual, IntPtr.Zero, true); glXCreateContextAttribsARB = GetProcAddress <CreateContextAttribsARB>("glXCreateContextAttribsARB"); glXSwapIntervalEXT = GetProcAddress <SwapIntervalEXT>("glXSwapIntervalEXT"); glXSwapIntervalMESA = GetProcAddress <SwapIntervalMESA>("glXSwapIntervalMESA"); glXSwapIntervalSGI = GetProcAddress <SwapIntervalSGI>("glXSwapIntervalSGI"); glXDestroyContext(display, c); XSetErrorHandler((a, b) => { return(0); }); if (Array.IndexOf(extensions, "GLX_ARB_create_context") >= 0) { int[] versions = { 46, 45, 44, 43, 42, 41, 40, 33 }; int flags = 0; #if DEBUG flags |= GLX_CONTEXT_DEBUG_BIT_ARB; #endif for (int i = 0; i < versions.Length && _context == IntPtr.Zero; i++) { int[] attribs = { GLX_CONTEXT_FLAGS_ARB, flags, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, GLX_CONTEXT_MAJOR_VERSION_ARB, versions[i] / 10, GLX_CONTEXT_MINOR_VERSION_ARB, versions[i] % 10, 0 }; _context = glXCreateContextAttribsARB(display, config, IntPtr.Zero, true, attribs); } } XSetErrorHandler(null); if (_context == IntPtr.Zero) { _context = glXCreateContext(display, visual, IntPtr.Zero, true); } glXMakeCurrent(display, window, _context); if (Array.IndexOf(extensions, "GLX_EXT_swap_control") >= 0) { glXSwapIntervalEXT(display, window, vsync ? 1 : 0); } else if (Array.IndexOf(extensions, "GLX_MESA_swap_control") >= 0) { glXSwapIntervalMESA((uint)(vsync ? 1 : 0)); } else if (Array.IndexOf(extensions, "GLX_SGI_swap_control") >= 0) { glXSwapIntervalSGI(vsync ? 1 : 0); } _device = new RenderDeviceGL(); }