/// <summary>Constructs a new GameWindow with the specified attributes.</summary> /// <param name="width">The width of the GameWindow in pixels.</param> /// <param name="height">The height of the GameWindow in pixels.</param> /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param> /// <param name="title">The title of the GameWindow.</param> /// <param name="options">GameWindow options regarding window appearance and behavior.</param> /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param> public GameWindow(int width, int height, GraphicsMode mode, string title, bool nullContext, GameWindowFlags options, DisplayDevice device) : base(width, height, title, options, mode, device) { try { glContext = nullContext ? new NullContext() : Factory.Default.CreateGLContext(mode, WindowInfo); glContext.MakeCurrent(WindowInfo); glContext.LoadAll(); VSync = true; } catch (Exception e) { Debug.Print(e.ToString()); base.Dispose(); throw; } }
public GL46SwapChain(SwapChainDescriptor swapChainDescriptor) { var options = new ToolkitOptions(); options.Backend = PlatformBackend.Default; Toolkit.Init(options); _windowInfo = Utilities.CreateWindowsWindowInfo(swapChainDescriptor.WindowHandle); var graphicsContextFlags = GraphicsContextFlags.ForwardCompatible; #if DEBUG graphicsContextFlags |= GraphicsContextFlags.Debug; #endif _nativeContext = new GraphicsContext(GraphicsMode.Default, _windowInfo, null, 4, 6, graphicsContextFlags); _nativeContext.LoadAll(); TurnOnDebugging(); _nativeContext.MakeCurrent(_windowInfo); _nativeContext.SwapInterval = swapChainDescriptor.VSync ? 1 : 0; OpenTK.Graphics.OpenGL4.GL.Enable(EnableCap.CullFace); OpenTK.Graphics.OpenGL4.GL.CullFace(CullFaceMode.Back); OpenTK.Graphics.OpenGL4.GL.FrontFace(FrontFaceDirection.Ccw); OpenTK.Graphics.OpenGL4.GL.Enable(EnableCap.DepthTest); OpenTK.Graphics.OpenGL4.GL.DepthFunc(DepthFunction.Less); }
public void Initialize() { // <Rant> // OpenTK has a great fuckup in its design here. It's absolutly nohm it possible to create // a render context for offscreen rendering without creating an OpenTK window. // before. // Passing Utilities.CreateDummyWindowInfo() or anything else will cause an invalid cast exception // Using Utilities.CreateWindowsWindowInfo(IntPtr.Zero) binds the code to windows only // Really great, why do i need to have a window in order to render to memory? -_- //</Rant> _window = new NativeWindow { Visible = false }; _context = new GraphicsContext(GraphicsMode.Default, _window.WindowInfo, 2, 0, GraphicsContextFlags.Default); _context.MakeCurrent(_window.WindowInfo); _context.LoadAll(); // create offscreen rendertarget with high precision _rtt = new RenderToTexture(1, 1, false, 4, typeof(float)); int precision; int range; GL.GetShaderPrecisionFormat(OpenTK.Graphics.OpenGL.ShaderType.FragmentShader, ShaderPrecisionType.HighFloat, out range, out precision); Debug.WriteLine("Precision: {0}, Range {1}", precision, range); // init SL# Bindings.OpenTK.SLSharp.Init(); }
public DecklinkWindow() { //Create the OpenGL window _win = new NativeWindow(PreviewWidth, PreviewHeight, "Decklink Test", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default); //Now create a Graphics context //and set it active for this thread _context = new GraphicsContext(GraphicsMode.Default, _win.WindowInfo); _context.MakeCurrent(_win.WindowInfo); _context.LoadAll(); //Create the frame buffer we will render to _fbo = new FrameBuffer(1280, 720); _texLogo = new Texture("la1tv.png"); _devices = new DecklinkDevices(); InitDecklink(0); _deckLinkOutput.SetScheduledFrameCompletionCallback(this); _totalFrames = 0; ResetFrame(); SetPreroll(); InitOpenGL(); Draw(); //thread blocking! }
/// <summary> /// Loads all OpenGL entry points. /// </summary> /// <exception cref="osuTK.Graphics.GraphicsContextException"> /// Occurs when this instance is not current on the calling thread. /// </exception> public void LoadAll() { if (GraphicsContext.CurrentContext != this) { throw new GraphicsContextException(); } implementation.LoadAll(); }
private void InitOpenGL() { var mode = new GraphicsMode(ColorFormat.Empty, 0, 0, 0, 0, 0, false); _context = new GraphicsContext(mode, _windowInfo, _settings.MajorVersion, _settings.MinorVersion, _settings.GraphicsContextFlags); _context.LoadAll(); _context.MakeCurrent(_windowInfo); var width = (int)RenderSize.Width; var height = (int)RenderSize.Height; _renderer = new GLWpfControlRenderer(width, height, _image, _settings.UseHardwareRender, _settings.PixelBufferObjectCount); }
void InitGL() { m_window = new NativeWindow(); m_context = new GraphicsContext(GraphicsMode.Default, m_window.WindowInfo); m_context.MakeCurrent(m_window.WindowInfo); m_context.LoadAll(); // Setup rendering texture m_renderTextureHandle = (uint)GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, m_renderTextureHandle); GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, Owner.VisualWidth, Owner.VisualHeight, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero); // Setup FBO m_fboHandle = (uint)GL.GenFramebuffer(); GL.BindFramebuffer(FramebufferTarget.Framebuffer, m_fboHandle); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, m_renderTextureHandle, 0); // Setup Cuda <-> OpenGL interop int length = Owner.VisualHeight * Owner.VisualWidth * sizeof(uint); //unbind - just in case this is causing us the invalid exception problems GL.BindBuffer(BufferTarget.PixelPackBuffer, 0); //create buffer GL.GenBuffers(1, out m_sharedBufferHandle); GL.BindBuffer(BufferTarget.PixelPackBuffer, m_sharedBufferHandle); GL.BufferData(BufferTarget.PixelPackBuffer, (IntPtr)(length), IntPtr.Zero, BufferUsageHint.StaticRead); // use data instead of IntPtr.Zero if needed GL.BindBuffer(BufferTarget.PixelPackBuffer, 0); try { m_renderResource = new CudaOpenGLBufferInteropResource(m_renderTextureHandle, CUGraphicsRegisterFlags.ReadOnly); // Read only by CUDA } catch (CudaException e) { MyLog.INFO.WriteLine( "{0}: CUDA-OpenGL interop error while itializing texture (using fallback): {1}", GetType().Name, e.Message); } // Clean up GL.BindTexture(TextureTarget.Texture2D, 0); FramebufferErrorCode err = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); }
public override void CreateContext() { Debug.Assert(Window != null, "Missing window, cannot create context."); if (Context != null) { MakeContextNotCurrent(); Context.Dispose(); } Context = new GraphicsContext(GraphicsMode.Default, Window.WindowInfo); Context.LoadAll(); Context.MakeCurrent(null); }
/// <summary>Constructs a new GameWindow with the specified attributes.</summary> /// <param name="width">The width of the GameWindow in pixels.</param> /// <param name="height">The height of the GameWindow in pixels.</param> /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param> /// <param name="title">The title of the GameWindow.</param> /// <param name="options">GameWindow options regarding window appearance and behavior.</param> /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param> public GameWindow(int width, int height, GraphicsMode mode, string title, bool nullContext, GameWindowFlags options, DisplayDevice device) : base(width, height, title, mode, device) { try { glContext = nullContext ? new NullContext() : Factory.Default.CreateGLContext(mode, WindowInfo); glContext.MakeCurrent(WindowInfo); glContext.LoadAll(); VSync = true; } catch (Exception e) { Debug.Print(e.ToString()); base.Dispose(); throw; } }
/// <summary> /// Constructs a new swap surface. /// </summary> /// <param name="window">Window to build a swap chain and drawing surface for.</param> /// <param name="resolution">Resolution of the rendering surface.</param> /// <param name="enableDeviceDebugLayer">Whether to use the debug layer for this window's graphics device.</param> public RenderSurface(IWindowInfo window, Int2 resolution, bool fullScreen = false, bool enableDeviceDebugLayer = false) { this.window = window; context = new GraphicsContext(new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 0, 4), window, 4, 6, GraphicsContextFlags.Default); context.LoadAll(); if (enableDeviceDebugLayer) { GL.Enable(EnableCap.DebugOutput); GL.DebugMessageCallback((source, type, id, severity, length, message, userParam) => { Console.Error.WriteLine($"{source}, {type}, {id}, {severity}, {System.Runtime.InteropServices.Marshal.PtrToStringAnsi(message)}"); if (type == DebugType.DebugTypeError) { throw new Exception(); } }, IntPtr.Zero); } Resolution = resolution; GL.Viewport(0, 0, Resolution.X, Resolution.Y); }
private void InitWindow() { var graphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 0, 0, 1); _tkWindow = new NativeWindow(_config.Window.SizeX, _config.Window.SizeY, "AutoCaption", GameWindowFlags.Default, graphicsMode, DisplayDevice.Default); _tkWindow.Closed += OnWindowClosed; _tkWindow.Resize += OnWindowResize; // TODO: Why does passing these sizes to the NativeWindow constructor result in the client size being larger? _tkWindow.ClientSize = new System.Drawing.Size(_config.Window.SizeX, _config.Window.SizeY); _tkContext = new GraphicsContext(graphicsMode, _tkWindow.WindowInfo, 3, 3, GraphicsContextFlags.ForwardCompatible) { ErrorChecking = true, SwapInterval = 1, }; _tkContext.LoadAll(); }
public void Reset() { if (_resetting) //Prevent a possible infinite loop { return; } _resetting = true; _window.Reset(); Dispose(); _winInfo = Utilities.CreateWindowsWindowInfo(_window.Handle); _context = new GraphicsContext(GraphicsMode.Default, WindowInfo); Capture(true); _context.LoadAll(); Update(); ResetOccured?.Invoke(this, EventArgs.Empty); _resetting = false; }
public Window(WindowSettings settings) { loadedFonts = new Dictionary <string, Font>(); setting = settings; window = new NativeWindow(setting.Width, setting.Height, setting.Title, GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default); gfxContext = new GraphicsContext(GraphicsMode.Default, window.WindowInfo, 3, 0, GraphicsContextFlags.Default); io = ImGui.GetIO(); control = new WindowControl(ref window, ref io); gfxContext.LoadAll(); gfxContext.MakeCurrent(window.WindowInfo); GL.ClearColor(Color.Black); loadedFonts.Add("default", io.FontAtlas.AddDefaultFont()); CreateDeviceObjects(); window.Visible = true; }
protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); if (!DesignMode) { DoubleBuffered = false; ResizeRedraw = true; ColorFormat colorBufferColorFormat = new ColorFormat(24); GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, 0, 0, 0, ColorFormat.Empty, 2, false); windowInfo = Utilities.CreateWindowsWindowInfo(Handle); graphicsContext = new GraphicsContext(graphicsMode, windowInfo, 1, 2, GraphicsContextFlags.Default); graphicsContext.MakeCurrent(windowInfo); graphicsContext.LoadAll(); GraphicsContextInitialized(); } }
public TKContext(Control window) { _window = window; _winInfo = Utilities.CreateWindowsWindowInfo(_window.Handle); _context = new GraphicsContext(GraphicsMode.Default, _winInfo); _context.MakeCurrent(WindowInfo); _context.LoadAll(); if (!_anyContextInitialized) { // Check for GLSL support string[] version = GL.GetString(StringName.Version).Split('.', ' '); _versionMax = int.Parse(version[0]); _versionMin = int.Parse(version[1]); //Need OpenGL 2.1 to use GLSL 120 _shadersSupported = !(_versionMax < 2 || _versionMax == 2 && _versionMin < 1); _anyContextInitialized = true; } BoundContexts.Add(this); }
private void OnLoaded(object sender, RoutedEventArgs args) { if (_context != null) { return; } if (_settings.ContextToUse == null) { var window = Window.GetWindow(this); var baseHandle = window is null ? IntPtr.Zero : new WindowInteropHelper(window).Handle; _hwnd = new HwndSource(0, 0, 0, 0, 0, "GLWpfControl", baseHandle); _windowInfo = Utilities.CreateWindowsWindowInfo(_hwnd.Handle); var mode = new GraphicsMode(ColorFormat.Empty, 0, 0, 0, 0, 0, false); _context = new GraphicsContext(mode, _windowInfo, _settings.MajorVersion, _settings.MinorVersion, _settings.GraphicsContextFlags); _context.LoadAll(); _context.MakeCurrent(_windowInfo); } else { _context = _settings.ContextToUse; } if (_renderer == null) { var width = (int)RenderSize.Width; var height = (int)RenderSize.Height; _renderer = new GLWpfControlRenderer(width, height, _image, _settings.UseHardwareRender, _settings.PixelBufferObjectCount); } _imageRectangle = new Rect(0, 0, RenderSize.Width, RenderSize.Height); _translateTransform = new TranslateTransform(0, RenderSize.Height); GL.Viewport(0, 0, (int)RenderSize.Width, (int)RenderSize.Height); Ready?.Invoke(); }
/// <summary> /// Initializes a new instance of the <see cref="osuTK.Graphics.GraphicsContext"/> class using /// an external context handle that was created by a third-party library. /// </summary> /// <param name="handle"> /// A valid, unique handle for an external OpenGL context, or <c>ContextHandle.Zero</c> to use the current context. /// It is an error to specify a handle that has been created through osuTK or that has been passed to osuTK before. /// </param> /// <param name="getAddress"> /// A <c>GetAddressDelegate</c> instance that accepts the name of an OpenGL function and returns /// a valid function pointer, or <c>IntPtr.Zero</c> if that function is not supported. This delegate should be /// implemented using the same toolkit that created the OpenGL context (i.e. if the context was created with /// SDL_GL_CreateContext(), then this delegate should use SDL_GL_GetProcAddress() to retrieve function /// pointers.) /// </param> /// <param name="getCurrent"> /// A <c>GetCurrentContextDelegate</c> instance that returns the handle of the current OpenGL context, /// or <c>IntPtr.Zero</c> if no context is current on the calling thread. This delegate should be implemented /// using the same toolkit that created the OpenGL context (i.e. if the context was created with /// SDL_GL_CreateContext(), then this delegate should use SDL_GL_GetCurrentContext() to retrieve /// the current context.) /// </param> public GraphicsContext(ContextHandle handle, GetAddressDelegate getAddress, GetCurrentContextDelegate getCurrent) { if (getAddress == null || getCurrent == null) { throw new ArgumentNullException(); } // Make sure osuTK has been initialized. // Fixes https://github.com/opentk/opentk/issues/52 Toolkit.Init(); lock (SyncRoot) { // Replace a zero-handle by the current context, if any if (handle == ContextHandle.Zero) { handle = getCurrent(); } // Make sure this handle corresponds to a valid, unique OpenGL context if (handle == ContextHandle.Zero) { throw new GraphicsContextMissingException(); } else if (available_contexts.ContainsKey(handle)) { throw new InvalidOperationException("Context handle has already been added"); } // We have a valid handle for an external OpenGL context, wrap it into a // DummyGLContext instance. implementation = new Platform.Dummy.DummyGLContext(handle, getAddress); GetCurrentContext = getCurrent ?? GetCurrentContext; AddContext(this); } implementation.LoadAll(); }
void StartUp(OpenTKApplication a_app) { #if DEBUG_INFO m_graphics = new GraphicsContext(GraphicsMode.Default, a_app.WindowInfo, 4, 5, GraphicsContextFlags.Debug); #else m_graphics = new GraphicsContext(GraphicsMode.Default, a_app.WindowInfo, 4, 5, GraphicsContextFlags.Default); #endif m_graphics.MakeCurrent(a_app.WindowInfo); m_graphics.LoadAll(); GL.ClearColor(Color.FromArgb(255, 25, 25, 25)); m_graphics.SwapInterval = 1; m_staticVAO = GL.GenVertexArray(); m_staticVBO = GL.GenBuffer(); m_staticIBO = GL.GenBuffer(); GL.BindVertexArray(m_staticVAO); GL.BindBuffer(BufferTarget.ArrayBuffer, m_staticVBO); GL.BindBuffer(BufferTarget.ElementArrayBuffer, m_staticIBO); GL.Enable(EnableCap.DepthTest); GL.CullFace(CullFaceMode.Back); GL.Enable(EnableCap.CullFace); m_time = new PipelineTime(); Shaders.InitShaders(m_pipeline); #if DEBUG_INFO Pipeline.GLError("Pipeline: Startup: "); #endif }
/// <summary> /// Initializes a new instance of the <see cref="OpenTK.Graphics.GraphicsContext"/> class using /// an external context handle that was created by a third-party library. /// </summary> /// <param name="handle"> /// A valid, unique handle for an external OpenGL context, or <c>ContextHandle.Zero</c> to use the current context. /// It is an error to specify a handle that has been created through OpenTK or that has been passed to OpenTK before. /// </param> /// <param name="getAddress"> /// A <c>GetAddressDelegate</c> instance that accepts the name of an OpenGL function and returns /// a valid function pointer, or <c>IntPtr.Zero</c> if that function is not supported. This delegate should be /// implemented using the same toolkit that created the OpenGL context (i.e. if the context was created with /// SDL_GL_CreateContext(), then this delegate should use SDL_GL_GetProcAddress() to retrieve function /// pointers.) /// </param> /// <param name="getCurrent"> /// A <c>GetCurrentContextDelegate</c> instance that returns the handle of the current OpenGL context, /// or <c>IntPtr.Zero</c> if no context is current on the calling thread. This delegate should be implemented /// using the same toolkit that created the OpenGL context (i.e. if the context was created with /// SDL_GL_CreateContext(), then this delegate should use SDL_GL_GetCurrentContext() to retrieve /// the current context.) /// </param> public GraphicsContext(ContextHandle handle, GetAddressDelegate getAddress, GetCurrentContextDelegate getCurrent) { if (getAddress == null || getCurrent == null) throw new ArgumentNullException(); // Make sure OpenTK has been initialized. // Fixes https://github.com/opentk/opentk/issues/52 Toolkit.Init(); lock (SyncRoot) { // Replace a zero-handle by the current context, if any if (handle == ContextHandle.Zero) { handle = getCurrent(); } // Make sure this handle corresponds to a valid, unique OpenGL context if (handle == ContextHandle.Zero) { throw new GraphicsContextMissingException(); } else if (available_contexts.ContainsKey(handle)) { throw new InvalidOperationException("Context handle has already been added"); } // We have a valid handle for an external OpenGL context, wrap it into a // DummyGLContext instance. implementation = new Platform.Dummy.DummyGLContext(handle, getAddress); GetCurrentContext = getCurrent ?? GetCurrentContext; AddContext(this); } implementation.LoadAll(); }
/// <summary> /// /// </summary> /// <see cref="http://www.opentk.com/doc/graphics/graphicscontext"/> public override void InitSynchronizedOnce() { if (!AlreadyInitialized) { AlreadyInitialized = true; AutoResetEvent CompletedEvent = new AutoResetEvent(false); var CThread = new Thread(() => { Thread.CurrentThread.CurrentCulture = new CultureInfo(PspConfig.ThreadCultureName); var UsedGraphicsMode = new GraphicsMode( color: new OpenTK.Graphics.ColorFormat(8, 8, 8, 8), depth: 16, stencil: 8, samples: 0, accum: new OpenTK.Graphics.ColorFormat(16, 16, 16, 16), //accum: new OpenTK.Graphics.ColorFormat(0, 0, 0, 0), buffers: 2, stereo: false ); var UsedGameWindowFlags = GameWindowFlags.Default; //Console.Error.WriteLine(UsedGraphicsMode); //Console.ReadKey(); #if USE_GL_CONTROL GLControl = new GLControl(UsedGraphicsMode, 3, 0, GraphicsContextFlags.Default); #else NativeWindow = new NativeWindow(512, 272, "PspGraphicEngine", UsedGameWindowFlags, UsedGraphicsMode, DisplayDevice.GetDisplay(DisplayIndex.Default)); #endif #if SHOW_WINDOW NativeWindow.Visible = true; #endif //Utilities.CreateWindowsWindowInfo(handle); GraphicsContext = new GraphicsContext(UsedGraphicsMode, WindowInfo); GraphicsContext.MakeCurrent(WindowInfo); { GraphicsContext.LoadAll(); Initialize(); } GraphicsContext.SwapInterval = 0; #if true //Console.WriteLine("## {0}", UsedGraphicsMode); Console.WriteLine("## UsedGraphicsMode: {0}", UsedGraphicsMode); Console.WriteLine("## GraphicsContext.GraphicsMode: {0}", GraphicsContext.GraphicsMode); Console.WriteLine("## OpenGL Context Version: {0}.{1}", GlGetInteger(GetPName.MajorVersion), GlGetInteger(GetPName.MinorVersion)); Console.WriteLine("## Depth Bits: {0}", GlGetInteger(GetPName.DepthBits)); Console.WriteLine("## Stencil Bits: {0}", GlGetInteger(GetPName.StencilBits)); Console.WriteLine("## Accum Bits: {0},{1},{2},{3}", GlGetInteger(GetPName.AccumRedBits), GlGetInteger(GetPName.AccumGreenBits), GlGetInteger(GetPName.AccumBlueBits), GlGetInteger(GetPName.AccumAlphaBits)); if (GlGetInteger(GetPName.StencilBits) <= 0) { ConsoleUtils.SaveRestoreConsoleState(() => { Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine("No stencil bits available!"); }); } /* GL.Enable(EnableCap.StencilTest); GL.StencilMask(0xFF); GL.ClearColor(new Color4(Color.FromArgb(0x11, 0x22, 0x33, 0x44))); GL.ClearStencil(0x7F); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit); var TestData = new uint[16 * 16]; TestData[0] = 0x12345678; GL.ReadPixels(0, 0, 16, 16, PixelFormat.Rgba, PixelType.UnsignedInt8888Reversed, TestData); Console.WriteLine(GL.GetError()); for (int n = 0; n < TestData.Length; n++) Console.Write("{0:X}", TestData[n]); */ #endif GraphicsContext.MakeCurrent(null); CompletedEvent.Set(); while (Running) { #if !USE_GL_CONTROL NativeWindow.ProcessEvents(); #endif Thread.Sleep(1); } StopEvent.Set(); }); CThread.Name = "GpuImplEventHandling"; CThread.IsBackground = true; CThread.Start(); CompletedEvent.WaitOne(); } }
/// <summary>Constructs a new GameWindow with the specified attributes.</summary> /// <param name="width">The width of the GameWindow in pixels.</param> /// <param name="height">The height of the GameWindow in pixels.</param> /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param> /// <param name="title">The title of the GameWindow.</param> /// <param name="options">GameWindow options regarding window appearance and behavior.</param> /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param> public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device) : base(width, height, title, options, mode == null ? GraphicsMode.Default : mode, device == null ? DisplayDevice.Default : device) { try { glContext = Factory.Default.CreateGLContext(mode == null ? GraphicsMode.Default : mode, WindowInfo); glContext.MakeCurrent(WindowInfo); glContext.LoadAll(); VSync = true; //glWindow.WindowInfoChanged += delegate(object sender, EventArgs e) { OnWindowInfoChangedInternal(e); }; } catch (Exception e) { Debug.Print(e.ToString()); base.Dispose(); throw; } }
public void LoadAll() { dummyContext.LoadAll(); }
internal override IntPtr OpenWindow(IntVector2 size, string title) { // init check for multi-window purposes if (!_isSdlInitialized) { if (SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING) < 0) { throw new GlaivesException($"Failed to initialize SDL: {SDL.SDL_GetError()}"); } _isSdlInitialized = true; } SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE); SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1); SDL.SDL_WindowFlags windowFlags = windowFlags = SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN | SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE; NativeWindowHandle = SDL.SDL_CreateWindow(title, SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, size.X, size.Y, windowFlags); if (NativeWindowHandle == IntPtr.Zero) { throw new GlaivesException($"Failed to open SDL window: {SDL.SDL_GetError()}"); } _isOpen = true; _windowInfo = OpenTK.Platform.Utilities.CreateSdl2WindowInfo(NativeWindowHandle); GraphicsMode graphicsMode = GraphicsMode.Default; GlContext = new GraphicsContext(graphicsMode, _windowInfo) { SwapInterval = 1 }; MakeContextCurrent(); GlContext.LoadAll(); string glVersion = GL.GetString(StringName.Version); int currentMajor = int.Parse(glVersion.Split('.')[0][0].ToString()); int currentMinor = int.Parse(glVersion.Split('.')[1][0].ToString()); if (currentMajor < 3) { throw new NotSupportedException("Your system does not support OpenGL 3.x"); } else if (currentMajor == 3) { if (currentMinor < 2) { throw new NotSupportedException("Your system does not support OpenGL 3.2"); } } return(NativeWindowHandle); }