Ejemplo n.º 1
0
        public bool InitialiseOpenGL()
        {
            GLFWBindingsContext binding = new GLFWBindingsContext();

            GL.LoadBindings(binding);

            if (GLFW.Init())
            {
                GL.ClearColor(0.2f, 0.4f, 0.8f, 1.0f);
                GL.Enable(EnableCap.CullFace);
                GL.CullFace(CullFaceMode.Back);
                GL.Enable(EnableCap.DepthTest);
                GL.DepthFunc(DepthFunction.Less);
                GL.DepthMask(true);

                //GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                //GL.ShadeModel(ShadingModel.Smooth);

                LogManager.OpenGLLogger.Log("Successfully initialised GLFW and OpenGL");
                return(true);
            }
            else
            {
                Console.WriteLine("Failed to initialise GLFW and OpenGL");
                return(false);
            }
        }
Ejemplo n.º 2
0
        private static IGraphicsContext GetOrCreateSharedOpenGLContext(GLWpfControlSettings settings)
        {
            if (_sharedContext != null)
            {
                var isSameContext = GLWpfControlSettings.WouldResultInSameContext(settings, _sharedContextSettings);
                if (!isSameContext)
                {
                    throw new ArgumentException($"The provided {nameof(GLWpfControlSettings)} would result" +
                                                $"in a different context creation to one previously created. To fix this," +
                                                $" either ensure all of your context settings are identical, or provide an " +
                                                $"external context via the '{nameof(GLWpfControlSettings.ContextToUse)}' field.");
                }
            }

            else
            {
                var nws = NativeWindowSettings.Default;
                nws.StartFocused    = false;
                nws.StartVisible    = false;
                nws.NumberOfSamples = 0;
                // if we ask GLFW for 1.0, we should get the highest level context available with full compat.
                nws.APIVersion = new Version(settings.MajorVersion, settings.MinorVersion);
                nws.Flags      = ContextFlags.Offscreen | settings.GraphicsContextFlags;
                // we have to ask for any compat in this case.
                nws.Profile      = settings.GraphicsProfile;
                nws.WindowBorder = WindowBorder.Hidden;
                nws.WindowState  = WindowState.Minimized;
                var glfwWindow = new NativeWindow(nws);
                var provider   = new GLFWBindingsContext();
                Wgl.LoadBindings(provider);
                // we're already in a window context, so we can just cheat by creating a new dependency object here rather than passing any around.
                var depObject = new DependencyObject();
                // retrieve window handle/info
                var window     = Window.GetWindow(depObject);
                var baseHandle = window is null ? IntPtr.Zero : new WindowInteropHelper(window).Handle;
                var hwndSource = new HwndSource(0, 0, 0, 0, 0, "GLWpfControl", baseHandle);

                _sharedContext          = glfwWindow.Context;
                _sharedContextSettings  = settings;
                _sharedContextResources = new IDisposable[] { hwndSource, glfwWindow };
                // GL init
                // var mode = new GraphicsMode(ColorFormat.Empty, 0, 0, 0, 0, 0, false);
                // _commonContext = new GraphicsContext(mode, _windowInfo, _settings.MajorVersion, _settings.MinorVersion,
                //     _settings.GraphicsContextFlags);
                // _commonContext.LoadAll();
                _sharedContext.MakeCurrent();
            }
            Interlocked.Increment(ref _sharedContextReferenceCount);
            return(_sharedContext);
        }
Ejemplo n.º 3
0
        private bool InitializeOpenGL( )
        {
            GLFWBindingsContext binding = new GLFWBindingsContext();

            GL.LoadBindings(binding);
            if (GLFW.Init())
            {
                Console.WriteLine("Succesfully initialised GLFW and OpenGL");
                return(true);
            }
            else
            {
                Console.WriteLine("Failed to initialise GLFW and OpenGL");
                return(false);
            }
        }
        public bool InitialiseOpenGL()
        {
            GLFWBindingsContext binding = new GLFWBindingsContext();

            GL.LoadBindings(binding);

            if (GLFW.Init())
            {
                Console.WriteLine("Initialised GLFW and OpenGL");
                return(true);
            }
            else
            {
                Console.WriteLine("Failed to init GLFW and OpenGL");
                return(false);
            }
        }