From 79133f4812075697702fed5f9b31df1bb7591a8c Mon Sep 17 00:00:00 2001 From: emmaus Date: Thu, 10 Sep 2020 22:23:27 +0000 Subject: [PATCH] fix windows --- GLWidget/GLWidget.cs | 16 ++++++++++++---- GLWidget/GTKBindingHelper.cs | 17 ++++++++++++++--- GLWidget/OpenTK/Platform/Windows/WglHelper.cs | 2 +- .../OpenTK/Platform/Windows/WinGLContext.cs | 4 +++- GLWidgetTestGTK3/GLWidgetTestGTK3.csproj | 2 +- GLWidgetTestGTK3/MainWindow.cs | 5 ++++- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/GLWidget/GLWidget.cs b/GLWidget/GLWidget.cs index 8ca3319..eb88efa 100644 --- a/GLWidget/GLWidget.cs +++ b/GLWidget/GLWidget.cs @@ -155,6 +155,7 @@ namespace OpenTK public void ClearCurrent() { + Gdk.GLContext.ClearCurrent(); GraphicsContext.MakeCurrent(null); } @@ -169,7 +170,7 @@ namespace OpenTK { try { - GraphicsContext.MakeCurrent(WindowInfo); + MakeCurrent(); } catch (Exception ex) { @@ -259,7 +260,7 @@ namespace OpenTK if (!_initialized) Initialize(); else if (!IsRenderHandler) - GraphicsContext.MakeCurrent(WindowInfo); + MakeCurrent(); return true; } @@ -277,6 +278,8 @@ namespace OpenTK private void Initialize() { + Toolkit.Init(); + _initialized = true; Gdk.GLContext.ClearCurrent(); @@ -302,7 +305,7 @@ namespace OpenTK buffers--; } - GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo); + GraphicsMode graphicsMode = GraphicsMode.Default;//new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo); this.Window.EnsureNative(); @@ -322,7 +325,7 @@ namespace OpenTK // GraphicsContext GraphicsContext = new GraphicsContext(graphicsMode, WindowInfo, GLVersionMajor, GLVersionMinor, GraphicsContextFlags); - GraphicsContext.MakeCurrent(WindowInfo); + MakeCurrent(); if (OpenTK.Graphics.GraphicsContext.ShareContexts) { @@ -345,6 +348,11 @@ namespace OpenTK var swap = GraphicsContext.SwapInterval; + GTKBindingHelper.InitializeGlBindings(); + + ClearCurrent(); + MakeCurrent(); + OnInitialized(); } diff --git a/GLWidget/GTKBindingHelper.cs b/GLWidget/GTKBindingHelper.cs index a07b450..74c149c 100644 --- a/GLWidget/GTKBindingHelper.cs +++ b/GLWidget/GTKBindingHelper.cs @@ -47,12 +47,23 @@ namespace OpenTK { if (CurrentPlatform == OSPlatform.Windows) { - IntPtr library = OpenTK.Platform.Windows.Functions.LoadLibrary(WglLibrary); - return OpenTK.Platform.Windows.Functions.GetProcAddress(library, procName); + var ptr = OpenTK.Platform.Windows.Wgl.GetAddress(procName); + + /* var addr = GetProcAddressWgl(procName); + if (addr == null || addr == IntPtr.Zero) + { + var library = UnsafeNativeMethods.LoadLibrary(WglLibrary); + + addr = UnsafeNativeMethods.GetProcAddress(library, procName); + } + + return addr;*/ + + return ptr; } else if (CurrentPlatform == OSPlatform.Linux) { - return OpenTK.Platform.X11.Glx.GetProcAddress(procName); + return GetProcAddressGlx(procName); } else if(CurrentPlatform == OSPlatform.OSX) { diff --git a/GLWidget/OpenTK/Platform/Windows/WglHelper.cs b/GLWidget/OpenTK/Platform/Windows/WglHelper.cs index 630fb49..93d1715 100644 --- a/GLWidget/OpenTK/Platform/Windows/WglHelper.cs +++ b/GLWidget/OpenTK/Platform/Windows/WglHelper.cs @@ -15,7 +15,7 @@ namespace OpenTK.Platform.Windows private static IntPtr[] EntryPoints; private static string[] EntryPointNames; - internal const string Library = "OPENGL32.DLL"; + internal const string Library = "opengl32.dll"; private readonly static Dictionary extensions = new Dictionary(); diff --git a/GLWidget/OpenTK/Platform/Windows/WinGLContext.cs b/GLWidget/OpenTK/Platform/Windows/WinGLContext.cs index 1661cd2..f04af2d 100644 --- a/GLWidget/OpenTK/Platform/Windows/WinGLContext.cs +++ b/GLWidget/OpenTK/Platform/Windows/WinGLContext.cs @@ -396,7 +396,9 @@ namespace OpenTK.Platform.Windows Debug.WriteLine(mode.Index.ToString()); - if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index.Value, ref pfd)) + var index = Functions.ChoosePixelFormat(window.DeviceContext, ref pfd); + + if (!Functions.SetPixelFormat(window.DeviceContext, index, ref pfd)) { throw new GraphicsContextException(String.Format( "Requested GraphicsMode not available. SetPixelFormat error: {0}", diff --git a/GLWidgetTestGTK3/GLWidgetTestGTK3.csproj b/GLWidgetTestGTK3/GLWidgetTestGTK3.csproj index 8fe5f05..591a7a3 100644 --- a/GLWidgetTestGTK3/GLWidgetTestGTK3.csproj +++ b/GLWidgetTestGTK3/GLWidgetTestGTK3.csproj @@ -12,7 +12,7 @@ 1.1 - x64 + AnyCPU diff --git a/GLWidgetTestGTK3/MainWindow.cs b/GLWidgetTestGTK3/MainWindow.cs index 5a6369d..09e54a1 100644 --- a/GLWidgetTestGTK3/MainWindow.cs +++ b/GLWidgetTestGTK3/MainWindow.cs @@ -143,7 +143,8 @@ namespace GLWidgetTestGTK3 Samples = 4, GLVersionMajor = 3, GLVersionMinor = 3, - GraphicsContextFlags = GraphicsContextFlags.Default + GraphicsContextFlags = GraphicsContextFlags.ForwardCompatible | GraphicsContextFlags.Debug, + IsRenderHandler = true }; this.MainGLWidget.Events |= @@ -351,6 +352,8 @@ namespace GLWidgetTestGTK3 GLInit = true; //GLib.Idle.Add(OnIdleProcessMain); + MainGLWidget.ClearCurrent(); + System.Threading.Thread thread = new System.Threading.Thread(Start); thread.Start(); }