diff --git a/Source/Examples/Tests/S04_Input_Logger.cs b/Source/Examples/Tests/S04_Input_Logger.cs index d5b203bc..6290352f 100644 --- a/Source/Examples/Tests/S04_Input_Logger.cs +++ b/Source/Examples/Tests/S04_Input_Logger.cs @@ -24,7 +24,6 @@ namespace Examples.Tests { InputDriver driver; Dictionary keyboardListBoxes = new Dictionary(4); - bool stop_polling; public S04_Input_Logger() { diff --git a/Source/Examples/Tutorial/T01_Simple_Window.cs b/Source/Examples/Tutorial/T01_Simple_Window.cs index 762296c8..a06990c0 100644 --- a/Source/Examples/Tutorial/T01_Simple_Window.cs +++ b/Source/Examples/Tutorial/T01_Simple_Window.cs @@ -22,10 +22,27 @@ namespace Examples.Tutorial this.CreateWindow(new DisplayMode(800, 600)); } + /// + /// Override the OnResize method to respond to window resize events. + /// Do not forget to call base.OnResize() so that event listeners + /// will be notified of window resize events! + /// + /// + protected override void OnResize(OpenTK.Platform.ResizeEventArgs e) + { + GL.Viewport(0, 0, e.Width, e.Height); + + GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION); + GL.LoadIdentity(); + GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0); + + base.OnResize(e); + } + /// /// Override the OnRenderFrame method to add your drawing code. /// Do not forget to call base.OnRenderFrame() so that event listeners - /// will be notified every time a frame is drawn! + /// will be notified of frame rendering events! /// /// Not used. public override void OnRenderFrame(EventArgs e) diff --git a/Source/OpenTK/OpenGL/GLHelper.cs b/Source/OpenTK/OpenGL/GLHelper.cs index 9d133ca1..71da4bfe 100644 --- a/Source/OpenTK/OpenGL/GLHelper.cs +++ b/Source/OpenTK/OpenGL/GLHelper.cs @@ -360,31 +360,46 @@ namespace OpenTK.OpenGL internal class GetProcAddressWindows : IGetProcAddress { + [System.Runtime.InteropServices.DllImport(Library, EntryPoint = "wglGetProcAddress", ExactSpelling = true)] + private static extern IntPtr wglGetProcAddress(String lpszProc); + public IntPtr GetProcAddress(string function) { - return OpenTK.Platform.Windows.Wgl.Imports.GetProcAddress(function); + return wglGetProcAddress(function); } } internal class GetProcAddressX11 : IGetProcAddress { + [DllImport(Library, EntryPoint = "glXGetProcAddress")] + private static extern IntPtr glxGetProcAddress([MarshalAs(UnmanagedType.LPTStr)] string procName); + public IntPtr GetProcAddress(string function) { - return X11.Glx.GetProcAddress(function); + return glxGetProcAddress(function); } } internal class GetProcAddressOSX : IGetProcAddress { + private const string Library = "libdl.dylib"; + + [DllImport(Library, EntryPoint = "NSIsSymbolNameDefined")] + private static extern bool NSIsSymbolNameDefined(string s); + [DllImport(Library, EntryPoint = "NSLookupAndBindSymbol")] + private static extern IntPtr NSLookupAndBindSymbol(string s); + [DllImport(Library, EntryPoint = "NSAddressOfSymbol")] + private static extern IntPtr NSAddressOfSymbol(IntPtr symbol); + public IntPtr GetProcAddress(string function) { string fname = "_" + function; - if (!OSX.Functions.NSIsSymbolNameDefined(fname)) + if (!NSIsSymbolNameDefined(fname)) return IntPtr.Zero; - IntPtr symbol = OSX.Functions.NSLookupAndBindSymbol(fname); + IntPtr symbol = NSLookupAndBindSymbol(fname); if (symbol != IntPtr.Zero) - symbol = OSX.Functions.NSAddressOfSymbol(symbol); + symbol = NSAddressOfSymbol(symbol); return symbol; } @@ -439,7 +454,7 @@ namespace OpenTK.OpenGL #endregion - #region private static Delegate GetExtensionDelegate(string name, Type signature) + #region internal static Delegate GetExtensionDelegate(string name, Type signature) /// /// Creates a System.Delegate that can be used to call a dynamically exported OpenGL function. @@ -450,7 +465,7 @@ namespace OpenTK.OpenGL /// A System.Delegate that can be used to call this OpenGL function or null /// if the function is not available in the current OpenGL context. /// - private static Delegate GetExtensionDelegate(string name, Type signature) + internal static Delegate GetExtensionDelegate(string name, Type signature) { IntPtr address = GetAddress(name); diff --git a/Source/OpenTK/OpenGL/GluHelper.cs b/Source/OpenTK/OpenGL/GluHelper.cs index 16f99bba..b01dadef 100644 --- a/Source/OpenTK/OpenGL/GluHelper.cs +++ b/Source/OpenTK/OpenGL/GluHelper.cs @@ -47,7 +47,7 @@ namespace OpenTK.OpenGL { MethodInfo m = importsClass.GetMethod(name.Substring(3), BindingFlags.Static | BindingFlags.NonPublic); return - Utilities.GetExtensionDelegate(name, signature) ?? + GL.GetExtensionDelegate(name, signature) ?? (m != null ? Delegate.CreateDelegate(signature, m) : null); } diff --git a/Source/OpenTK/Platform/Windows/WglHelper.cs b/Source/OpenTK/Platform/Windows/WglHelper.cs index 7060629c..eed612e4 100644 --- a/Source/OpenTK/Platform/Windows/WglHelper.cs +++ b/Source/OpenTK/Platform/Windows/WglHelper.cs @@ -62,12 +62,12 @@ namespace OpenTK.Platform.Windows if (importsClass.GetMethod(realName, BindingFlags.NonPublic | BindingFlags.Static) != null) { - d = Utilities.GetExtensionDelegate(name, signature) ?? + d = GetExtensionDelegate(name, signature) ?? Delegate.CreateDelegate(signature, typeof(Imports), realName); } else { - d = Utilities.GetExtensionDelegate(name, signature); + d = GetExtensionDelegate(name, signature); } return d; @@ -75,6 +75,35 @@ namespace OpenTK.Platform.Windows #endregion + #region private static Delegate GetExtensionDelegate(string name, Type signature) + + /// + /// Creates a System.Delegate that can be used to call a dynamically exported OpenGL function. + /// + /// The name of the OpenGL function (eg. "glNewList") + /// The signature of the OpenGL function. + /// + /// A System.Delegate that can be used to call this OpenGL function or null + /// if the function is not available in the current OpenGL context. + /// + private static Delegate GetExtensionDelegate(string name, Type signature) + { + IntPtr address = Imports.GetProcAddress(name); + + if (address == IntPtr.Zero || + address == new IntPtr(1) || // Workaround for buggy nvidia drivers which return + address == new IntPtr(2)) // 1 or 2 instead of IntPtr.Zero for some extensions. + { + return null; + } + else + { + return Marshal.GetDelegateForFunctionPointer(address, signature); + } + } + + #endregion + /// /// Loads all Wgl entry points, core and extensions. ///