diff --git a/Source/Bind/GL2/SpecReader.cs b/Source/Bind/GL2/SpecReader.cs index f6631d02..b25ffeca 100644 --- a/Source/Bind/GL2/SpecReader.cs +++ b/Source/Bind/GL2/SpecReader.cs @@ -100,7 +100,7 @@ namespace Bind.GL2 // complete_enum contains all opengl enumerants. Bind.Structures.Enum complete_enum = new Bind.Structures.Enum(); - complete_enum.Name = "GLenum"; + complete_enum.Name = Settings.CompleteEnumName; Trace.WriteLine(String.Format("Reading opengl enumerant specs")); Trace.Indent(); diff --git a/Source/Bind/Properties/AssemblyInfo.cs b/Source/Bind/Properties/AssemblyInfo.cs index 301a29cf..d76d2917 100644 --- a/Source/Bind/Properties/AssemblyInfo.cs +++ b/Source/Bind/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("0.9.7.1")] -[assembly: AssemblyFileVersion("0.9.7.1")] +[assembly: AssemblyVersion("0.9.7.2")] +[assembly: AssemblyFileVersion("0.9.7.2")] diff --git a/Source/Bind/Settings.cs b/Source/Bind/Settings.cs index 80ec19d1..df8f6426 100644 --- a/Source/Bind/Settings.cs +++ b/Source/Bind/Settings.cs @@ -29,6 +29,11 @@ namespace Bind public static string GluClass = "Glu"; public static Legacy Compatibility = Legacy.None; + /// + /// The name of the C# enum which holds every single OpenGL enum (for compatibility purposes). + /// + public static string CompleteEnumName = "All"; + public enum Legacy { None, diff --git a/Source/Bind/Structures/Delegate.cs b/Source/Bind/Structures/Delegate.cs index 8937a4c6..676b7d78 100644 --- a/Source/Bind/Structures/Delegate.cs +++ b/Source/Bind/Structures/Delegate.cs @@ -810,7 +810,10 @@ namespace Bind.Structures if (ReturnType.CurrentType.Contains("GLenum")) { if (Settings.Compatibility == Settings.Legacy.None) - ReturnType.CurrentType = ReturnType.CurrentType.Insert(0, Settings.GLEnumsClass + "."); + ReturnType.CurrentType = + String.Format("{0}.{1}", + Settings.GLEnumsClass, + Settings.CompleteEnumName); else ReturnType.CurrentType = "int"; } diff --git a/Source/Bind/Structures/Parameter.cs b/Source/Bind/Structures/Parameter.cs index ee7da5cc..9870cf8b 100644 --- a/Source/Bind/Structures/Parameter.cs +++ b/Source/Bind/Structures/Parameter.cs @@ -245,7 +245,7 @@ namespace Bind.Structures } else { - p.CurrentType = String.Format("{0}.GLenum", Settings.GLEnumsClass); + p.CurrentType = String.Format("{0}.{1}", Settings.GLEnumsClass, Settings.CompleteEnumName); } } else diff --git a/Source/Examples/ExampleLauncher.cs b/Source/Examples/ExampleLauncher.cs index 01aaa3c1..1bef7aba 100644 --- a/Source/Examples/ExampleLauncher.cs +++ b/Source/Examples/ExampleLauncher.cs @@ -9,6 +9,9 @@ using System.Reflection; using System.Threading; using OpenTK; using System.Diagnostics; +using System.Security; +using System.Security.Permissions; +using System.Security.Policy; namespace Examples { @@ -83,31 +86,27 @@ namespace Examples void Launch(object example) { + Type ex = example as Type; + (ex.GetConstructor(Type.EmptyTypes).Invoke(null) as IExample).Launch(); + //(example as Type).InvokeMember("Launch", BindingFlags.InvokeMethod, null, example, null); + /* + AppDomain app = AppDomain.CreateDomain((example as Type).Name); + + Type exType = example as Type; try { - (example as Type).InvokeMember("Launch", BindingFlags.InvokeMethod, null, null, null); + IExample ex = app.CreateInstanceAndUnwrap( + exType.Assembly.GetName().Name, + "Examples.Tests.Shim") as IExample; + ex.Launch(); + //ex.InvokeMember("Launch", BindingFlags.InvokeMethod, null, null, null); + // } - catch (Exception expt) + finally { - System.Diagnostics.Debug.WriteLine( - String.Format( - "Exception: {3}{0}Stacktrace:{0}{1}{0}{0}Inner exception:{0}{2}", - System.Environment.NewLine, - expt.StackTrace, - expt.InnerException, - expt.Message - ) - ); - MessageBox.Show( - String.Format( - "Stacktrace:{0}{1}{0}{0}Inner exception:{0}{2}", - System.Environment.NewLine, - expt.StackTrace, - expt.InnerException - ), - expt.Message - ); + AppDomain.Unload(app); } + */ } public void ExampleLauncher_Load(object sender, EventArgs e) diff --git a/Source/Examples/IExample.cs b/Source/Examples/IExample.cs index 9f148cfb..c409129a 100644 --- a/Source/Examples/IExample.cs +++ b/Source/Examples/IExample.cs @@ -10,5 +10,6 @@ namespace Examples /// interface IExample { + void Launch(); } } diff --git a/Source/Examples/Properties/AssemblyInfo.cs b/Source/Examples/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..45b25efb --- /dev/null +++ b/Source/Examples/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OpenTK Examples")] +[assembly: AssemblyDescription("Examples showcasing OpenTK and OpenGL")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OpenTK")] +[assembly: AssemblyCopyright("Copyright © 2006-2007 Stefanos Apostolopoulos")] +[assembly: AssemblyTrademark("OpenTK")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f236c767-678f-4c20-9282-d051a3c39657")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("0.3.9.0")] +[assembly: AssemblyFileVersion("0.3.9.0")] diff --git a/Source/Examples/T10_GLSL_Cube.cs b/Source/Examples/T10_GLSL_Cube.cs new file mode 100644 index 00000000..b0cd65a0 --- /dev/null +++ b/Source/Examples/T10_GLSL_Cube.cs @@ -0,0 +1,228 @@ +#region --- License --- +/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos + * See license.txt for license info + */ +#endregion + +#region --- Using Directives --- + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using System.Threading; + +using OpenTK.OpenGL; +using Enums = OpenTK.OpenGL.GL.Enums; +using OpenTK; +using OpenTK.Input; + +#endregion --- Using Directives --- + +namespace Examples.Tutorial +{ + public class T10_GLSL_Cube : GameWindow, IExample + { + #region --- Fields --- + + #region Shaders + + string[] vertex_shader_source = + { + "void main() {", + "gl_FrontColor = gl_Color;", + "gl_Position = ftransform();", + "}", + }; + + string[] fragment_shader_source = + { + "void main() { gl_FragColor = gl_Color; }\0" + }; + + #endregion + + static float angle; + + #endregion + + #region --- Constructors --- + + public T10_GLSL_Cube() + { + Context.MakeCurrent(); + + //Text = + // GL.GetString(Enums.StringName.VENDOR) + " " + + // GL.GetString(Enums.StringName.RENDERER) + " " + + // GL.GetString(Enums.StringName.VERSION); + + GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f); + GL.Enable(Enums.EnableCap.DEPTH_TEST); + + int vertex_shader_object, fragment_shader_object; + int status; + int shader_program; + + vertex_shader_object = GL.CreateShader(Enums.VERSION_2_0.VERTEX_SHADER); + fragment_shader_object = GL.CreateShader(Enums.VERSION_2_0.FRAGMENT_SHADER); + + GL.ShaderSource(vertex_shader_object, vertex_shader_source.Length, vertex_shader_source, (int[])null); + GL.CompileShader(vertex_shader_object); + GL.GetShader(vertex_shader_object, Enums.VERSION_2_0.COMPILE_STATUS, out status); + if (status != (int)Enums.Boolean.TRUE) + { + StringBuilder info = new StringBuilder(1024); + GL.GetShaderInfoLog(vertex_shader_object, info.MaxCapacity, (int[])null, info); + + throw new Exception(info.ToString()); + } + + GL.ShaderSource(fragment_shader_object, fragment_shader_source.Length, fragment_shader_source, (int[])null); + GL.CompileShader(fragment_shader_object); + GL.GetShader(fragment_shader_object, Enums.VERSION_2_0.COMPILE_STATUS, out status); + if (status != (int)Enums.Boolean.TRUE) + { + StringBuilder info = new StringBuilder(1024); + GL.GetShaderInfoLog(fragment_shader_object, 1024, (int[])null, info); + + throw new Exception(info.ToString()); + } + + shader_program = GL.CreateProgram(); + GL.AttachShader(shader_program, fragment_shader_object); + GL.AttachShader(shader_program, vertex_shader_object); + + GL.LinkProgram(shader_program); + GL.UseProgram(shader_program); + + OnResize(new OpenTK.Platform.ResizeEventArgs(this.Width, this.Height)); + } + + #endregion + + #region static public void Launch() + + /// + /// Launches this example. + /// + /// + /// Provides a simple way for the example launcher to launch the examples. + /// + static public void Launch() + { + using (T10_GLSL_Cube ex = new T10_GLSL_Cube()) + { + ex.Run(); + } + } + + #endregion + + #region OnResize + + protected override void OnResize(OpenTK.Platform.ResizeEventArgs e) + { + base.OnResize(e); + + GL.Viewport(0, 0, this.Width, this.Height); + + double ratio = 0.0; + ratio = this.Width / (double)this.Height; + + GL.MatrixMode(Enums.MatrixMode.PROJECTION); + GL.LoadIdentity(); + Glu.Perspective(45.0, ratio, 1.0, 64.0); + } + + #endregion + + #region UpdateFrame + + public override void UpdateFrame() + { + base.UpdateFrame(); + + if (Key[OpenTK.Input.Keys.Escape]) + { + this.Quit = true; + } + + GL.MatrixMode(Enums.MatrixMode.MODELVIEW); + GL.LoadIdentity(); + Glu.LookAt( + 0.0, 5.0, 5.0, + 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0 + ); + GL.Rotatef(angle, 0.0f, 1.0f, 0.0f); + angle += 0.05f; + } + + #endregion + + #region RenderFrame + + public override void RenderFrame() + { + base.RenderFrame(); + + GL.Clear(Enums.ClearBufferMask.COLOR_BUFFER_BIT | Enums.ClearBufferMask.DEPTH_BUFFER_BIT); + + DrawCube(); + + Context.SwapBuffers(); + } + + #endregion + + #region DrawCube + + public void DrawCube() + { + GL.Begin(Enums.BeginMode.QUADS); + + GL.Color3(1, 0, 0); + GL.Vertex3(-1.0f, -1.0f, -1.0f); + GL.Vertex3(-1.0f, 1.0f, -1.0f); + GL.Vertex3(1.0f, 1.0f, -1.0f); + GL.Vertex3(1.0f, -1.0f, -1.0f); + + GL.Color3(1, 1, 0); + GL.Vertex3(-1.0f, -1.0f, -1.0f); + GL.Vertex3(1.0f, -1.0f, -1.0f); + GL.Vertex3(1.0f, -1.0f, 1.0f); + GL.Vertex3(-1.0f, -1.0f, 1.0f); + + GL.Color3(1, 0, 1); + GL.Vertex3(-1.0f, -1.0f, -1.0f); + GL.Vertex3(-1.0f, -1.0f, 1.0f); + GL.Vertex3(-1.0f, 1.0f, 1.0f); + GL.Vertex3(-1.0f, 1.0f, -1.0f); + + GL.Color3(0, 1, 0); + GL.Vertex3(-1.0f, -1.0f, 1.0f); + GL.Vertex3(1.0f, -1.0f, 1.0f); + GL.Vertex3(1.0f, 1.0f, 1.0f); + GL.Vertex3(-1.0f, 1.0f, 1.0f); + + GL.Color3(0, 0, 1); + GL.Vertex3(-1.0f, 1.0f, -1.0f); + GL.Vertex3(-1.0f, 1.0f, 1.0f); + GL.Vertex3(1.0f, 1.0f, 1.0f); + GL.Vertex3(1.0f, 1.0f, -1.0f); + + GL.Color3(0, 1, 1); + GL.Vertex3(1.0f, -1.0f, -1.0f); + GL.Vertex3(1.0f, 1.0f, -1.0f); + GL.Vertex3(1.0f, 1.0f, 1.0f); + GL.Vertex3(1.0f, -1.0f, 1.0f); + + GL.End(); + } + + #endregion + } +} diff --git a/Source/Examples/Tests/S02_RawInput_Logger.cs b/Source/Examples/Tests/S02_RawInput_Logger.cs new file mode 100644 index 00000000..762c5a89 --- /dev/null +++ b/Source/Examples/Tests/S02_RawInput_Logger.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; + +using OpenTK; +using OpenTK.OpenGL; +using System.Threading; +using System.Runtime.Serialization; +using System.IO; +using System.Diagnostics; + +namespace Examples.Tests +{ + public class S02_RawInput_Logger : GameWindow, IExample + { + #region IExample Members + + public void Launch() + { + using (StreamWriter sw = new StreamWriter(Path.Combine(System.Environment.CurrentDirectory, "keymap.log"))) + { + //Debug.Listeners.Clear(); + Debug.Listeners.Add(new TextWriterTraceListener(sw)); + Debug.AutoFlush = true; + Debug.WriteLine("Starting key dump"); + + //using (S02_RawInput_Logger ex = new S02_RawInput_Logger()) + { + try + { + //ex.Run(); + Run(); + } + catch (Exception expt) + { + System.Diagnostics.Debug.WriteLine( + String.Format( + "Exception: {3}{0}Stacktrace:{0}{1}{0}{0}{2}", + System.Environment.NewLine, + expt.TargetSite, + expt.StackTrace, + expt.Message + ) + ); + /*MessageBox.Show( + String.Format( + "Stacktrace:{0}{1}{0}{0}{2}", + System.Environment.NewLine, + expt.TargetSite, + expt.StackTrace + ), + expt.Message + );*/ + throw; + } + } + Debug.Flush(); + Debug.Close(); + } + } + + #endregion + + public S02_RawInput_Logger() + { + GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); + } + + public override void RenderFrame() + { + base.RenderFrame(); + + GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT); + Context.SwapBuffers(); + } + } +} diff --git a/Source/Examples/Tutorial/T03_RotatingCube.cs b/Source/Examples/Tutorial/T03_RotatingCube.cs index c74273dc..491bb1cb 100644 --- a/Source/Examples/Tutorial/T03_RotatingCube.cs +++ b/Source/Examples/Tutorial/T03_RotatingCube.cs @@ -14,7 +14,6 @@ using OpenTK; using OpenTK.OpenGL; using OpenTK.Platform; using Enums = OpenTK.OpenGL.GL.Enums; -using OpenTK.Input; #endregion @@ -122,46 +121,43 @@ namespace Examples.Tutorial #endregion - #region DrawCube function + #region private void DrawCube() - /// - /// Draws simple, colored cube. - /// - protected void DrawCube() + private void DrawCube() { - GL.Begin(Enums.BeginMode.QUADS); + GL.Begin(GL.Enums.BeginMode.QUADS); - GL.Color3(1, 0, 0); + GL.Color3(1.0f, 0.0f, 0.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f); - GL.Color3(1, 1, 0); + GL.Color3(1.0f, 1.0f, 0.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f); - GL.Color3(1, 0, 1); + GL.Color3(1.0f, 0.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f); - GL.Color3(0, 1, 0); + GL.Color3(0.0f, 1.0f, 0.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f); - GL.Color3(0, 0, 1); + GL.Color3(0.0f, 0.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f); - GL.Color3(0, 1, 1); + GL.Color3(0.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f); @@ -172,7 +168,7 @@ namespace Examples.Tutorial #endregion - #region static public void Launch() + #region public void Launch() /// /// Launches this example. @@ -180,11 +176,12 @@ namespace Examples.Tutorial /// /// Provides a simple way for the example launcher to launch the examples. /// - static public void Launch() + public void Launch() { - using (T03_RotatingCube ex = new T03_RotatingCube()) + //using (T03_RotatingCube ex = new T03_RotatingCube()) { - ex.Run(); + //ex.Run(); + Run(); } } diff --git a/Source/Examples/Tutorial/T07_DisplayLists_Cube.cs b/Source/Examples/Tutorial/T07_DisplayLists_Cube.cs index c9c64b05..da3a19ee 100644 --- a/Source/Examples/Tutorial/T07_DisplayLists_Cube.cs +++ b/Source/Examples/Tutorial/T07_DisplayLists_Cube.cs @@ -17,7 +17,6 @@ using System.Windows.Forms; using OpenTK.OpenGL; using Enums = OpenTK.OpenGL.GL.Enums; using OpenTK; -using OpenTK.Input; #endregion --- Using Directives --- @@ -80,7 +79,7 @@ namespace Examples.Tutorial #endregion - #region static public void Launch() + #region public void Launch() /// /// Launches this example. @@ -88,11 +87,12 @@ namespace Examples.Tutorial /// /// Provides a simple way for the example launcher to launch the examples. /// - static public void Launch() + public void Launch() { - using (T03_RotatingCube ex = new T03_RotatingCube()) + //using (T03_RotatingCube ex = new T03_RotatingCube()) { - ex.Run(); + //ex.Run(); + Run(); } } diff --git a/Source/Examples/Tutorial/T08_VBO.cs b/Source/Examples/Tutorial/T08_VBO.cs index 5cfa879f..f7886f6a 100644 --- a/Source/Examples/Tutorial/T08_VBO.cs +++ b/Source/Examples/Tutorial/T08_VBO.cs @@ -12,7 +12,6 @@ using System.Text; using OpenTK; using OpenTK.OpenGL; -using OpenTK.Input; using OpenTK.Platform; #endregion @@ -107,7 +106,7 @@ namespace Examples.Tutorial GL.DrawElements( GL.Enums.BeginMode.QUADS, idata.Length, - GL.Enums.GLenum.UNSIGNED_SHORT, + GL.Enums.All.UNSIGNED_SHORT, idata); GL.BindBuffer(GL.Enums.VERSION_1_5.ARRAY_BUFFER, 0); @@ -212,7 +211,7 @@ namespace Examples.Tutorial #endregion - #region static public void Launch() + #region public void Launch() /// /// Launches this example. @@ -220,11 +219,12 @@ namespace Examples.Tutorial /// /// Provides a simple way for the example launcher to launch the examples. /// - static public void Launch() + public void Launch() { - using (T08_VBO ex = new T08_VBO()) + //using (T08_VBO ex = new T08_VBO()) { - ex.Run(); + //ex.Run(); + Run(); } } diff --git a/Source/Examples/Tutorial/T10_GLSL_Cube.cs b/Source/Examples/Tutorial/T10_GLSL_Cube.cs index b0cd65a0..cc5b6f55 100644 --- a/Source/Examples/Tutorial/T10_GLSL_Cube.cs +++ b/Source/Examples/Tutorial/T10_GLSL_Cube.cs @@ -15,9 +15,7 @@ using System.Windows.Forms; using System.Threading; using OpenTK.OpenGL; -using Enums = OpenTK.OpenGL.GL.Enums; using OpenTK; -using OpenTK.Input; #endregion --- Using Directives --- @@ -60,19 +58,19 @@ namespace Examples.Tutorial // GL.GetString(Enums.StringName.VERSION); GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f); - GL.Enable(Enums.EnableCap.DEPTH_TEST); + GL.Enable(GL.Enums.EnableCap.DEPTH_TEST); - int vertex_shader_object, fragment_shader_object; + uint vertex_shader_object, fragment_shader_object; int status; - int shader_program; + uint shader_program; - vertex_shader_object = GL.CreateShader(Enums.VERSION_2_0.VERTEX_SHADER); - fragment_shader_object = GL.CreateShader(Enums.VERSION_2_0.FRAGMENT_SHADER); + vertex_shader_object = (uint)GL.CreateShader(GL.Enums.VERSION_2_0.VERTEX_SHADER); + fragment_shader_object = (uint)GL.CreateShader(GL.Enums.VERSION_2_0.FRAGMENT_SHADER); GL.ShaderSource(vertex_shader_object, vertex_shader_source.Length, vertex_shader_source, (int[])null); GL.CompileShader(vertex_shader_object); - GL.GetShader(vertex_shader_object, Enums.VERSION_2_0.COMPILE_STATUS, out status); - if (status != (int)Enums.Boolean.TRUE) + GL.GetShader(vertex_shader_object, GL.Enums.VERSION_2_0.COMPILE_STATUS, out status); + if (status != (int)GL.Enums.Boolean.TRUE) { StringBuilder info = new StringBuilder(1024); GL.GetShaderInfoLog(vertex_shader_object, info.MaxCapacity, (int[])null, info); @@ -82,8 +80,8 @@ namespace Examples.Tutorial GL.ShaderSource(fragment_shader_object, fragment_shader_source.Length, fragment_shader_source, (int[])null); GL.CompileShader(fragment_shader_object); - GL.GetShader(fragment_shader_object, Enums.VERSION_2_0.COMPILE_STATUS, out status); - if (status != (int)Enums.Boolean.TRUE) + GL.GetShader(fragment_shader_object, GL.Enums.VERSION_2_0.COMPILE_STATUS, out status); + if (status != (int)GL.Enums.Boolean.TRUE) { StringBuilder info = new StringBuilder(1024); GL.GetShaderInfoLog(fragment_shader_object, 1024, (int[])null, info); @@ -91,7 +89,7 @@ namespace Examples.Tutorial throw new Exception(info.ToString()); } - shader_program = GL.CreateProgram(); + shader_program = (uint)GL.CreateProgram(); GL.AttachShader(shader_program, fragment_shader_object); GL.AttachShader(shader_program, vertex_shader_object); @@ -103,7 +101,7 @@ namespace Examples.Tutorial #endregion - #region static public void Launch() + #region public void Launch() /// /// Launches this example. @@ -111,11 +109,12 @@ namespace Examples.Tutorial /// /// Provides a simple way for the example launcher to launch the examples. /// - static public void Launch() + public void Launch() { - using (T10_GLSL_Cube ex = new T10_GLSL_Cube()) + //using (T10_GLSL_Cube ex = new T10_GLSL_Cube()) { - ex.Run(); + //ex.Run(); + Run(); } } @@ -132,7 +131,7 @@ namespace Examples.Tutorial double ratio = 0.0; ratio = this.Width / (double)this.Height; - GL.MatrixMode(Enums.MatrixMode.PROJECTION); + GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION); GL.LoadIdentity(); Glu.Perspective(45.0, ratio, 1.0, 64.0); } @@ -150,7 +149,7 @@ namespace Examples.Tutorial this.Quit = true; } - GL.MatrixMode(Enums.MatrixMode.MODELVIEW); + GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW); GL.LoadIdentity(); Glu.LookAt( 0.0, 5.0, 5.0, @@ -169,7 +168,7 @@ namespace Examples.Tutorial { base.RenderFrame(); - GL.Clear(Enums.ClearBufferMask.COLOR_BUFFER_BIT | Enums.ClearBufferMask.DEPTH_BUFFER_BIT); + GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT | GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT); DrawCube(); @@ -178,43 +177,43 @@ namespace Examples.Tutorial #endregion - #region DrawCube + #region private void DrawCube() - public void DrawCube() + private void DrawCube() { - GL.Begin(Enums.BeginMode.QUADS); + GL.Begin(GL.Enums.BeginMode.QUADS); - GL.Color3(1, 0, 0); + GL.Color3(1.0f, 0.0f, 0.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f); - GL.Color3(1, 1, 0); + GL.Color3(1.0f, 1.0f, 0.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f); - GL.Color3(1, 0, 1); + GL.Color3(1.0f, 0.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f); - GL.Color3(0, 1, 0); + GL.Color3(0.0f, 1.0f, 0.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f); - GL.Color3(0, 0, 1); + GL.Color3(0.0f, 0.0f, 1.0f); GL.Vertex3(-1.0f, 1.0f, -1.0f); GL.Vertex3(-1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f); - GL.Color3(0, 1, 1); + GL.Color3(0.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f); diff --git a/Source/OpenTK/GameWindow.cs b/Source/OpenTK/GameWindow.cs index b403877e..8b65e309 100644 --- a/Source/OpenTK/GameWindow.cs +++ b/Source/OpenTK/GameWindow.cs @@ -9,7 +9,6 @@ using System.Collections.Generic; using System.Text; using System.Diagnostics; -using OpenTK.Input; using OpenTK.Platform; namespace OpenTK @@ -19,6 +18,10 @@ namespace OpenTK private INativeWindow glWindow; private ResizeEventArgs resizeEventArgs = new ResizeEventArgs(); + public Input.IKeyboard Keyboard { get { return inputDevices.Keyboards[0]; } } + + private InputDevices inputDevices = new InputDevices(); + #region --- Contructors --- /// @@ -176,11 +179,6 @@ namespace OpenTK public event UpdateFrameEvent UpdateFrameNotify; public event RenderFrameEvent RenderFrameNotify; - public IKeyboard Key - { - get { return glWindow.Key; } - } - #endregion #region --- IResizable Members --- diff --git a/Source/OpenTK/Input/IInputDevice.cs b/Source/OpenTK/Input/IInputDevice.cs new file mode 100644 index 00000000..918d23ac --- /dev/null +++ b/Source/OpenTK/Input/IInputDevice.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenTK.Input +{ + public interface IInputDevice + { + string Description { get; } + InputDeviceType DeviceType { get; } + + } + + /// + /// The type of the input device. + /// + public enum InputDeviceType + { + /// + /// Device is a keyboard. + /// + Keyboard, + /// + /// Device is a mouse. + /// + Mouse, + /// + /// Device is a Human Interface Device. Joysticks, joypads, pens + /// and some specific usb keyboards/mice fall into this category. + /// + HID + } +} \ No newline at end of file diff --git a/Source/OpenTK/Input/IInputDriver.cs b/Source/OpenTK/Input/IInputDriver.cs new file mode 100644 index 00000000..40de652e --- /dev/null +++ b/Source/OpenTK/Input/IInputDriver.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenTK.Input +{ + public interface IInputDriver + { + IList InputDevices { get; } + IList Keyboards { get; } + //IEnumerable Mice { get; } + //IEnumerable Hids { get; } + } +} \ No newline at end of file diff --git a/Source/OpenTK/Input/IKeyboard.cs b/Source/OpenTK/Input/IKeyboard.cs index f2d3160a..143cce2d 100644 --- a/Source/OpenTK/Input/IKeyboard.cs +++ b/Source/OpenTK/Input/IKeyboard.cs @@ -6,9 +6,8 @@ namespace OpenTK.Input { - public interface IKeyboard + public interface IKeyboard : IInputDevice { bool this[Keys k] { get; } - //void Poll(); } -} +} \ No newline at end of file diff --git a/Source/OpenTK/Input/Keyboard.cs b/Source/OpenTK/Input/Keyboard.cs index 69d413ed..3902f988 100644 --- a/Source/OpenTK/Input/Keyboard.cs +++ b/Source/OpenTK/Input/Keyboard.cs @@ -16,6 +16,8 @@ namespace OpenTK.Input { private IKeyboard keyboard; + #region --- Constructors --- + public Keyboard() { if (Environment.OSVersion.Platform == PlatformID.Win32NT || @@ -36,6 +38,8 @@ namespace OpenTK.Input } } + #endregion + #region --- IKeyboard members --- public bool this[Keys k] @@ -45,8 +49,27 @@ namespace OpenTK.Input } #endregion + + #region --- IInputDevice Members --- + + public string Description + { + get { return keyboard.Description; } + } + + public InputDeviceType DeviceType + { + get { return keyboard.DeviceType; } + } + + #endregion } + #region public enum Keys : int + + /// + /// The available keyboard keys. + /// public enum Keys : int { // Modifiers @@ -56,6 +79,9 @@ namespace OpenTK.Input RightControl, LeftAlt, RightAlt, + LeftApp, + RightApp, + Menu, // Function keys (hopefully enough for most keyboards - mine has 26) F1, F2, F3, F4, @@ -73,7 +99,6 @@ namespace OpenTK.Input Left, Right, - // Special keys Enter, Escape, Space, @@ -86,6 +111,43 @@ namespace OpenTK.Input Home, End, CapsLock, + PrintScreen, + Pause, + NumLock, + + // Special keys + Sleep, + /*LogOff, + Help, + Undo, + Redo, + New, + Open, + Close, + Reply, + Forward, + Send, + Spell, + Save, + Calculator, + + // Folders and applications + Documents, + Pictures, + Music, + MediaPlayer, + Mail, + Browser, + Messenger, + + // Multimedia keys + Mute, + PlayPause, + Stop, + VolumeUp, + VOlumeDown, + PreviousTrack, + NextTrack,*/ // Keypad keys Keypad0, @@ -103,8 +165,7 @@ namespace OpenTK.Input KeypadSubtract, KeypadAdd, KeypadDecimal, - KeypadEqual, - KeypadEnter, + //KeypadEnter, // Letters A, B, C, D, E, F, G, @@ -125,17 +186,21 @@ namespace OpenTK.Input Number9, // Symbols + Tilde, Minus, - Equal, + //Equal, + Plus, LeftBracket, RightBracket, Semicolon, - QuotationMark, + Quote, Comma, - FullStop, + Period, Slash, BackSlash, MaxKeys } -} + + #endregion +} \ No newline at end of file diff --git a/Source/OpenTK/InputDevices.cs b/Source/OpenTK/InputDevices.cs new file mode 100644 index 00000000..68409117 --- /dev/null +++ b/Source/OpenTK/InputDevices.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using OpenTK.Input; + +namespace OpenTK +{ + public class InputDevices : IInputDriver + { + IInputDriver inputDriver; + + public InputDevices() + { + if (Environment.OSVersion.Version.Major > 5 || + (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1)) + { + inputDriver = new OpenTK.Platform.Windows.WinRawInput(); + } + else + { + throw new PlatformNotSupportedException("Input is not implemented for platforms prior to Windows XP, yet."); + } + } + + #region --- IInputDriver Members --- + + IList OpenTK.Input.IInputDriver.InputDevices + { + get { return inputDriver.InputDevices; } + } + + public IList Keyboards + { + get { return inputDriver.Keyboards; } + } + + #endregion + } +} diff --git a/Source/OpenTK/OpenGL/Bindings/GL.cs b/Source/OpenTK/OpenGL/Bindings/GL.cs index 6b9c6a87..89fea19d 100644 --- a/Source/OpenTK/OpenGL/Bindings/GL.cs +++ b/Source/OpenTK/OpenGL/Bindings/GL.cs @@ -4743,7 +4743,7 @@ namespace OpenTK.OpenGL } public static - GL.Enums.GLenum GetError() + GL.Enums.All GetError() { return Delegates.glGetError(); } @@ -5851,20 +5851,20 @@ namespace OpenTK.OpenGL [System.CLSCompliant(false)] public static - unsafe void DrawElements(GL.Enums.BeginMode mode, Int32 count, GL.Enums.GLenum type, void* indices) + unsafe void DrawElements(GL.Enums.BeginMode mode, Int32 count, GL.Enums.All type, void* indices) { - unsafe { Delegates.glDrawElements((GL.Enums.BeginMode)mode, (Int32)count, (GL.Enums.GLenum)type, (void*)indices); } + unsafe { Delegates.glDrawElements((GL.Enums.BeginMode)mode, (Int32)count, (GL.Enums.All)type, (void*)indices); } } public static - void DrawElements(GL.Enums.BeginMode mode, Int32 count, GL.Enums.GLenum type, [In, Out] object indices) + void DrawElements(GL.Enums.BeginMode mode, Int32 count, GL.Enums.All type, [In, Out] object indices) { System.Runtime.InteropServices.GCHandle indices_ptr = System.Runtime.InteropServices.GCHandle.Alloc(indices, System.Runtime.InteropServices.GCHandleType.Pinned); unsafe { try { - Delegates.glDrawElements((GL.Enums.BeginMode)mode, (Int32)count, (GL.Enums.GLenum)type, (void*)indices_ptr.AddrOfPinnedObject()); + Delegates.glDrawElements((GL.Enums.BeginMode)mode, (Int32)count, (GL.Enums.All)type, (void*)indices_ptr.AddrOfPinnedObject()); } finally { @@ -27616,7 +27616,7 @@ namespace OpenTK.OpenGL } public static - GL.Enums.GLenum CheckFramebufferStat(GL.Enums.EXT_framebuffer_object target) + GL.Enums.All CheckFramebufferStat(GL.Enums.EXT_framebuffer_object target) { return Delegates.glCheckFramebufferStatusEXT((GL.Enums.EXT_framebuffer_object)target); } @@ -31538,20 +31538,20 @@ namespace OpenTK.OpenGL [System.CLSCompliant(false)] public static - unsafe void IglooInterfaceSGIX(GL.Enums.GLenum pname, void* @params) + unsafe void IglooInterfaceSGIX(GL.Enums.All pname, void* @params) { - unsafe { Delegates.glIglooInterfaceSGIX((GL.Enums.GLenum)pname, (void*)@params); } + unsafe { Delegates.glIglooInterfaceSGIX((GL.Enums.All)pname, (void*)@params); } } public static - void IglooInterfaceSGIX(GL.Enums.GLenum pname, [In, Out] object @params) + void IglooInterfaceSGIX(GL.Enums.All pname, [In, Out] object @params) { System.Runtime.InteropServices.GCHandle @params_ptr = System.Runtime.InteropServices.GCHandle.Alloc(@params, System.Runtime.InteropServices.GCHandleType.Pinned); unsafe { try { - Delegates.glIglooInterfaceSGIX((GL.Enums.GLenum)pname, (void*)@params_ptr.AddrOfPinnedObject()); + Delegates.glIglooInterfaceSGIX((GL.Enums.All)pname, (void*)@params_ptr.AddrOfPinnedObject()); } finally { @@ -48811,9 +48811,9 @@ namespace OpenTK.OpenGL public static class INGR { public static - void BlendFuncSeparateINGR(GL.Enums.GLenum sfactorRGB, GL.Enums.GLenum dfactorRGB, GL.Enums.GLenum sfactorAlpha, GL.Enums.GLenum dfactorAlpha) + void BlendFuncSeparateINGR(GL.Enums.All sfactorRGB, GL.Enums.All dfactorRGB, GL.Enums.All sfactorAlpha, GL.Enums.All dfactorAlpha) { - Delegates.glBlendFuncSeparateINGR((GL.Enums.GLenum)sfactorRGB, (GL.Enums.GLenum)dfactorRGB, (GL.Enums.GLenum)sfactorAlpha, (GL.Enums.GLenum)dfactorAlpha); + Delegates.glBlendFuncSeparateINGR((GL.Enums.All)sfactorRGB, (GL.Enums.All)dfactorRGB, (GL.Enums.All)sfactorAlpha, (GL.Enums.All)dfactorAlpha); } } diff --git a/Source/OpenTK/OpenGL/Bindings/GLCore.cs b/Source/OpenTK/OpenGL/Bindings/GLCore.cs index 6863f425..ef14ab99 100644 --- a/Source/OpenTK/OpenGL/Bindings/GLCore.cs +++ b/Source/OpenTK/OpenGL/Bindings/GLCore.cs @@ -792,7 +792,7 @@ namespace OpenTK.OpenGL internal extern static unsafe void GetDoublev(GL.Enums.GetPName pname, [Out] Double* @params); [System.Security.SuppressUnmanagedCodeSecurity()] [System.Runtime.InteropServices.DllImport(GL.Library, EntryPoint = "glGetError", ExactSpelling = true)] - internal extern static GL.Enums.GLenum GetError(); + internal extern static GL.Enums.All GetError(); [System.Security.SuppressUnmanagedCodeSecurity()] [System.Runtime.InteropServices.DllImport(GL.Library, EntryPoint = "glGetFloatv", ExactSpelling = true)] internal extern static unsafe void GetFloatv(GL.Enums.GetPName pname, [Out] Single* @params); @@ -939,7 +939,7 @@ namespace OpenTK.OpenGL internal extern static void DrawArrays(GL.Enums.BeginMode mode, Int32 first, Int32 count); [System.Security.SuppressUnmanagedCodeSecurity()] [System.Runtime.InteropServices.DllImport(GL.Library, EntryPoint = "glDrawElements", ExactSpelling = true)] - internal extern static unsafe void DrawElements(GL.Enums.BeginMode mode, Int32 count, GL.Enums.GLenum type, void* indices); + internal extern static unsafe void DrawElements(GL.Enums.BeginMode mode, Int32 count, GL.Enums.All type, void* indices); [System.Security.SuppressUnmanagedCodeSecurity()] [System.Runtime.InteropServices.DllImport(GL.Library, EntryPoint = "glEdgeFlagPointer", ExactSpelling = true)] internal extern static unsafe void EdgeFlagPointer(Int32 stride, void* pointer); @@ -3159,7 +3159,7 @@ namespace OpenTK.OpenGL internal extern static void BlendFuncSeparateEXT(GL.Enums.EXT_blend_func_separate sfactorRGB, GL.Enums.EXT_blend_func_separate dfactorRGB, GL.Enums.EXT_blend_func_separate sfactorAlpha, GL.Enums.EXT_blend_func_separate dfactorAlpha); [System.Security.SuppressUnmanagedCodeSecurity()] [System.Runtime.InteropServices.DllImport(GL.Library, EntryPoint = "glBlendFuncSeparateINGR", ExactSpelling = true)] - internal extern static void BlendFuncSeparateINGR(GL.Enums.GLenum sfactorRGB, GL.Enums.GLenum dfactorRGB, GL.Enums.GLenum sfactorAlpha, GL.Enums.GLenum dfactorAlpha); + internal extern static void BlendFuncSeparateINGR(GL.Enums.All sfactorRGB, GL.Enums.All dfactorRGB, GL.Enums.All sfactorAlpha, GL.Enums.All dfactorAlpha); [System.Security.SuppressUnmanagedCodeSecurity()] [System.Runtime.InteropServices.DllImport(GL.Library, EntryPoint = "glVertexWeightfEXT", ExactSpelling = true)] internal extern static void VertexWeightfEXT(Single weight); @@ -3333,7 +3333,7 @@ namespace OpenTK.OpenGL internal extern static void TextureColorMaskSGIS(GL.Enums.Boolean red, GL.Enums.Boolean green, GL.Enums.Boolean blue, GL.Enums.Boolean alpha); [System.Security.SuppressUnmanagedCodeSecurity()] [System.Runtime.InteropServices.DllImport(GL.Library, EntryPoint = "glIglooInterfaceSGIX", ExactSpelling = true)] - internal extern static unsafe void IglooInterfaceSGIX(GL.Enums.GLenum pname, void* @params); + internal extern static unsafe void IglooInterfaceSGIX(GL.Enums.All pname, void* @params); [System.Security.SuppressUnmanagedCodeSecurity()] [System.Runtime.InteropServices.DllImport(GL.Library, EntryPoint = "glDeleteFencesNV", ExactSpelling = true)] internal extern static unsafe void DeleteFencesNV(Int32 n, UInt32* fences); @@ -4269,7 +4269,7 @@ namespace OpenTK.OpenGL internal extern static unsafe void GenFramebuffersEXT(Int32 n, [Out] UInt32* framebuffers); [System.Security.SuppressUnmanagedCodeSecurity()] [System.Runtime.InteropServices.DllImport(GL.Library, EntryPoint = "glCheckFramebufferStatusEXT", ExactSpelling = true)] - internal extern static GL.Enums.GLenum CheckFramebufferStatusEXT(GL.Enums.EXT_framebuffer_object target); + internal extern static GL.Enums.All CheckFramebufferStatusEXT(GL.Enums.EXT_framebuffer_object target); [System.Security.SuppressUnmanagedCodeSecurity()] [System.Runtime.InteropServices.DllImport(GL.Library, EntryPoint = "glFramebufferTexture1DEXT", ExactSpelling = true)] internal extern static void FramebufferTexture1DEXT(GL.Enums.EXT_framebuffer_object target, GL.Enums.EXT_framebuffer_object attachment, GL.Enums.EXT_framebuffer_object textarget, UInt32 texture, Int32 level); diff --git a/Source/OpenTK/OpenGL/Bindings/GLDelegates.cs b/Source/OpenTK/OpenGL/Bindings/GLDelegates.cs index 5602798c..c94d49c4 100644 --- a/Source/OpenTK/OpenGL/Bindings/GLDelegates.cs +++ b/Source/OpenTK/OpenGL/Bindings/GLDelegates.cs @@ -793,7 +793,7 @@ namespace OpenTK.OpenGL internal unsafe delegate void GetDoublev(GL.Enums.GetPName pname, [Out] Double* @params); internal unsafe static GetDoublev glGetDoublev = (GetDoublev)GL.GetDelegateForExtensionMethod("glGetDoublev", typeof(GetDoublev)) ?? new GetDoublev(Imports.GetDoublev); [System.Security.SuppressUnmanagedCodeSecurity()] - internal delegate GL.Enums.GLenum GetError(); + internal delegate GL.Enums.All GetError(); internal static GetError glGetError = (GetError)GL.GetDelegateForExtensionMethod("glGetError", typeof(GetError)) ?? new GetError(Imports.GetError); [System.Security.SuppressUnmanagedCodeSecurity()] internal unsafe delegate void GetFloatv(GL.Enums.GetPName pname, [Out] Single* @params); @@ -940,7 +940,7 @@ namespace OpenTK.OpenGL internal delegate void DrawArrays(GL.Enums.BeginMode mode, Int32 first, Int32 count); internal static DrawArrays glDrawArrays = (DrawArrays)GL.GetDelegateForExtensionMethod("glDrawArrays", typeof(DrawArrays)) ?? new DrawArrays(Imports.DrawArrays); [System.Security.SuppressUnmanagedCodeSecurity()] - internal unsafe delegate void DrawElements(GL.Enums.BeginMode mode, Int32 count, GL.Enums.GLenum type, void* indices); + internal unsafe delegate void DrawElements(GL.Enums.BeginMode mode, Int32 count, GL.Enums.All type, void* indices); internal unsafe static DrawElements glDrawElements = (DrawElements)GL.GetDelegateForExtensionMethod("glDrawElements", typeof(DrawElements)) ?? new DrawElements(Imports.DrawElements); [System.Security.SuppressUnmanagedCodeSecurity()] internal unsafe delegate void EdgeFlagPointer(Int32 stride, void* pointer); @@ -3160,7 +3160,7 @@ namespace OpenTK.OpenGL internal delegate void BlendFuncSeparateEXT(GL.Enums.EXT_blend_func_separate sfactorRGB, GL.Enums.EXT_blend_func_separate dfactorRGB, GL.Enums.EXT_blend_func_separate sfactorAlpha, GL.Enums.EXT_blend_func_separate dfactorAlpha); internal static BlendFuncSeparateEXT glBlendFuncSeparateEXT = (BlendFuncSeparateEXT)GL.GetDelegateForExtensionMethod("glBlendFuncSeparateEXT", typeof(BlendFuncSeparateEXT)); [System.Security.SuppressUnmanagedCodeSecurity()] - internal delegate void BlendFuncSeparateINGR(GL.Enums.GLenum sfactorRGB, GL.Enums.GLenum dfactorRGB, GL.Enums.GLenum sfactorAlpha, GL.Enums.GLenum dfactorAlpha); + internal delegate void BlendFuncSeparateINGR(GL.Enums.All sfactorRGB, GL.Enums.All dfactorRGB, GL.Enums.All sfactorAlpha, GL.Enums.All dfactorAlpha); internal static BlendFuncSeparateINGR glBlendFuncSeparateINGR = (BlendFuncSeparateINGR)GL.GetDelegateForExtensionMethod("glBlendFuncSeparateINGR", typeof(BlendFuncSeparateINGR)); [System.Security.SuppressUnmanagedCodeSecurity()] internal delegate void VertexWeightfEXT(Single weight); @@ -3334,7 +3334,7 @@ namespace OpenTK.OpenGL internal delegate void TextureColorMaskSGIS(GL.Enums.Boolean red, GL.Enums.Boolean green, GL.Enums.Boolean blue, GL.Enums.Boolean alpha); internal static TextureColorMaskSGIS glTextureColorMaskSGIS = (TextureColorMaskSGIS)GL.GetDelegateForExtensionMethod("glTextureColorMaskSGIS", typeof(TextureColorMaskSGIS)); [System.Security.SuppressUnmanagedCodeSecurity()] - internal unsafe delegate void IglooInterfaceSGIX(GL.Enums.GLenum pname, void* @params); + internal unsafe delegate void IglooInterfaceSGIX(GL.Enums.All pname, void* @params); internal unsafe static IglooInterfaceSGIX glIglooInterfaceSGIX = (IglooInterfaceSGIX)GL.GetDelegateForExtensionMethod("glIglooInterfaceSGIX", typeof(IglooInterfaceSGIX)); [System.Security.SuppressUnmanagedCodeSecurity()] internal unsafe delegate void DeleteFencesNV(Int32 n, UInt32* fences); @@ -4270,7 +4270,7 @@ namespace OpenTK.OpenGL internal unsafe delegate void GenFramebuffersEXT(Int32 n, [Out] UInt32* framebuffers); internal unsafe static GenFramebuffersEXT glGenFramebuffersEXT = (GenFramebuffersEXT)GL.GetDelegateForExtensionMethod("glGenFramebuffersEXT", typeof(GenFramebuffersEXT)); [System.Security.SuppressUnmanagedCodeSecurity()] - internal delegate GL.Enums.GLenum CheckFramebufferStatusEXT(GL.Enums.EXT_framebuffer_object target); + internal delegate GL.Enums.All CheckFramebufferStatusEXT(GL.Enums.EXT_framebuffer_object target); internal static CheckFramebufferStatusEXT glCheckFramebufferStatusEXT = (CheckFramebufferStatusEXT)GL.GetDelegateForExtensionMethod("glCheckFramebufferStatusEXT", typeof(CheckFramebufferStatusEXT)); [System.Security.SuppressUnmanagedCodeSecurity()] internal delegate void FramebufferTexture1DEXT(GL.Enums.EXT_framebuffer_object target, GL.Enums.EXT_framebuffer_object attachment, GL.Enums.EXT_framebuffer_object textarget, UInt32 texture, Int32 level); diff --git a/Source/OpenTK/OpenGL/Bindings/GLEnums.cs b/Source/OpenTK/OpenGL/Bindings/GLEnums.cs index a708155c..53ee60f5 100644 --- a/Source/OpenTK/OpenGL/Bindings/GLEnums.cs +++ b/Source/OpenTK/OpenGL/Bindings/GLEnums.cs @@ -2580,7 +2580,7 @@ namespace OpenTK.OpenGL UNPACK_SUBSAMPLE_RATE_SGIX = ((int)0x85A1), } - public enum GLenum + public enum All { MAX_GEOMETRY_BINDABLE_UNIFORMS_EXT = ((int)0x8DE4), T4F_V4F = ((int)0x2A28), @@ -2820,7 +2820,7 @@ namespace OpenTK.OpenGL DONT_CARE = ((int)0x1100), ALPHA_FLOAT16_ATI = ((int)0x881C), LINEAR_MIPMAP_LINEAR = ((int)0x2703), - MODELVIEW0_STACK_DEPTH_EXT = ((int)GetPName.MODELVIEW_STACK_DEPTH), + MODELVIEW0_STACK_DEPTH_EXT = ((int)All.MODELVIEW_STACK_DEPTH), POINT_TOKEN = ((int)0x0701), COMPRESSED_SRGB_EXT = ((int)0x8C48), EVAL_VERTEX_ATTRIB0_NV = ((int)0x86C6), @@ -5227,7 +5227,7 @@ namespace OpenTK.OpenGL VERTEX4_BIT_PGI = ((int)0x00000008), TEXTURE_INDEX_SIZE_EXT = ((int)0x80ED), MAP2_TEXTURE_COORD_3 = ((int)0x0DB5), - MODELVIEW0_MATRIX_EXT = ((int)GetPName.MODELVIEW_MATRIX), + MODELVIEW0_MATRIX_EXT = ((int)All.MODELVIEW_MATRIX), TEXTURE_DEPTH = ((int)0x8071), POLYGON_OFFSET_BIAS_EXT = ((int)0x8039), OFFSET_TEXTURE_SCALE_NV = ((int)0x86E2), @@ -5462,7 +5462,7 @@ namespace OpenTK.OpenGL FLOAT_RG16_NV = ((int)0x8886), INTENSITY8 = ((int)0x804B), PIXEL_COUNT_NV = ((int)0x8866), - MODELVIEW0_EXT = ((int)MatrixMode.MODELVIEW), + MODELVIEW0_EXT = ((int)All.MODELVIEW), MAX_ELEMENTS_VERTICES = ((int)0x80E8), VERTEX_ARRAY_SIZE = ((int)0x807A), BGRA_EXT = ((int)0x80E1), @@ -6959,13 +6959,13 @@ namespace OpenTK.OpenGL MODELVIEW1_MATRIX_EXT = ((int)0x8506), VERTEX_WEIGHT_ARRAY_EXT = ((int)0x850C), VERTEX_WEIGHT_ARRAY_POINTER_EXT = ((int)0x8510), - MODELVIEW0_STACK_DEPTH_EXT = ((int)GetPName.MODELVIEW_STACK_DEPTH), + MODELVIEW0_STACK_DEPTH_EXT = ((int)All.MODELVIEW_STACK_DEPTH), VERTEX_WEIGHT_ARRAY_TYPE_EXT = ((int)0x850E), CURRENT_VERTEX_WEIGHT_EXT = ((int)0x850B), VERTEX_WEIGHT_ARRAY_SIZE_EXT = ((int)0x850D), - MODELVIEW0_MATRIX_EXT = ((int)GetPName.MODELVIEW_MATRIX), + MODELVIEW0_MATRIX_EXT = ((int)All.MODELVIEW_MATRIX), VERTEX_WEIGHT_ARRAY_STRIDE_EXT = ((int)0x850F), - MODELVIEW0_EXT = ((int)MatrixMode.MODELVIEW), + MODELVIEW0_EXT = ((int)All.MODELVIEW), } public enum NV_light_max_exponent diff --git a/Source/OpenTK/Platform/IGameWindow.cs b/Source/OpenTK/Platform/IGameWindow.cs index b1049129..e347d70d 100644 --- a/Source/OpenTK/Platform/IGameWindow.cs +++ b/Source/OpenTK/Platform/IGameWindow.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Text; -using OpenTK.Input; namespace OpenTK.Platform { @@ -15,8 +14,6 @@ namespace OpenTK.Platform event UpdateFrameEvent UpdateFrameNotify; event RenderFrameEvent RenderFrameNotify; - - IKeyboard Key { get; } } public delegate void UpdateFrameEvent(EventArgs e); diff --git a/Source/OpenTK/Platform/INativeWindow.cs b/Source/OpenTK/Platform/INativeWindow.cs index d01a4fa4..1640901e 100644 --- a/Source/OpenTK/Platform/INativeWindow.cs +++ b/Source/OpenTK/Platform/INativeWindow.cs @@ -13,7 +13,6 @@ namespace OpenTK.Platform bool IsIdle { get; } bool Quit { get; set; } bool Fullscreen { get; set; } - OpenTK.Input.IKeyboard Key { get; } IGLContext Context { get; } } } diff --git a/Source/OpenTK/Platform/Windows/API.cs b/Source/OpenTK/Platform/Windows/API.cs index 70c0ffd1..d4351708 100644 --- a/Source/OpenTK/Platform/Windows/API.cs +++ b/Source/OpenTK/Platform/Windows/API.cs @@ -57,6 +57,7 @@ namespace OpenTK.Platform.Windows RawInputHeaderSize = (uint)Marshal.SizeOf(typeof(RawInputHeader)); RawInputSize = (uint)Marshal.SizeOf(typeof(RawInput)); RawInputDeviceSize = (uint)Marshal.SizeOf(typeof(RawInputDevice)); + RawInputDeviceListSize = (uint)Marshal.SizeOf(typeof(RawInputDeviceList)); } #region Constants @@ -159,8 +160,6 @@ namespace OpenTK.Platform.Windows // (found in winuser.h) internal const int ENUM_REGISTRY_SETTINGS = -2; internal const int ENUM_CURRENT_SETTINGS = -1; - - public const int VK_ESCAPE = 0x1B; } #endregion @@ -171,18 +170,6 @@ namespace OpenTK.Platform.Windows #region PeekMessage - [StructLayout(LayoutKind.Sequential)] - internal struct Message - { - internal IntPtr hWnd; - internal int msg; - internal IntPtr wParam; - internal IntPtr lParam; - internal int time; - internal System.Drawing.Point p; - //System.Drawing. - } - /// /// Low-level WINAPI function that checks the next message in the queue. /// @@ -796,7 +783,41 @@ namespace OpenTK.Platform.Windows /// [DllImport("user32.dll", SetLastError = true)] public static extern UINT GetRawInputDeviceList( - [Out] RawInputDeviceList[] RawInputDeviceList, + [In, Out] RawInputDeviceList[] RawInputDeviceList, + [In, Out] ref UINT NumDevices, + UINT Size + ); + + /// + /// Enumerates the raw input devices attached to the system. + /// + /// + /// ointer to buffer that holds an array of RawInputDeviceList structures + /// for the devices attached to the system. + /// If NULL, the number of devices are returned in NumDevices. + /// + /// + /// Pointer to a variable. If RawInputDeviceList is NULL, it specifies the number + /// of devices attached to the system. Otherwise, it contains the size, in bytes, + /// of the preallocated buffer pointed to by pRawInputDeviceList. + /// However, if NumDevices is smaller than needed to contain RawInputDeviceList structures, + /// the required buffer size is returned here. + /// + /// + /// Size of a RawInputDeviceList structure. + /// + /// + /// If the function is successful, the return value is the number of devices stored in the buffer + /// pointed to by RawInputDeviceList. + /// If RawInputDeviceList is NULL, the return value is zero. + /// If NumDevices is smaller than needed to contain all the RawInputDeviceList structures, + /// the return value is (UINT) -1 and the required buffer is returned in NumDevices. + /// Calling GetLastError returns ERROR_INSUFFICIENT_BUFFER. + /// On any other error, the function returns (UINT) -1 and GetLastError returns the error indication. + /// + [DllImport("user32.dll", SetLastError = true)] + public static extern UINT GetRawInputDeviceList( + [In, Out] IntPtr RawInputDeviceList, [In, Out] ref UINT NumDevices, UINT Size ); @@ -919,6 +940,24 @@ namespace OpenTK.Platform.Windows #region --- Structures --- + #region Message + + [StructLayout(LayoutKind.Sequential)] + internal struct Message + { + internal IntPtr HWnd; + internal int Msg; + internal IntPtr WParam; + internal IntPtr LParam; + internal IntPtr Result; + + //internal int Time; + //internal System.Drawing.Point p; + //System.Drawing. + } + + #endregion + #region CreateStruct internal struct CreateStruct @@ -1358,11 +1397,13 @@ namespace OpenTK.Platform.Windows #region RawInputDeviceList + public static readonly uint RawInputDeviceListSize; + /// /// Contains information about a raw input device. /// [StructLayout(LayoutKind.Sequential)] - public class RawInputDeviceList + public struct RawInputDeviceList { /// /// Handle to the raw input device. @@ -1372,6 +1413,11 @@ namespace OpenTK.Platform.Windows /// Type of device. /// public RawInputDeviceType Type; + + public override string ToString() + { + return String.Format("{0}, Handle: {1}", Type, Device); + } } #endregion diff --git a/Source/OpenTK/Platform/Windows/WinGLNative.cs b/Source/OpenTK/Platform/Windows/WinGLNative.cs index 07316ba7..10b79587 100644 --- a/Source/OpenTK/Platform/Windows/WinGLNative.cs +++ b/Source/OpenTK/Platform/Windows/WinGLNative.cs @@ -11,7 +11,6 @@ using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Windows.Forms; -using OpenTK.Input; #endregion @@ -21,11 +20,11 @@ namespace OpenTK.Platform.Windows { private WinGLContext glContext; private DisplayMode mode = new DisplayMode(); + + private Input.IInputDriver inputDriver; private bool disposed; - private WinRawKeyboard key; - #region --- Contructors --- /// @@ -46,7 +45,6 @@ namespace OpenTK.Platform.Windows private void CreateWindow(DisplayMode mode) { - CreateParams cp = new CreateParams(); cp.ClassStyle = (int)API.WindowClassStyle.OwnDC | @@ -74,12 +72,6 @@ namespace OpenTK.Platform.Windows 0.0f ) ); - - if (Environment.OSVersion.Version.Major > 5 || - (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1)) - key = new WinRawKeyboard(this.Handle); // WinXP and higher support raw input. - else - throw new PlatformNotSupportedException("Input is not implemented for platforms prior to Windows XP, yet."); } /* @@ -179,17 +171,9 @@ namespace OpenTK.Platform.Windows case API.Constants.WM_KEYUP: break; - case API.Constants.WM_INPUT: // Raw input - API.RawInput rin = WinRawInput.ProcessEvent(ref msg); - if (rin.Header.Type == API.RawInputDeviceType.KEYBOARD) - { - if (this.key.ProcessEvent(rin)) - return; - else - break; - break; - } - break; + //case API.Constants.WM_INPUT: // Raw input + // WinRawInput.ProcessEvent(ref msg, key); + // break; case API.Constants.WM_CLOSE: API.PostQuitMessage(0); @@ -203,18 +187,6 @@ namespace OpenTK.Platform.Windows base.WndProc(ref m); } - private bool ProcessKey(ref Message m) - { - switch ((int)m.WParam) - { - case API.Constants.VK_ESCAPE: - //= (m.Msg == API.Constants.WM_KEYDOWN) ? true : false; - return true; - } - - return false; - } - #endregion #region --- INativeWindow Members --- @@ -247,15 +219,6 @@ namespace OpenTK.Platform.Windows #endregion - #region public IKeyboard Key - - public IKeyboard Key - { - get { return this.key; } - } - - #endregion - #region public bool Quit private bool quit; diff --git a/Source/OpenTK/Platform/Windows/WinRawInput.cs b/Source/OpenTK/Platform/Windows/WinRawInput.cs index b34d3516..eb24c481 100644 --- a/Source/OpenTK/Platform/Windows/WinRawInput.cs +++ b/Source/OpenTK/Platform/Windows/WinRawInput.cs @@ -1,5 +1,5 @@ #region --- License --- -/* Copyright (c) 2007 Stefanos Apostolopoulos +/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos * See license.txt for license info */ #endregion @@ -9,53 +9,206 @@ using System; using System.Collections.Generic; using System.Text; -using System.Windows.Forms; using System.Runtime.InteropServices; +using System.Diagnostics; +using System.Windows.Forms; +using OpenTK.Input; #endregion namespace OpenTK.Platform.Windows { - static class WinRawInput + internal class WinRawInput : NativeWindow, Input.IInputDriver { - private static API.RawInput data = new API.RawInput(); - internal static API.RawInput ProcessEvent(ref System.Windows.Forms.Message msg) + /// + /// Input event data. + /// + private API.RawInput data = new API.RawInput(); + + /// + /// The list of keyboards connected to this system. + /// + private List keyboards = new List(); + + WinRawKeyboard key; + + internal IEnumerable InputDevices + { + get + { + return (IEnumerable)key; + } + } + + internal WinRawInput() + { + CreateParams cp = new CreateParams(); + /*cp.ClassStyle = + (int)API.WindowClassStyle.ParentDC; + cp.Style = + (int)API.WindowStyle.Disabled | + (int)API.WindowStyle.ChildWindow;*/ + + cp.Caption = "OpenTK hidden input handler window"; + base.CreateHandle(cp); + //key = new WinRawKeyboard(this.Handle); + + uint numKeyboards = WinRawKeyboard.Count; + } + + + private static uint deviceCount; + + internal static uint DeviceCount + { + get { return DeviceListChanged ? deviceCount : deviceCount; } + } + + /// + /// Gets a value indicating whether the Device list has changed, for example + /// by removing or adding a device. + /// + internal static bool DeviceListChanged + { + get + { + uint count = 0; + if (API.GetRawInputDeviceList(null, ref count, API.RawInputDeviceListSize) == 0) + { + if (deviceCount == count) + return true; + + deviceCount = count; + return false; + } + else + { + throw new ApplicationException(String.Format( + "Could not retrieve the count of Keyboard devices. Windows error: {0}", + Marshal.GetLastWin32Error())); + } + } + } + + #region protected override void WndProc(ref Message msg) + + /// + /// Processes the input Windows Message, routing the data to the correct Keyboard, Mouse or HID. + /// + /// The WM_INPUT message, containing the data on the input event. + protected override void WndProc(ref Message msg) { if (msg.Msg == API.Constants.WM_INPUT) { uint size = 0; // Get the size of the input data - API.GetRawInputData( - msg.LParam, - API.GetRawInputDataEnum.INPUT, - IntPtr.Zero, - ref size, - API.RawInputHeaderSize - ); + API.GetRawInputData(msg.LParam, API.GetRawInputDataEnum.INPUT, + IntPtr.Zero, ref size, API.RawInputHeaderSize); if (data == null || API.RawInputSize < size) { - throw new Exception("WTF?!"); + throw new ApplicationException("Critical error when processing raw windows input."); } - if (size == - API.GetRawInputData( - msg.LParam, - API.GetRawInputDataEnum.INPUT, - data, - ref size, - API.RawInputHeaderSize)) + if (size == API.GetRawInputData(msg.LParam, API.GetRawInputDataEnum.INPUT, + data, ref size, API.RawInputHeaderSize)) { - return data; + switch (data.Header.Type) + { + case API.RawInputDeviceType.KEYBOARD: + ProcessKeyboardEvent(data); + break; + + case API.RawInputDeviceType.MOUSE: + throw new NotImplementedException(); + + case API.RawInputDeviceType.HID: + throw new NotImplementedException(); + } } else { - throw new Exception( - "GetRawInputData returned invalid data. Please file a bug in http://opentk.sourceforge.net" + throw new ApplicationException( + "GetRawInputData returned invalid data. Please file a bug at http://opentk.sourceforge.net" ); } } - throw new Exception("Never reach this!"); + + base.WndProc(ref msg); } + + #endregion + + #region internal bool ProcessKeyboardEvent(API.RawInput rin) + + /// + /// Processes raw input events. + /// + /// + /// + internal bool ProcessKeyboardEvent(API.RawInput rin) + { + switch (rin.Header.Type) + { + case API.RawInputDeviceType.KEYBOARD: + bool pressed = + rin.Data.Keyboard.Message == API.Constants.WM_KEYDOWN || + rin.Data.Keyboard.Message == API.Constants.WM_SYSKEYDOWN; + + // Generic control, shift, alt keys may be sent instead of left/right. + // It seems you have to explicitly register left/right events. + switch (rin.Data.Keyboard.VKey) + { + case API.VirtualKeys.SHIFT: + key[Input.Keys.LeftShift] = key[Input.Keys.RightShift] = pressed; + return false; + + case API.VirtualKeys.CONTROL: + key[Input.Keys.LeftControl] = key[Input.Keys.RightControl] = pressed; + return false; + + case API.VirtualKeys.MENU: + key[Input.Keys.LeftAlt] = key[Input.Keys.RightAlt] = pressed; + return false; + + default: + if (!WinRawKeyboard.KeyMap.ContainsKey(rin.Data.Keyboard.VKey)) + { + Debug.Print("Virtual key {0} not mapped.", rin.Data.Keyboard.VKey); + OpenTK.OpenGL.GL.ClearColor(1.0f, 0.3f, 0.3f, 0.0f); + } + else + { + key[WinRawKeyboard.KeyMap[rin.Data.Keyboard.VKey]] = pressed; + OpenTK.OpenGL.GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); + } + break; + } + break; + + case API.RawInputDeviceType.MOUSE: + break; + + case API.RawInputDeviceType.HID: + break; + } + return false; + } + + #endregion + + #region --- IInputDriver Members --- + + IList Input.IInputDriver.InputDevices + { + get { throw new Exception("The method or operation is not implemented."); } + } + + public IList Keyboards + { + get { return (IList)keyboards; } + } + + #endregion } } diff --git a/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs b/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs index d7cccea8..9956140c 100644 --- a/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs +++ b/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs @@ -10,16 +10,158 @@ using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; - -using OpenTK.Input; +using System.Diagnostics; #endregion namespace OpenTK.Platform.Windows { - internal class WinRawKeyboard : OpenTK.Input.IKeyboard + internal class WinRawKeyboard : Input.IKeyboard { - private bool[] keys = new bool[(int)Keys.MaxKeys]; + private bool[] keys = new bool[(int)Input.Keys.MaxKeys]; + + #region internal static Dictionary KeyMap + + internal static Dictionary KeyMap = + new Dictionary((int)API.VirtualKeys.Last); + + private static bool keyMapExists; + /// + /// Initializes the map between VirtualKeys and OpenTK.Keys + /// + private static void InitKeyMap() + { + if (!keyMapExists) + { + try + { + KeyMap.Add(API.VirtualKeys.ESCAPE, Input.Keys.Escape); + + // Function keys + for (int i = 0; i < 24; i++) + { + KeyMap.Add((API.VirtualKeys)((int)API.VirtualKeys.F1 + i), Input.Keys.F1 + i); + } + + // Number keys (0-9) + for (int i = 0; i <= 9; i++) + { + KeyMap.Add((API.VirtualKeys)(0x30 + i), Input.Keys.Number0 + i); + } + + // Letters (A-Z) + for (int i = 0; i < 26; i++) + { + KeyMap.Add((API.VirtualKeys)(0x41 + i), Input.Keys.A + i); + } + + KeyMap.Add(API.VirtualKeys.TAB, Input.Keys.Tab); + KeyMap.Add(API.VirtualKeys.CAPITAL, Input.Keys.CapsLock); + KeyMap.Add(API.VirtualKeys.LCONTROL, Input.Keys.LeftControl); + KeyMap.Add(API.VirtualKeys.LSHIFT, Input.Keys.LeftShift); + KeyMap.Add(API.VirtualKeys.LWIN, Input.Keys.LeftApp); + KeyMap.Add(API.VirtualKeys.LMENU, Input.Keys.LeftAlt); + KeyMap.Add(API.VirtualKeys.SPACE, Input.Keys.Space); + KeyMap.Add(API.VirtualKeys.RMENU, Input.Keys.RightAlt); + KeyMap.Add(API.VirtualKeys.RWIN, Input.Keys.RightApp); + KeyMap.Add(API.VirtualKeys.APPS, Input.Keys.Menu); + KeyMap.Add(API.VirtualKeys.RCONTROL, Input.Keys.RightControl); + KeyMap.Add(API.VirtualKeys.RSHIFT, Input.Keys.RightShift); + KeyMap.Add(API.VirtualKeys.RETURN, Input.Keys.Enter); + KeyMap.Add(API.VirtualKeys.BACK, Input.Keys.Backspace); + + KeyMap.Add(API.VirtualKeys.OEM_1, Input.Keys.Semicolon); // Varies by keyboard, ;: on Win2K/US + KeyMap.Add(API.VirtualKeys.OEM_2, Input.Keys.Slash); // Varies by keyboard, /? on Win2K/US + KeyMap.Add(API.VirtualKeys.OEM_3, Input.Keys.Tilde); // Varies by keyboard, `~ on Win2K/US + KeyMap.Add(API.VirtualKeys.OEM_4, Input.Keys.LeftBracket); // Varies by keyboard, [{ on Win2K/US + KeyMap.Add(API.VirtualKeys.OEM_5, Input.Keys.BackSlash); // Varies by keyboard, \| on Win2K/US + KeyMap.Add(API.VirtualKeys.OEM_6, Input.Keys.RightBracket); // Varies by keyboard, ]} on Win2K/US + KeyMap.Add(API.VirtualKeys.OEM_7, Input.Keys.Quote); // Varies by keyboard, '" on Win2K/US + KeyMap.Add(API.VirtualKeys.OEM_PLUS, Input.Keys.Plus); // Invariant: + + KeyMap.Add(API.VirtualKeys.OEM_COMMA, Input.Keys.Comma); // Invariant: , + KeyMap.Add(API.VirtualKeys.OEM_MINUS, Input.Keys.Minus); // Invariant: - + KeyMap.Add(API.VirtualKeys.OEM_PERIOD, Input.Keys.Period); // Invariant: . + + KeyMap.Add(API.VirtualKeys.HOME, Input.Keys.Home); + KeyMap.Add(API.VirtualKeys.END, Input.Keys.End); + KeyMap.Add(API.VirtualKeys.DELETE, Input.Keys.Delete); + KeyMap.Add(API.VirtualKeys.PRIOR, Input.Keys.PageUp); + KeyMap.Add(API.VirtualKeys.NEXT, Input.Keys.PageDown); + KeyMap.Add(API.VirtualKeys.PRINT, Input.Keys.PrintScreen); + KeyMap.Add(API.VirtualKeys.PAUSE, Input.Keys.Pause); + KeyMap.Add(API.VirtualKeys.NUMLOCK, Input.Keys.NumLock); + + KeyMap.Add(API.VirtualKeys.SLEEP, Input.Keys.Sleep); + + // Keypad + for (int i = 0; i <= 9; i++) + { + KeyMap.Add((API.VirtualKeys)((int)API.VirtualKeys.NUMPAD0 + i), Input.Keys.Keypad0 + i); + + } + KeyMap.Add(API.VirtualKeys.DECIMAL, Input.Keys.KeypadDecimal); + KeyMap.Add(API.VirtualKeys.ADD, Input.Keys.KeypadAdd); + KeyMap.Add(API.VirtualKeys.SUBTRACT, Input.Keys.KeypadSubtract); + KeyMap.Add(API.VirtualKeys.DIVIDE, Input.Keys.KeypadDivide); + KeyMap.Add(API.VirtualKeys.MULTIPLY, Input.Keys.KeypadMultiply); + + // Navigation + KeyMap.Add(API.VirtualKeys.UP, Input.Keys.Up); + KeyMap.Add(API.VirtualKeys.DOWN, Input.Keys.Down); + KeyMap.Add(API.VirtualKeys.LEFT, Input.Keys.Left); + KeyMap.Add(API.VirtualKeys.RIGHT, Input.Keys.Right); + } + catch (ArgumentException e) + { + Debug.Print("Exception while creating keymap: '{0}'.", e.ToString()); + System.Windows.Forms.MessageBox.Show( + String.Format("Exception while creating keymap: '{0}'.", e.ToString())); + } + finally + { + keyMapExists = true; + } + } + } + + #endregion + + /// + /// The count of physical keyboards connected to this computer. + /// + private static uint keyboardCount; + internal static uint Count + { + get + { + if (!WinRawInput.DeviceListChanged && keyboardCount != 0) + { + return keyboardCount; + } + else + { + UpdateKeyboardList(); + return keyboardCount; + } + } + } + + internal static void UpdateKeyboardList() + { + uint count = WinRawInput.DeviceCount; + API.RawInputDeviceList[] ridl = new API.RawInputDeviceList[count]; + for (int i = 0; i < count; i++) + ridl[i] = new API.RawInputDeviceList(); + API.GetRawInputDeviceList(ridl, ref count, API.RawInputDeviceListSize); + + for (int i = 0; i < count; i++) + { + //do something with the information (see section on GetRawInputDeviceInfo) + + } + } + + #region --- Constructors --- internal WinRawKeyboard() : this(IntPtr.Zero) @@ -28,6 +170,7 @@ namespace OpenTK.Platform.Windows internal WinRawKeyboard(IntPtr windowHandle) { + Debug.WriteLine("Keyboard driver: Windows raw input"); API.RawInputDevice[] rid = new API.RawInputDevice[1]; // Keyboard is 1/6 (page/id). See http://www.microsoft.com/whdc/device/input/HID_HWID.mspx rid[0] = new API.RawInputDevice(); @@ -48,67 +191,37 @@ namespace OpenTK.Platform.Windows ); } - // Set the VirtualKey -> OpenTK.Key map - keyMap.Add(API.VirtualKeys.ESCAPE, Keys.Escape); - keyMap.Add(API.VirtualKeys.F1, Keys.F1); - keyMap.Add(API.VirtualKeys.F2, Keys.F2); - keyMap.Add(API.VirtualKeys.F3, Keys.F3); - keyMap.Add(API.VirtualKeys.F4, Keys.F4); - keyMap.Add(API.VirtualKeys.F5, Keys.F5); - keyMap.Add(API.VirtualKeys.F6, Keys.F6); - keyMap.Add(API.VirtualKeys.F7, Keys.F7); - keyMap.Add(API.VirtualKeys.F8, Keys.F8); - keyMap.Add(API.VirtualKeys.F9, Keys.F9); - keyMap.Add(API.VirtualKeys.F10, Keys.F10); - keyMap.Add(API.VirtualKeys.F11, Keys.F11); - keyMap.Add(API.VirtualKeys.F12, Keys.F12); + InitKeyMap(); } - internal bool ProcessEvent(API.RawInput rin) - { - switch (rin.Header.Type) - { - case API.RawInputDeviceType.KEYBOARD: - this[keyMap[rin.Data.Keyboard.VKey]] = - rin.Data.Keyboard.Message == API.Constants.WM_KEYDOWN || - rin.Data.Keyboard.Message == API.Constants.WM_SYSKEYDOWN; - break; - } - - return false; - } - - #region KeyMap - - internal static Dictionary keyMap = - new Dictionary((int)API.VirtualKeys.Last); - - /* - internal static List> keyMap = - new List>( - new KeyValuePair[] - { - new KeyValuePair(API.VirtualKeys.ESCAPE, Keys.Escape), - new KeyValuePair(API.VirtualKeys.F1, Keys.F1) - } - ); - */ #endregion #region --- IKeyboard members --- - public bool this[Keys k] + public bool this[Input.Keys k] { get { return keys[(int)k]; } internal set { + Debug.Print("OpenTK key {0} {1}.", k, value ? "pressed" : "released"); keys[(int)k] = value; - //throw new NotImplementedException(); } } #endregion + + #region --- IInputDevice Members --- + + public string Description + { + get { throw new Exception("The method or operation is not implemented."); } + } + + public Input.InputDeviceType DeviceType + { + get { return Input.InputDeviceType.Keyboard; } + } + + #endregion } - - } diff --git a/Source/OpenTK/Platform/X11/X11GLNative.cs b/Source/OpenTK/Platform/X11/X11GLNative.cs index 40febeb2..104372c4 100644 --- a/Source/OpenTK/Platform/X11/X11GLNative.cs +++ b/Source/OpenTK/Platform/X11/X11GLNative.cs @@ -9,7 +9,6 @@ using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Diagnostics; -using OpenTK.Input; //using OpenTK.OpenGL; @@ -273,7 +272,7 @@ namespace OpenTK.Platform.X11 #region public Keyboard Key - public IKeyboard Key + public Input.IKeyboard Key { get { throw new NotImplementedException(); } } diff --git a/Source/OpenTK/Properties/AssemblyInfo.cs b/Source/OpenTK/Properties/AssemblyInfo.cs index fc350917..75db52aa 100644 --- a/Source/OpenTK/Properties/AssemblyInfo.cs +++ b/Source/OpenTK/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("OpenTK Framework")] -[assembly: AssemblyDescription("Create OpenGL applications in C#.")] +[assembly: AssemblyTitle("OpenTK")] +[assembly: AssemblyDescription("An open-source game development toolkit for .Net/Mono")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("OpenTK.Framework")] +[assembly: AssemblyProduct("OpenTK")] [assembly: AssemblyCopyright("Copyright © 2006-2007 Stefanos Apostolopoulos")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")]