From defa7aa9c585ae77f95ff2c99b79d636f6426343 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 2 Sep 2007 00:07:40 +0000 Subject: [PATCH] Updated examples to reflect namespace change of DisplayMode and ColorMode. Renamed T03_RotatingCube.cs to T03_Immediate_Mode_Cube.cs. Renamed T07_DisplayLists_Cube.cs to T07_Display_Lists_Flower.cs. Renamed Cube.cs to W02_Immediate_Mode_Cube.cs Updated colors in T10_GLSL_Cube and T03_Immediate_Mode_Cube Add S03_Stack_Imbalance.cs test. Add T01_Simple_Window.cs and T02_Resizable_Window.cs tutorials. --- Source/Examples/Tests/S02_RawInput_Logger.cs | 2 +- Source/Examples/Tests/S03_Stack_Imbalance.cs | 67 ++++++++++++++++ Source/Examples/Tutorial/T01_Simple_Window.cs | 59 ++++++++++++++ .../Examples/Tutorial/T02_Resizable_Window.cs | 76 +++++++++++++++++++ ...tingCube.cs => T03_Immediate_Mode_Cube.cs} | 29 +++---- ...ts_Cube.cs => T07_Display_Lists_Flower.cs} | 6 +- Source/Examples/Tutorial/T10_GLSL_Cube.cs | 63 ++++++--------- Source/Examples/WinForms/W01_First_Window.cs | 2 - ...cs => W02_Immediate_Mode_Cube.Designer.cs} | 2 +- .../{Cube.cs => W02_Immediate_Mode_Cube.cs} | 62 ++++++++------- ...Cube.resx => W02_Immediate_Mode_Cube.resx} | 0 11 files changed, 275 insertions(+), 93 deletions(-) create mode 100644 Source/Examples/Tests/S03_Stack_Imbalance.cs create mode 100644 Source/Examples/Tutorial/T01_Simple_Window.cs create mode 100644 Source/Examples/Tutorial/T02_Resizable_Window.cs rename Source/Examples/Tutorial/{T03_RotatingCube.cs => T03_Immediate_Mode_Cube.cs} (83%) rename Source/Examples/Tutorial/{T07_DisplayLists_Cube.cs => T07_Display_Lists_Flower.cs} (91%) rename Source/Examples/WinForms/{Cube.Designer.cs => W02_Immediate_Mode_Cube.Designer.cs} (95%) rename Source/Examples/WinForms/{Cube.cs => W02_Immediate_Mode_Cube.cs} (93%) rename Source/Examples/WinForms/{Cube.resx => W02_Immediate_Mode_Cube.resx} (100%) diff --git a/Source/Examples/Tests/S02_RawInput_Logger.cs b/Source/Examples/Tests/S02_RawInput_Logger.cs index 21220940..a1de71d6 100644 --- a/Source/Examples/Tests/S02_RawInput_Logger.cs +++ b/Source/Examples/Tests/S02_RawInput_Logger.cs @@ -59,7 +59,7 @@ namespace Examples.Tests public S02_RawInput_Logger() { - this.CreateWindow(new OpenTK.Platform.DisplayMode(100, 100)); + this.CreateWindow(new DisplayMode(100, 100)); foreach (OpenTK.Input.Keyboard k in this.Keyboard) { diff --git a/Source/Examples/Tests/S03_Stack_Imbalance.cs b/Source/Examples/Tests/S03_Stack_Imbalance.cs new file mode 100644 index 00000000..d18daa5d --- /dev/null +++ b/Source/Examples/Tests/S03_Stack_Imbalance.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenTK; +using OpenTK.OpenGL; + +namespace Examples.Tests +{ + public class S03_Stack_Imbalance : GameWindow//, IExample + { + public S03_Stack_Imbalance() + { + this.CreateWindow(new DisplayMode(800, 600)); + } + + #region IExample Members + + public void Launch() + { + this.Run(); + } + + #endregion + + protected override void OnResize(OpenTK.Platform.ResizeEventArgs e) + { + GL.Ortho(-1.0, 1.0, -1.0, 1.0, 1.0, 32.0); + + base.OnResize(e); + } + + float[] proj = new float[16]; + public override void OnRenderFrame(EventArgs e) + { + GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT); + + GL.GetFloatv(GL.Enums.GetPName.PROJECTION_MATRIX, proj); + + float sum = 0.0f; + for (int i = 0; i < 16; i++) + { + sum += proj[i]; + } + + if (sum == 0) + { + throw new Exception("GetFloatv did not return anything!"); + } + + + GL.Begin(GL.Enums.BeginMode.TRIANGLES); + + GL.Color3(System.Drawing.Color.Chartreuse); + GL.Vertex3(-1.0, -1.0, 2.0); + GL.Color3(System.Drawing.Color.Crimson); + GL.Vertex3( 1.0, -1.0, 2.0); + GL.Color3(System.Drawing.Color.DarkGoldenrod); + GL.Vertex3( 0.0, 1.0, 2.0); + + GL.End(); + + Context.SwapBuffers(); + + base.OnRenderFrame(e); + } + } +} diff --git a/Source/Examples/Tutorial/T01_Simple_Window.cs b/Source/Examples/Tutorial/T01_Simple_Window.cs new file mode 100644 index 00000000..7a822e63 --- /dev/null +++ b/Source/Examples/Tutorial/T01_Simple_Window.cs @@ -0,0 +1,59 @@ +#region --- License --- +/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos + * See license.txt for license info + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; + +using OpenTK; +using OpenTK.OpenGL; + +namespace Examples.Tutorial +{ + public class T01_Simple_Window : GameWindow, IExample + { + public T01_Simple_Window() + { + this.CreateWindow(new DisplayMode(800, 600)); + } + + /// + /// 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! + /// + /// Not used. + public override void OnRenderFrame(EventArgs e) + { + GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT); + + GL.Begin(GL.Enums.BeginMode.TRIANGLES); + + GL.Color3(Color.SpringGreen); + GL.Vertex2(-1.0f, 1.0f); + GL.Color3(Color.SteelBlue); + GL.Vertex2(0.0f, -1.0f); + GL.Color3(Color.PeachPuff); + GL.Vertex2(1.0f, 1.0f); + + GL.End(); + + Context.SwapBuffers(); + + base.OnRenderFrame(e); + } + + #region IExample Members + + public void Launch() + { + this.Run(); + } + + #endregion + } +} diff --git a/Source/Examples/Tutorial/T02_Resizable_Window.cs b/Source/Examples/Tutorial/T02_Resizable_Window.cs new file mode 100644 index 00000000..d49e1a08 --- /dev/null +++ b/Source/Examples/Tutorial/T02_Resizable_Window.cs @@ -0,0 +1,76 @@ +#region --- License --- +/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos + * See license.txt for license info + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; + +using OpenTK; +using OpenTK.OpenGL; + +namespace Examples.Tutorial +{ + class T02_Resizable_Window : GameWindow, IExample + { + public T02_Resizable_Window() + { + 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 of frame rendering events! + /// + /// Not used. + public override void OnRenderFrame(EventArgs e) + { + GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT); + + GL.Begin(GL.Enums.BeginMode.TRIANGLES); + + GL.Color3(Color.SpringGreen); + GL.Vertex2(-1.0f, 1.0f); + GL.Color3(Color.SteelBlue); + GL.Vertex2(0.0f, -1.0f); + GL.Color3(Color.PeachPuff); + GL.Vertex2(1.0f, 1.0f); + + GL.End(); + + Context.SwapBuffers(); + + base.OnRenderFrame(e); + } + + #region IExample Members + + public void Launch() + { + this.Run(); + } + + #endregion + } +} diff --git a/Source/Examples/Tutorial/T03_RotatingCube.cs b/Source/Examples/Tutorial/T03_Immediate_Mode_Cube.cs similarity index 83% rename from Source/Examples/Tutorial/T03_RotatingCube.cs rename to Source/Examples/Tutorial/T03_Immediate_Mode_Cube.cs index f80a0145..aa0fa591 100644 --- a/Source/Examples/Tutorial/T03_RotatingCube.cs +++ b/Source/Examples/Tutorial/T03_Immediate_Mode_Cube.cs @@ -9,18 +9,18 @@ using System; using System.Collections.Generic; using System.Windows.Forms; +using System.Threading; +using System.Drawing; using OpenTK; using OpenTK.OpenGL; using OpenTK.Platform; -using Enums = OpenTK.OpenGL.GL.Enums; -using System.Threading; #endregion namespace Examples.Tutorial { - public class T03_RotatingCube : OpenTK.GameWindow, IExample + public class T03_Immediate_Mode_Cube : OpenTK.GameWindow, IExample { #region --- Fields --- @@ -33,7 +33,7 @@ namespace Examples.Tutorial #region --- Constructors --- - public T03_RotatingCube() + public T03_Immediate_Mode_Cube() { CreateWindow(new DisplayMode(800, 600)); } @@ -47,7 +47,7 @@ namespace Examples.Tutorial base.OnLoad(e); GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f); - GL.Enable(Enums.EnableCap.DEPTH_TEST); + GL.Enable(GL.Enums.EnableCap.DEPTH_TEST); } #endregion @@ -69,7 +69,7 @@ namespace Examples.Tutorial double ratio = e.Width / (double)e.Height; - GL.MatrixMode(Enums.MatrixMode.PROJECTION); + GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION); GL.LoadIdentity(); Glu.Perspective(45.0, ratio, 1.0, 64.0); } @@ -99,7 +99,7 @@ namespace Examples.Tutorial Fullscreen = !Fullscreen; } - GL.MatrixMode(Enums.MatrixMode.MODELVIEW); + GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW); GL.LoadIdentity(); Glu.LookAt( 0.0, 5.0, 5.0, @@ -120,7 +120,7 @@ namespace Examples.Tutorial /// public override void OnRenderFrame(EventArgs e) { - 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(); @@ -136,37 +136,38 @@ namespace Examples.Tutorial { GL.Begin(GL.Enums.BeginMode.QUADS); - GL.Color3(1.0f, 0.0f, 0.0f); + GL.Color3(Color.Silver); 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.0f, 1.0f, 0.0f); + GL.Color3(Color.Honeydew); 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.0f, 0.0f, 1.0f); + GL.Color3(Color.Moccasin); + 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.0f, 1.0f, 0.0f); + GL.Color3(Color.IndianRed); 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.0f, 0.0f, 1.0f); + GL.Color3(Color.PaleVioletRed); 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.0f, 1.0f, 1.0f); + GL.Color3(Color.ForestGreen); 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/Examples/Tutorial/T07_DisplayLists_Cube.cs b/Source/Examples/Tutorial/T07_Display_Lists_Flower.cs similarity index 91% rename from Source/Examples/Tutorial/T07_DisplayLists_Cube.cs rename to Source/Examples/Tutorial/T07_Display_Lists_Flower.cs index 56340fd2..d32434b7 100644 --- a/Source/Examples/Tutorial/T07_DisplayLists_Cube.cs +++ b/Source/Examples/Tutorial/T07_Display_Lists_Flower.cs @@ -23,7 +23,7 @@ using System.Threading; namespace Examples.Tutorial { - public partial class T07_DisplayLists_Cube : GameWindow, IExample + public partial class T07_Display_Lists_Flower : GameWindow, IExample { #region --- Variables --- @@ -33,9 +33,9 @@ namespace Examples.Tutorial #region --- Constructors --- - public T07_DisplayLists_Cube() + public T07_Display_Lists_Flower() { - this.CreateWindow(new OpenTK.Platform.DisplayMode(800, 600)); + this.CreateWindow(new DisplayMode(800, 600)); //Text = // "DisplayLists example (" + // GL.GetString(Enums.StringName.RENDERER) + " " + diff --git a/Source/Examples/Tutorial/T10_GLSL_Cube.cs b/Source/Examples/Tutorial/T10_GLSL_Cube.cs index 4815cd23..1b54dd32 100644 --- a/Source/Examples/Tutorial/T10_GLSL_Cube.cs +++ b/Source/Examples/Tutorial/T10_GLSL_Cube.cs @@ -50,40 +50,7 @@ namespace Examples.Tutorial public T10_GLSL_Cube() { - this.CreateWindow(new OpenTK.Platform.DisplayMode(800, 600)); - } - - #endregion - - #region public void Launch() - - /// - /// Launches this example. - /// - /// - /// Provides a simple way for the example launcher to launch the examples. - /// - public void Launch() - { - Run(); - } - - #endregion - - #region OnCreate - - /// - /// This is the place to change window parameters. - /// - /// Not used. - public override void OnCreate(EventArgs e) - { - base.OnCreate(e); - - //Text = - // GL.GetString(Enums.StringName.VENDOR) + " " + - // GL.GetString(Enums.StringName.RENDERER) + " " + - // GL.GetString(Enums.StringName.VERSION); + this.CreateWindow(new DisplayMode(800, 600)); } #endregion @@ -224,37 +191,38 @@ namespace Examples.Tutorial { GL.Begin(GL.Enums.BeginMode.QUADS); - GL.Color3(1.0f, 0.0f, 0.0f); + GL.Color3(Color.Silver); 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.0f, 1.0f, 0.0f); + GL.Color3(Color.Honeydew); 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.0f, 0.0f, 1.0f); + GL.Color3(Color.Moccasin); + 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.0f, 1.0f, 0.0f); + GL.Color3(Color.IndianRed); 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.0f, 0.0f, 1.0f); + GL.Color3(Color.PaleVioletRed); 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.0f, 1.0f, 1.0f); + GL.Color3(Color.ForestGreen); GL.Vertex3(1.0f, -1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, -1.0f); GL.Vertex3(1.0f, 1.0f, 1.0f); @@ -264,5 +232,20 @@ namespace Examples.Tutorial } #endregion + + #region public void Launch() + + /// + /// Launches this example. + /// + /// + /// Provides a simple way for the example launcher to launch the examples. + /// + public void Launch() + { + Run(); + } + + #endregion } } diff --git a/Source/Examples/WinForms/W01_First_Window.cs b/Source/Examples/WinForms/W01_First_Window.cs index 3b89e8d3..1c04f18d 100644 --- a/Source/Examples/WinForms/W01_First_Window.cs +++ b/Source/Examples/WinForms/W01_First_Window.cs @@ -34,8 +34,6 @@ namespace Examples.WinForms System.Diagnostics.Trace.WriteLine("Exception during initialization, aborting: {0}", e.ToString()); return; } - - this.ShowDialog(); } protected override void OnLoad(EventArgs e) diff --git a/Source/Examples/WinForms/Cube.Designer.cs b/Source/Examples/WinForms/W02_Immediate_Mode_Cube.Designer.cs similarity index 95% rename from Source/Examples/WinForms/Cube.Designer.cs rename to Source/Examples/WinForms/W02_Immediate_Mode_Cube.Designer.cs index 2c5293f0..c3c38928 100644 --- a/Source/Examples/WinForms/Cube.Designer.cs +++ b/Source/Examples/WinForms/W02_Immediate_Mode_Cube.Designer.cs @@ -1,6 +1,6 @@ namespace Examples.WinForms { - partial class Cube + partial class W02_Immediate_Mode_Cube { /// /// Required designer variable. diff --git a/Source/Examples/WinForms/Cube.cs b/Source/Examples/WinForms/W02_Immediate_Mode_Cube.cs similarity index 93% rename from Source/Examples/WinForms/Cube.cs rename to Source/Examples/WinForms/W02_Immediate_Mode_Cube.cs index 7094248b..83b11249 100644 --- a/Source/Examples/WinForms/Cube.cs +++ b/Source/Examples/WinForms/W02_Immediate_Mode_Cube.cs @@ -24,28 +24,51 @@ using System.Threading; namespace Examples.WinForms { - public partial class Cube : Form, IExample + public partial class W02_Immediate_Mode_Cube : Form, IExample { static float angle; #region --- Constructor --- - public Cube() + public W02_Immediate_Mode_Cube() { InitializeComponent(); - - this.ShowDialog(); } #endregion - #region Closing event + #region OnLoad + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + glControl.KeyDown += new KeyEventHandler(glControl_KeyDown); + glControl.Resize += new EventHandler(glControl_Resize); + glControl.Paint += new PaintEventHandler(glControl_Paint); + + glControl.CreateContext(); + + Text = + GL.GetString(GL.Enums.StringName.VENDOR) + " " + + GL.GetString(GL.Enums.StringName.RENDERER) + " " + + GL.GetString(GL.Enums.StringName.VERSION); + + GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f); + GL.Enable(GL.Enums.EnableCap.DEPTH_TEST); + + Application.Idle += Application_Idle; + } + + #endregion + + #region OnClosing protected override void OnClosing(CancelEventArgs e) { - base.OnClosing(e); - Application.Idle -= Application_Idle; + + base.OnClosing(e); } #endregion @@ -86,31 +109,6 @@ namespace Examples.WinForms #endregion - #region Load event handler - - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); - - glControl.KeyDown += new KeyEventHandler(glControl_KeyDown); - glControl.Resize += new EventHandler(glControl_Resize); - glControl.Paint += new PaintEventHandler(glControl_Paint); - - glControl.CreateContext(); - - Text = - GL.GetString(GL.Enums.StringName.VENDOR) + " " + - GL.GetString(GL.Enums.StringName.RENDERER) + " " + - GL.GetString(GL.Enums.StringName.VERSION); - - GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f); - GL.Enable(GL.Enums.EnableCap.DEPTH_TEST); - - Application.Idle += Application_Idle; - } - - #endregion - #region GLControl.Resize event handler void glControl_Resize(object sender, EventArgs e) diff --git a/Source/Examples/WinForms/Cube.resx b/Source/Examples/WinForms/W02_Immediate_Mode_Cube.resx similarity index 100% rename from Source/Examples/WinForms/Cube.resx rename to Source/Examples/WinForms/W02_Immediate_Mode_Cube.resx