コード例 #1
0
        public Sdl2GraphicsContext(GraphicsMode mode,
                                   IWindowInfo win, IGraphicsContext shareContext,
                                   int major, int minor,
                                   OpenTK.Graphics.GraphicsContextFlags flags)
            : this(win)
        {
            lock (SDL.Sync)
            {
                bool retry = false;
                do
                {
                    SetGLAttributes(mode, shareContext, major, minor, flags);
                    SdlContext = new ContextHandle(SDL.GL.CreateContext(Window.Handle));

                    // If we failed to create a valid context, relax the GraphicsMode
                    // and try again.
                    retry =
                        SdlContext == ContextHandle.Zero &&
                        Utilities.RelaxGraphicsMode(ref mode);
                }while (retry);

                if (SdlContext == ContextHandle.Zero)
                {
                    var error = SDL.GetError();
                    Debug.Print("SDL2 failed to create OpenGL context: {0}", error);
                    throw new GraphicsContextException(error);
                }

                Mode = GetGLAttributes(SdlContext, out flags);
            }
            Handle = GraphicsContext.GetCurrentContext();
            Debug.Print("SDL2 created GraphicsContext (handle: {0})", Handle);
            Debug.Print("    GraphicsMode: {0}", Mode);
            Debug.Print("    GraphicsContextFlags: {0}", flags);
        }
コード例 #2
0
ファイル: GameWindow.cs プロジェクト: WeirdBeardDev/arcengine
        /// <summary>
        /// Constructor
        /// </summary>
        public GameWindow(GameWindowParams param)
        {
            Trace.WriteDebugLine("[GameWindow] Constructor()");

            if (param == null)
            {
                Trace.WriteDebugLine("[GameWindow] param == null !");
                throw new ArgumentNullException("param");
            }

            InitializeComponent();

            TK.GraphicsContextFlags compatible = param.Compatible ? TK.GraphicsContextFlags.Default : TK.GraphicsContextFlags.ForwardCompatible;

            // Adds the control to the form
            Trace.WriteDebugLine("[GameWindow] Requesting a {0}.{1} {2}Opengl context (Color: {3}, Depth: {4}, Stencil:{5}, Sample: {6})",
                                 param.Major, param.Minor, param.Compatible ? "compatible " : string.Empty, param.Color, param.Depth, param.Stencil, param.Samples);

            RenderControl = new OpenTK.GLControl(new TK.GraphicsMode(param.Color, param.Depth, param.Stencil, param.Samples),
                                                 param.Major, param.Minor, compatible);
            Trace.WriteDebugLine("[GameWindow] Got GraphicsMode {0}", RenderControl.GraphicsMode);
            RenderControl.Dock = DockStyle.Fill;
            Controls.Add(RenderControl);


            // Resize the window
            ClientSize = param.Size;

            VSync = true;
            if (param.FullScreen)
            {
                SetFullScreen(param.Size, param.Color);
            }
        }
コード例 #3
0
 public Sdl2GraphicsContext(GraphicsMode mode,
                            IWindowInfo win, IGraphicsContext shareContext,
                            int major, int minor,
                            OpenTK.Graphics.GraphicsContextFlags flags)
     : this(win)
 {
     lock (SDL.Sync)
     {
         SetGLAttributes(mode, shareContext, major, minor, flags);
         SdlContext = new ContextHandle(SDL.SDL_GL_CreateContext(Window.Handle));
     }
     if (SdlContext == ContextHandle.Zero)
     {
         var error = SDL.SDL_GetError();
         Debug.Print("SDL2 failed to create OpenGL context: {0}", error);
         throw new GraphicsContextException(error);
     }
     Handle = GraphicsContext.GetCurrentContext();
 }
コード例 #4
0
 public OpenTK.Graphics.IGraphicsContext CreateContext(int major, int minor, OpenTK.Graphics.GraphicsContextFlags flags)
 {
     return(new GraphicsContext(mode, window_info, major, minor, flags));
 }