public static void Init(OpenTK.Graphics.IGraphicsContext context, OpenTK.Platform.IWindowInfo wininf) { Graphics.context = context; Graphics.windowInfo = wininf; init = true; }
public OpenTKGLContext(OpenTK.Platform.IWindowInfo windowInfo) { // setup created glcontrol / gtk control this.windowInfo = windowInfo; this.graphicsContext = new GraphicsContext(GraphicsMode.Default, this.windowInfo); Initialized = true; }
public OpenTKGLContext( OpenTK.Platform.IWindowInfo windowInfo ) { // setup created glcontrol / gtk control this.windowInfo = windowInfo; this.graphicsContext = new GraphicsContext( GraphicsMode.Default, this.windowInfo ); Initialized = true; }
public static void Initialize(OpenTK.Platform.IWindowInfo windowInfo, int major, int minor, GraphicsContextFlags contextFlags) { //GraphicsContextFlags flags = GraphicsContextFlags. ThreadingHelper.context = new GraphicsContext(GraphicsMode.Default, windowInfo, major, minor, contextFlags); ThreadingHelper.context.MakeCurrent(windowInfo); (ThreadingHelper.context as IGraphicsContextInternal).LoadAll(); ThreadingHelper.windowInfo = windowInfo; }
public static void CreateDummyContext() { IntPtr hWnd; control = new Control(); hWnd = control.Handle; windowInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(hWnd); context = new GraphicsContext(GraphicsMode.Default, windowInfo); context.MakeCurrent(windowInfo); context.LoadAll(); }
private void InitializeOgl(Control WinControl) { if (RenderingContext != null) { if (!RenderingContext.IsDisposed) { DisposeOglObjects(); } } /* private OpenTK.Platform.IWindowInfo*/ WindowsInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(WinControl.Handle); OpenTK.Graphics.GraphicsMode GraphicMode = new OpenTK.Graphics.GraphicsMode(new OpenTK.Graphics.ColorFormat(PfdColorBits), PfdDepthBits, PfdStencilBits, PfdAuxBits, new OpenTK.Graphics.ColorFormat(PfdAccumBits), PfdBuffers, PfdStereo); OpenTK.Graphics.GraphicsMode GraphicMode2 = OpenTK.Graphics.GraphicsMode.Default; RenderingContext = new OpenTK.Graphics.GraphicsContext(GraphicMode2, WindowsInfo); RenderingContext.LoadAll(); FBO.LoadMethods(); RenderingContext.SwapInterval = 1; GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.CullFace(CullFaceMode.Back); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.ShadeModel(ShadingModel.Smooth); GL.Enable(EnableCap.Normalize); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Lighting); ShadowMapSampler = GL.GenSampler(); // Texture.Sampler= GL.GenSampler(); ActivateShader(); Lights[0].Position = new xyzwf(3, 4, 10, 0); FieldOfView = 0; Selector.PickingShader = PickingShader; //System.Diagnostics.ConsoleTraceListener myWriter = new //System.Diagnostics.ConsoleTraceListener(); //System.Diagnostics.Debug.Listeners.Clear(); //System.Diagnostics.Debug.Listeners.Add(myWriter); CheckError(); ClockWise = true; Culling = false; SwapBuffers(); CheckError(); }
protected override void OnHandleDestroyed(EventArgs e) { base.OnHandleDestroyed(e); if (graphicsContext != null) { graphicsContext.Dispose(); graphicsContext = null; } if (windowInfo != null) { windowInfo.Dispose(); windowInfo = null; } }
public unsafe override void EndFrame(Game game) { // TODO: PRESENT OpenTK.Platform.IWindowInfo info = game.window.WindowInfo; using (Graphics g = Graphics.FromHwnd(info.WinHandle)) { fixed(int *colPtr = colBuffer) { using (Bitmap bmp = new Bitmap(width, height, width * 4, PixelFormat.Format32bppRgb, (IntPtr)colPtr)) { g.DrawImage(bmp, 0, 0, width, height); } } } }
protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); windowInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(Handle); graphicsContext = new OpenTK.Graphics.GraphicsContext(graphicsMode, windowInfo, major, minor, graphicsContextFlags); graphicsContext.MakeCurrent(windowInfo); graphicsContext.LoadAll(); graphicsContext.SwapInterval = VSync ? 1 : 0; if (platformRenderContext == null) { platformRenderContext = new Graphics.Platform.OpenGL.PlatformRenderContext(); PlatformRenderer.Initialize(platformRenderContext); } graphicsContext.MakeCurrent(null); }
static void Main(string[] args) { ContextSettings contextSettings = new ContextSettings(24, 0, 0); var window = new RenderWindow(new SFML.Window.VideoMode(640, 480), "ImGui + SFML + .Net = <3", Styles.Default, contextSettings); OpenTK.Graphics.GraphicsMode graphicsMode = new OpenTK.Graphics.GraphicsMode(32, (int)contextSettings.DepthBits, (int)contextSettings.StencilBits, (int)contextSettings.AntialiasingLevel); OpenTK.Platform.IWindowInfo windowInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(window.SystemHandle); OpenTK.Graphics.GraphicsContext context = new OpenTK.Graphics.GraphicsContext(graphicsMode, windowInfo); context.MakeCurrent(windowInfo); context.LoadAll(); window.SetFramerateLimit(60); ImGuiSfml.Init(window); window.Closed += (s, e) => window.Close(); CircleShape shape = new CircleShape(100); shape.FillColor = Color.Green; Clock deltaClock = new Clock(); while (window.IsOpen) { window.DispatchEvents(); ImGuiSfml.Update(window, deltaClock.Restart()); ImGui.ShowDemoWindow(); //ImGui.ShowTestWindow(); /* * ImGui.Begin("Hello, world!"); * ImGui.Button("Look at this pretty button"); * ImGui.End(); */ window.Clear(); window.Draw(shape); ImGuiSfml.Render(window); window.Display(); } }
private void ConstructContext() { OpenTK.Graphics.GraphicsContextFlags flags = OpenTK.Graphics.GraphicsContextFlags.Default; int major = 1; int minor = 0; OpenTK.Platform.IWindowInfo windowInfo = Window.window.WindowInfo; if (System.Environment.OSVersion.Platform == PlatformID.Win32NT || System.Environment.OSVersion.Platform == PlatformID.Win32S || System.Environment.OSVersion.Platform == PlatformID.Win32Windows || System.Environment.OSVersion.Platform == PlatformID.WinCE) { major = 4; minor = 4; } if (this.Context == null || this.Context.IsDisposed) { OpenTK.Graphics.ColorFormat colorFormat = new OpenTK.Graphics.ColorFormat(8, 8, 8, 8); int depth = 24;//TODO: wth? int stencil = 8; int samples = 4; OpenTK.Graphics.GraphicsMode mode = new OpenTK.Graphics.GraphicsMode(colorFormat, depth, stencil, samples); try { this.Context = new OpenTK.Graphics.GraphicsContext(mode, windowInfo, major, minor, flags); //this.Context = Window.Context; } catch (Exception ex) { mode = OpenTK.Graphics.GraphicsMode.Default; major = 1; minor = 0; flags = OpenTK.Graphics.GraphicsContextFlags.Default; this.Context = new OpenTK.Graphics.GraphicsContext(mode, windowInfo, major, minor, flags); } } this.Context.MakeCurrent(windowInfo); (this.Context as OpenTK.Graphics.IGraphicsContextInternal).LoadAll(); ThreadingHelper.Initialize(windowInfo, major, minor, contextFlags); this.Context.MakeCurrent(windowInfo); }
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); }
public static IntPtr GetWindowDisplay(OpenTK.Platform.IWindowInfo windowInfo) { var x11WindowInfoType = typeof(OpenTK.NativeWindow).Assembly.GetType("OpenTK.Platform.X11.X11WindowInfo"); return((IntPtr)x11WindowInfoType.GetField("display", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(windowInfo)); }
public static void Initialize(OpenTK.Platform.IWindowInfo windowInfo, int major, int minor, GraphicsContextFlags contextFlags) { //GraphicsContextFlags flags = GraphicsContextFlags. ThreadingHelper.context = new GraphicsContext(GraphicsMode.Default, windowInfo, major, minor, contextFlags); ThreadingHelper.windowInfo = windowInfo; }
private void PlatformSetup() { #if WINDOWS || LINUX || ANGLE GraphicsMode mode = GraphicsMode.Default; //var wnd = (Game.Instance.Window as OpenTKGameWindow).Window.WindowInfo; // JA - Windows Handle fix OpenTK.Platform.IWindowInfo wnd = null; if (Game.Instance != null) { wnd = (Game.Instance.Window as OpenTKGameWindow).Window.WindowInfo; } else if (windowsHandleSet) { wnd = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(windowsHandle); } #if GLES // Create an OpenGL ES 2.0 context var flags = GraphicsContextFlags.Embedded; int major = 2; int minor = 0; #else // Create an OpenGL compatibility context var flags = GraphicsContextFlags.Default; int major = 1; int minor = 0; #endif if (Context == null || Context.IsDisposed) { // JA - Windows Handle fix if (Game.Instance != null) { var color = PresentationParameters.BackBufferFormat.GetColorFormat(); var depth = PresentationParameters.DepthStencilFormat == DepthFormat.None ? 0 : PresentationParameters.DepthStencilFormat == DepthFormat.Depth16 ? 16 : 24; var stencil = PresentationParameters.DepthStencilFormat == DepthFormat.Depth24Stencil8 ? 8 : 0; var samples = 0; if (Game.Instance.graphicsDeviceManager.PreferMultiSampling) { // Use a default of 4x samples if PreferMultiSampling is enabled // without explicitly setting the desired MultiSampleCount. if (PresentationParameters.MultiSampleCount == 0) { PresentationParameters.MultiSampleCount = 4; } samples = PresentationParameters.MultiSampleCount; } } try { Context = new GraphicsContext(mode, wnd, major, minor, flags); } catch (Exception e) { Game.Instance.Log("Failed to create OpenGL context, retrying. Error: " + e.ToString()); major = 1; minor = 0; flags = GraphicsContextFlags.Default; Context = new GraphicsContext(mode, wnd, major, minor, flags); } } Context.MakeCurrent(wnd); (Context as IGraphicsContextInternal).LoadAll(); Context.SwapInterval = PresentationParameters.PresentationInterval.GetSwapInterval(); // Provide the graphics context for background loading // Note: this context should use the same GraphicsMode, // major, minor version and flags parameters as the main // context. Otherwise, context sharing will very likely fail. if (Threading.BackgroundContext == null) { Threading.BackgroundContext = new GraphicsContext(mode, wnd, major, minor, flags); Threading.WindowInfo = wnd; Threading.BackgroundContext.MakeCurrent(null); } Context.MakeCurrent(wnd); #endif MaxTextureSlots = 16; GL.GetInteger(GetPName.MaxTextureImageUnits, out MaxTextureSlots); GraphicsExtensions.CheckGLError(); GL.GetInteger(GetPName.MaxVertexAttribs, out MaxVertexAttributes); GraphicsExtensions.CheckGLError(); GL.GetInteger(GetPName.MaxTextureSize, out _maxTextureSize); GraphicsExtensions.CheckGLError(); #if !GLES // Initialize draw buffer attachment array int maxDrawBuffers; GL.GetInteger(GetPName.MaxDrawBuffers, out maxDrawBuffers); _drawBuffers = new DrawBuffersEnum[maxDrawBuffers]; for (int i = 0; i < maxDrawBuffers; i++) { _drawBuffers[i] = (DrawBuffersEnum)(FramebufferAttachment.ColorAttachment0Ext + i); } #endif _extensions = GetGLExtensions(); }