diff --git a/Source/Examples/ExampleLauncher.cs b/Source/Examples/ExampleLauncher.cs
index 0edfaea0..62ad62e1 100644
--- a/Source/Examples/ExampleLauncher.cs
+++ b/Source/Examples/ExampleLauncher.cs
@@ -64,6 +64,8 @@ namespace Examples
#endregion
+ #region public void ExampleLauncher_Load(object sender, EventArgs e)
+
public void ExampleLauncher_Load(object sender, EventArgs e)
{
try
@@ -119,27 +121,7 @@ namespace Examples
this.listBox1.SelectedIndex = 0;
}
- void LaunchGameWindow(object example)
- {
- Type ex = example as Type;
- try
- {
- using (GameWindow gw = (GameWindow)(ex.GetConstructor(Type.EmptyTypes).Invoke(null)))
- {
- (gw as IExample).Launch();
- }
-
- }
- catch (Exception expt)
- {
- if (expt.InnerException != null)
- MessageBox.Show(expt.InnerException.ToString(), "An error has occured: \"" + expt.InnerException.Message + "\"",
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- else
- MessageBox.Show(expt.ToString(), "An error has occured: \"" + expt.Message + "\"",
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
+ #endregion
private void RunExample()
{
@@ -150,36 +132,43 @@ namespace Examples
Debug.Print("Launching example: {0}", example.ToString());
this.Visible = false;
- if (example.BaseType == typeof(GameWindow))
+ try
{
- LaunchGameWindow(example);
- }
- else if (example.BaseType == typeof(Form))
- {
- try
+ if (example.BaseType == typeof(GameWindow))
+ {
+ using (GameWindow gw = (GameWindow)(example.GetConstructor(Type.EmptyTypes).Invoke(null)))
+ {
+ (gw as IExample).Launch();
+ }
+ }
+ else if (example.BaseType == typeof(Form))
{
using (Form f = (Form)example.GetConstructor(Type.EmptyTypes).Invoke(null))
{
f.ShowDialog(this);
}
}
- catch (Exception expt)
+ else
{
- MessageBox.Show(
- String.Format(
- "Stacktrace:{0}{1}{0}{0}Inner exception:{0}{2}",
- System.Environment.NewLine,
- expt.StackTrace,
- expt.InnerException
- ),
- expt.Message);
+ // Console application.
+ IExample ex = (IExample)example.GetConstructor(Type.EmptyTypes).Invoke(null);
+ ex.Launch();
}
+
}
- else
+ catch (Exception expt)
{
- // Console application.
- IExample ex = (IExample)example.GetConstructor(Type.EmptyTypes).Invoke(null);
- ex.Launch();
+#if DEBUG
+ throw;
+#else
+ if (expt.InnerException != null)
+ MessageBox.Show(expt.InnerException.ToString(), "An error has occured: \"" +
+ expt.InnerException.Message + "\"", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ else
+ MessageBox.Show(expt.ToString(), "An error has occured: \"" + expt.Message + "\"",
+ MessageBoxButtons.OK, MessageBoxIcon.Warning);
+#endif
+
}
GC.Collect();
diff --git a/Source/Examples/Tests/S01_Call_Performance.cs b/Source/Examples/Tests/S01_Call_Performance.cs
index e10b4a1e..0de341a2 100644
--- a/Source/Examples/Tests/S01_Call_Performance.cs
+++ b/Source/Examples/Tests/S01_Call_Performance.cs
@@ -13,6 +13,7 @@ using System.Windows.Forms;
using OpenTK.OpenGL;
using System.Security;
+using OpenTK.OpenGL.Enums;
namespace Examples.Tests
{
@@ -92,10 +93,7 @@ namespace Examples.Tests
Trace.Write("Timing OpenTK.OpenGL core functions (void*): ");
timer.Start();
for (int i = 0; ++i < num_calls; )
- {
- GL.CallLists(v.Length, GL.Enums.ListNameType.FLOAT, v);
-
- }
+ GL.CallLists(v.Length, ListNameType.Float, v);
timer.Stop();
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
timer.Reset();
@@ -103,9 +101,8 @@ namespace Examples.Tests
Trace.Write("Timing OpenTK.OpenGL extension functions: ");
timer.Start();
for (int i = 0; ++i < num_calls; )
- {
- GL.ARB.ActiveTexture(GL.Enums.ARB_multitexture.TEXTURE0_ARB);
- }
+ GL.Arb.ActiveTexture(ArbMultitexture.Texture0Arb);
+
timer.Stop();
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
timer.Reset();
@@ -139,7 +136,7 @@ namespace Examples.Tests
timer.Start();
for (int i = 0; ++i < num_calls; )
{
- glCallLists(v.Length, GL.Enums.ListNameType.FLOAT, v);
+ glCallLists(v.Length, ListNameType.Float, v);
}
timer.Stop();
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
@@ -168,7 +165,7 @@ namespace Examples.Tests
extern static void glVertex2fv(float[] v);
[DllImport("opengl32.dll", EntryPoint = "glCallLists"), SuppressUnmanagedCodeSecurity]
- extern static void glCallLists(int count, GL.Enums.ListNameType type, object lists);
+ extern static void glCallLists(int count, ListNameType type, object lists);
}
}
diff --git a/Source/Examples/Tutorial/Fonts.cs b/Source/Examples/Tutorial/Fonts.cs
index 9790f326..44c53c73 100644
--- a/Source/Examples/Tutorial/Fonts.cs
+++ b/Source/Examples/Tutorial/Fonts.cs
@@ -14,6 +14,7 @@ using OpenTK.Fonts;
using OpenTK.OpenGL;
using OpenTK.Input;
using System.IO;
+using OpenTK.OpenGL.Enums;
namespace Examples.Tutorial
{
@@ -36,9 +37,9 @@ namespace Examples.Tutorial
public override void OnLoad(EventArgs e)
{
- GL.Enable(GL.Enums.EnableCap.TEXTURE_2D);
- GL.Enable(GL.Enums.EnableCap.BLEND);
- GL.BlendFunc(GL.Enums.BlendingFactorSrc.SRC_ALPHA, GL.Enums.BlendingFactorDest.ONE_MINUS_SRC_ALPHA);
+ GL.Enable(EnableCap.Texture2d);
+ GL.Enable(EnableCap.Blend);
+ GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
//serif.LoadGlyphs("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz,.!?;()\'- ");
serif.LoadGlyphs("A");
@@ -92,13 +93,13 @@ namespace Examples.Tutorial
current_position = initial_position;
scroll_position = current_position;
- GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT);
+ GL.Clear(ClearBufferMask.ColorBufferBit);
- GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
+ GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(0.0, Width, Height, 0.0, 0.0, 1.0);
- GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW);
+ GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.Translate(0.0f, scroll_position, 0.0f);
@@ -110,13 +111,13 @@ namespace Examples.Tutorial
int texture;
serif.GlyphData('A', ref rect, out width, out height, out texture);
- GL.BindTexture(GL.Enums.TextureTarget.TEXTURE_2D, texture);
+ GL.BindTexture(TextureTarget.Texture2d, texture);
- GL.Enable(GL.Enums.EnableCap.BLEND);
- GL.BlendFunc(GL.Enums.BlendingFactorSrc.SRC_ALPHA, GL.Enums.BlendingFactorDest.ONE_MINUS_SRC_ALPHA);
+ GL.Enable(EnableCap.Blend);
+ GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
//GL.Color4(Color.White);
- GL.Begin(GL.Enums.BeginMode.QUADS);
+ GL.Begin(BeginMode.Quads);
GL.TexCoord2(rect.Left, rect.Top);
GL.Vertex2(0.0, 0.0);
diff --git a/Source/Examples/Tutorial/T01_Simple_Window.cs b/Source/Examples/Tutorial/T01_Simple_Window.cs
index 8e991026..79c1d927 100644
--- a/Source/Examples/Tutorial/T01_Simple_Window.cs
+++ b/Source/Examples/Tutorial/T01_Simple_Window.cs
@@ -13,6 +13,7 @@ using System.Diagnostics;
using OpenTK;
using OpenTK.OpenGL;
using OpenTK.Fonts;
+using OpenTK.OpenGL.Enums;
namespace Examples.Tutorial
{
@@ -22,10 +23,7 @@ namespace Examples.Tutorial
public class T01_Simple_Window : GameWindow, IExample
{
public T01_Simple_Window() : base(new DisplayMode(800, 600), "OpenTK | Tutorial 1: Simple Window")
- {
- }
-
- TextureFont sans = new TextureFont(new Font(FontFamily.GenericSansSerif, 16.0f));
+ { }
#region OnLoad
@@ -51,7 +49,7 @@ namespace Examples.Tutorial
{
GL.Viewport(0, 0, e.Width, e.Height);
- GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
+ GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);
@@ -86,9 +84,9 @@ namespace Examples.Tutorial
/// There is no need to call the base implementation.
public override void OnRenderFrame(RenderFrameEventArgs e)
{
- GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT);
- /*
- GL.Begin(GL.Enums.BeginMode.TRIANGLES);
+ GL.Clear(ClearBufferMask.ColorBufferBit);
+
+ GL.Begin(BeginMode.Triangles);
GL.Color3(Color.SpringGreen);
GL.Vertex2(-1.0f, 1.0f);
@@ -99,19 +97,6 @@ namespace Examples.Tutorial
GL.End();
- GL.PushMatrix();
- */
- GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW);
- GL.LoadIdentity();
- GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 1.0);
- GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
- GL.LoadIdentity();
- GL.Translate(0.7f, 1.0f, 0.0f);
-
- //sans.Print(RenderPeriod.ToString());
-
- //GL.PopMatrix();
-
this.SwapBuffers();
}
diff --git a/Source/Examples/Tutorial/T02_Vertex_Arrays.cs b/Source/Examples/Tutorial/T02_Vertex_Arrays.cs
index 3757fda3..49a9183a 100644
--- a/Source/Examples/Tutorial/T02_Vertex_Arrays.cs
+++ b/Source/Examples/Tutorial/T02_Vertex_Arrays.cs
@@ -15,6 +15,7 @@ using OpenTK.OpenGL;
using System.Diagnostics;
using OpenTK.Input;
using OpenTK.Fonts;
+using OpenTK.OpenGL.Enums;
namespace Examples.Tutorial
{
@@ -27,7 +28,8 @@ namespace Examples.Tutorial
float angle = 0.0f;
Shapes.Shape shape = new Examples.Shapes.Plane(16, 16, 2.0f, 2.0f);
- TextureFont sans = new TextureFont(new Font(FontFamily.GenericSansSerif, 32, FontStyle.Regular, GraphicsUnit.Pixel));
+ TextureFont sans = new TextureFont(new Font(FontFamily.GenericSansSerif, 32, FontStyle.Regular,
+ GraphicsUnit.Pixel));
#region Constructor
@@ -57,14 +59,14 @@ namespace Examples.Tutorial
public override void OnLoad(EventArgs e)
{
- GL.Enable(GL.Enums.EnableCap.TEXTURE_2D);
+ GL.Enable(EnableCap.Texture2d);
GL.ClearColor(Color.CadetBlue);
- GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
+ GL.Enable(EnableCap.DepthTest);
- GL.EnableClientState(GL.Enums.EnableCap.VERTEX_ARRAY);
+ GL.EnableClientState(EnableCap.VertexArray);
//GL.EnableClientState(GL.Enums.EnableCap.COLOR_ARRAY);
- GL.VertexPointer(3, GL.Enums.VertexPointerType.FLOAT, 0, shape.Vertices);
+ GL.VertexPointer(3, VertexPointerType.Float, 0, shape.Vertices);
//GL.ColorPointer(4, GL.Enums.ColorPointerType.UNSIGNED_BYTE, 0, shape.Colors);
}
@@ -87,7 +89,7 @@ namespace Examples.Tutorial
double ratio = e.Width / (double)e.Height;
- GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
+ GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
Glu.Perspective(45.0, ratio, 1.0, 64.0);
}
@@ -139,9 +141,9 @@ namespace Examples.Tutorial
///
public override void OnRenderFrame(RenderFrameEventArgs e)
{
- GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT | GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
+ GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
- GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW);
+ GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
Glu.LookAt(
0.0, 5.0, 5.0,
@@ -155,10 +157,8 @@ namespace Examples.Tutorial
angle -= 360.0f;
GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
- GL.DrawElements(GL.Enums.BeginMode.TRIANGLES, shape.Indices.Length,
- GL.Enums.All.UNSIGNED_INT, shape.Indices);
-
-// GL.DrawArrays(GL.Enums.BeginMode.LINES, 0, shape.Vertices.Length);
+ GL.DrawElements(BeginMode.Triangles, shape.Indices.Length,
+ All.UnsignedInt, shape.Indices);
//GL.Begin(GL.Enums.BeginMode.TRIANGLES);
@@ -170,10 +170,10 @@ namespace Examples.Tutorial
GL.PushMatrix();
- GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
+ GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 1.0);
- GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW);
+ GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
//GL.Translate(0.7f, 1.0f, 0.0f);
diff --git a/Source/Examples/Tutorial/T03_Immediate_Mode_Cube.cs b/Source/Examples/Tutorial/T03_Immediate_Mode_Cube.cs
index ad00a291..27b94893 100644
--- a/Source/Examples/Tutorial/T03_Immediate_Mode_Cube.cs
+++ b/Source/Examples/Tutorial/T03_Immediate_Mode_Cube.cs
@@ -14,6 +14,7 @@ using System.Drawing;
using OpenTK;
using OpenTK.OpenGL;
+using OpenTK.OpenGL.Enums;
using OpenTK.Platform;
#endregion
@@ -36,13 +37,11 @@ namespace Examples.Tutorial
#region --- Constructors ---
- public T03_Immediate_Mode_Cube()
- {
- CreateWindow(new DisplayMode(800, 600));
- }
-
- #endregion
+ public T03_Immediate_Mode_Cube() : base(new DisplayMode(800, 600), "OpenTK Tutorial: Immediate mode rendering")
+ { }
+ #endregion
+
#region OnLoad
public override void OnLoad(EventArgs e)
@@ -50,7 +49,7 @@ namespace Examples.Tutorial
base.OnLoad(e);
GL.ClearColor(Color.MidnightBlue);
- GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
+ GL.Enable(EnableCap.DepthTest);
}
#endregion
@@ -72,7 +71,7 @@ namespace Examples.Tutorial
double ratio = e.Width / (double)e.Height;
- GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
+ GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
Glu.Perspective(45.0, ratio, 1.0, 64.0);
}
@@ -117,15 +116,14 @@ namespace Examples.Tutorial
///
public override void OnRenderFrame(RenderFrameEventArgs e)
{
- GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT | GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
+ GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
- GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW);
+ GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
- Glu.LookAt(
- 0.0, 5.0, 5.0,
- 0.0, 0.0, 0.0,
- 0.0, 1.0, 0.0
- );
+ Glu.LookAt(0.0, 5.0, 5.0,
+ 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0);
+
GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
DrawCube();
@@ -140,7 +138,7 @@ namespace Examples.Tutorial
private void DrawCube()
{
- GL.Begin(GL.Enums.BeginMode.QUADS);
+ GL.Begin(BeginMode.Quads);
GL.Color3(Color.Silver);
GL.Vertex3(-1.0f, -1.0f, -1.0f);
diff --git a/Source/Examples/Tutorial/T04_Vertex_Lighting.cs b/Source/Examples/Tutorial/T04_Vertex_Lighting.cs
index a85b220b..23527d05 100644
--- a/Source/Examples/Tutorial/T04_Vertex_Lighting.cs
+++ b/Source/Examples/Tutorial/T04_Vertex_Lighting.cs
@@ -12,6 +12,7 @@ using System.Drawing;
using OpenTK;
using OpenTK.OpenGL;
using Examples.Shapes;
+using OpenTK.OpenGL.Enums;
namespace Examples.Tutorial
{
@@ -38,31 +39,31 @@ namespace Examples.Tutorial
base.OnLoad(e);
GL.ClearColor(Color.MidnightBlue);
- GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
+ GL.Enable(EnableCap.DepthTest);
//GL.Enable(GL.Enums.EnableCap.CULL_FACE);
- GL.EnableClientState(GL.Enums.EnableCap.VERTEX_ARRAY);
- GL.EnableClientState(GL.Enums.EnableCap.NORMAL_ARRAY);
- GL.VertexPointer(3, GL.Enums.VertexPointerType.FLOAT, 0, shape.Vertices);
- GL.NormalPointer(GL.Enums.NormalPointerType.FLOAT, 0, shape.Normals);
+ GL.EnableClientState(EnableCap.VertexArray);
+ GL.EnableClientState(EnableCap.NormalArray);
+ GL.VertexPointer(3, VertexPointerType.Float, 0, shape.Vertices);
+ GL.NormalPointer(NormalPointerType.Float, 0, shape.Normals);
// Enable Light 0 and set its parameters.
- GL.Lightv(GL.Enums.LightName.LIGHT0, GL.Enums.LightParameter.POSITION, new float[] { 1.0f, 1.0f, -0.5f });
- GL.Lightv(GL.Enums.LightName.LIGHT0, GL.Enums.LightParameter.AMBIENT, new float[] { 0.3f, 0.3f, 0.3f, 1.0f });
- GL.Lightv(GL.Enums.LightName.LIGHT0, GL.Enums.LightParameter.DIFFUSE, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
- GL.Lightv(GL.Enums.LightName.LIGHT0, GL.Enums.LightParameter.SPECULAR, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
- GL.Lightv(GL.Enums.LightName.LIGHT0, GL.Enums.LightParameter.SPOT_EXPONENT, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
- GL.LightModelv(GL.Enums.LightModelParameter.LIGHT_MODEL_AMBIENT, new float[] { 0.2f, 0.2f, 0.2f, 1.0f });
- GL.LightModel(GL.Enums.LightModelParameter.LIGHT_MODEL_TWO_SIDE, 1);
- GL.LightModel(GL.Enums.LightModelParameter.LIGHT_MODEL_LOCAL_VIEWER, 1);
- GL.Enable(GL.Enums.EnableCap.LIGHTING);
- GL.Enable(GL.Enums.EnableCap.LIGHT0);
+ GL.Lightv(LightName.Light0, LightParameter.Position, new float[] { 1.0f, 1.0f, -0.5f });
+ GL.Lightv(LightName.Light0, LightParameter.Ambient, new float[] { 0.3f, 0.3f, 0.3f, 1.0f });
+ GL.Lightv(LightName.Light0, LightParameter.Diffuse, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
+ GL.Lightv(LightName.Light0, LightParameter.Specular, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
+ GL.Lightv(LightName.Light0, LightParameter.SpotExponent, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
+ GL.LightModelv(LightModelParameter.LightModelAmbient, new float[] { 0.2f, 0.2f, 0.2f, 1.0f });
+ GL.LightModel(LightModelParameter.LightModelTwoSide, 1);
+ GL.LightModel(LightModelParameter.LightModelLocalViewer, 1);
+ GL.Enable(EnableCap.Lighting);
+ GL.Enable(EnableCap.Light0);
- // Use GL.Material to set your object's material parameters..
- GL.Materialv(GL.Enums.MaterialFace.FRONT, GL.Enums.MaterialParameter.AMBIENT, new float[] { 0.3f, 0.3f, 0.3f, 1.0f });
- GL.Materialv(GL.Enums.MaterialFace.FRONT, GL.Enums.MaterialParameter.DIFFUSE, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
- GL.Materialv(GL.Enums.MaterialFace.FRONT, GL.Enums.MaterialParameter.SPECULAR, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
- GL.Materialv(GL.Enums.MaterialFace.FRONT, GL.Enums.MaterialParameter.EMISSION, new float[] { 0.0f, 0.0f, 0.0f, 1.0f });
+ // Use GL.Material to set your object's material parameters.
+ GL.Materialv(MaterialFace.Front, MaterialParameter.Ambient, new float[] { 0.3f, 0.3f, 0.3f, 1.0f });
+ GL.Materialv(MaterialFace.Front, MaterialParameter.Diffuse, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
+ GL.Materialv(MaterialFace.Front, MaterialParameter.Specular, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
+ GL.Materialv(MaterialFace.Front, MaterialParameter.Emission, new float[] { 0.0f, 0.0f, 0.0f, 1.0f });
}
#endregion
@@ -84,7 +85,7 @@ namespace Examples.Tutorial
double ratio = e.Width / (double)e.Height;
- GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
+ GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
Glu.Perspective(45.0, ratio, 1.0, 64.0);
}
@@ -139,18 +140,18 @@ namespace Examples.Tutorial
///
public override void OnRenderFrame(RenderFrameEventArgs e)
{
- GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT | GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
+ GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
- GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW);
+ GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
- Glu.LookAt(
- 0.0, 0.0, -7.5 + zoom,
- 0.0, 0.0, 0.0,
- 0.0, 1.0, 0.0);
+ Glu.LookAt(0.0, 0.0, -7.5 + zoom,
+ 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0);
GL.Rotate(x_angle, 0.0f, 1.0f, 0.0f);
- GL.DrawElements(GL.Enums.BeginMode.TRIANGLES, shape.Indices.Length,
- GL.Enums.All.UNSIGNED_INT, shape.Indices);
+ //GL.DrawElements(GL.Enums.BeginMode.TRIANGLES, shape.Indices.Length,
+ // GL.Enums.All.UNSIGNED_INT, shape.Indices);
+ GL.DrawArrays(BeginMode.Points, 0, shape.Vertices.Length);
SwapBuffers();
}
diff --git a/Source/Examples/Tutorial/T07_Display_Lists_Flower.cs b/Source/Examples/Tutorial/T07_Display_Lists_Flower.cs
index 8bc25aa4..1f9587d0 100644
--- a/Source/Examples/Tutorial/T07_Display_Lists_Flower.cs
+++ b/Source/Examples/Tutorial/T07_Display_Lists_Flower.cs
@@ -13,12 +13,12 @@ using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
-
-using OpenTK.OpenGL;
-using Enums = OpenTK.OpenGL.GL.Enums;
-using OpenTK;
using System.Threading;
+using OpenTK;
+using OpenTK.OpenGL;
+using OpenTK.OpenGL.Enums;
+
#endregion --- Using Directives ---
namespace Examples.Tutorial
@@ -46,9 +46,9 @@ namespace Examples.Tutorial
public override void OnLoad(EventArgs e)
{
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
- GL.Enable(Enums.EnableCap.DEPTH_TEST);
+ GL.Enable(EnableCap.DepthTest);
- GL.MatrixMode(Enums.MatrixMode.MODELVIEW);
+ GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
// Build some display lists.
@@ -57,7 +57,7 @@ namespace Examples.Tutorial
for (int i = 0; i < num_lists; i++)
{
lists[i] = first_list + i;
- GL.NewList(first_list + i, Enums.ListMode.COMPILE);
+ GL.NewList(first_list + i, ListMode.Compile);
GL.Color3(1.0, c, 1 - c);
@@ -66,7 +66,7 @@ namespace Examples.Tutorial
GL.Rotate(c * 360.0f, 0.0, 0.0, 1.0);
GL.Translate(5.0, 0.0, 0.0);
- GL.Begin(Enums.BeginMode.QUADS);
+ GL.Begin(BeginMode.Quads);
GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3(1.0f, -1.0f, 1.0f);
@@ -103,7 +103,7 @@ namespace Examples.Tutorial
double ratio = 0.0;
ratio = this.Width / (double)this.Height;
- GL.MatrixMode(Enums.MatrixMode.PROJECTION);
+ GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
Glu.Perspective(45.0, ratio, 1.0, 64.0);
}
@@ -126,15 +126,15 @@ namespace Examples.Tutorial
public override void OnRenderFrame(RenderFrameEventArgs e)
{
- GL.MatrixMode(Enums.MatrixMode.MODELVIEW);
+ GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
Glu.LookAt(
0.0, 0.0, 16.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
- GL.Clear(Enums.ClearBufferMask.COLOR_BUFFER_BIT | Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
- GL.CallLists(num_lists, Enums.ListNameType.INT, lists);
+ GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
+ GL.CallLists(num_lists, ListNameType.Int, lists);
SwapBuffers();
}
diff --git a/Source/Examples/Tutorial/T08_VBO.cs b/Source/Examples/Tutorial/T08_VBO.cs
index 82c3076f..5a0a9ab2 100644
--- a/Source/Examples/Tutorial/T08_VBO.cs
+++ b/Source/Examples/Tutorial/T08_VBO.cs
@@ -14,71 +14,31 @@ using OpenTK;
using OpenTK.OpenGL;
using OpenTK.Platform;
using System.Threading;
+using OpenTK.OpenGL.Enums;
#endregion
namespace Examples.Tutorial
{
- public class T08_VBO : OpenTK.GameWindow /*, IExample */
+ public class T08_VBO : GameWindow, IExample
{
#region --- Private Fields ---
- int vbo, ibo, nbo; // vertex, index and normal buffer objects.
+ Shapes.Shape shape = new Examples.Shapes.Cube();
+ //new Examples.Shapes.Plane(16, 16, 2.0f, 2.0f);
+
+ int handle_vertex_buffer, ibo, nbo; // vertex, index and normal buffer objects.
float angle;
- // Cube vertices
- float[] vdata =
- {
- -1.0f, -1.0f, 1.0f ,
- 1.0f, -1.0f, 1.0f ,
- 1.0f, 1.0f, 1.0f ,
- -1.0f, 1.0f, 1.0f ,
- -1.0f, -1.0f, -1.0f ,
- 1.0f, -1.0f, -1.0f ,
- 1.0f, 1.0f, -1.0f ,
- -1.0f, 1.0f, -1.0f ,
- };
-
- // Cube normals
- float[,] ndata =
- {
- { 1.0f, 0.0f, 0.0f },
- { 0.0f, 1.0f, 0.0f },
- { 0.0f, 0.0f, 1.0f },
- { -1.0f, 0.0f, 0.0f },
- { 0.0f, -1.0f, 0.0f },
- { 0.0f, 0.0f, -1.0f },
- };
-
- // Indices
- ushort[] idata =
- {
- // front face
- 0, 1, 2, 3,
- // top face
- 3, 4, 6, 7,
- // back face
- 7, 6, 5, 4,
- // left face
- 4, 0, 3, 7,
- // bottom face
- 0, 1, 5, 4,
- // right face
- 1, 5, 6, 2,
- };
-
#endregion
#region --- Constructor ---
- public T08_VBO()
- {
- this.CreateWindow(new DisplayMode(800, 600));
- }
+ public T08_VBO() : base(new DisplayMode(800, 600), "OpenTK Tutorial 08: Vertex Buffer Objects") { }
#endregion
- #region OnLoad
+ #region OnLoad override
public override void OnLoad(EventArgs e)
{
@@ -92,35 +52,56 @@ namespace Examples.Tutorial
}
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
- GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
- GL.EnableClientState(GL.Enums.EnableCap.VERTEX_ARRAY);
- GL.EnableClientState(GL.Enums.EnableCap.INDEX_ARRAY);
+ GL.Enable(EnableCap.DepthTest);
+ GL.EnableClientState(EnableCap.VertexArray);
+ //GL.EnableClientState(GL.Enums.EnableCap.INDEX_ARRAY);
- LoadCube();
+ // Create the Vertex Buffer Object:
+ // 1) Generate the buffer handles.
+ // 2) Bind the Vertex Buffer and upload your vertex data. Check that the data was uploaded correctly.
+ // 3) Bind the Index Buffer and upload your index data. Check that the data was uploaded correctly.
- this.OnResize(new ResizeEventArgs(this.Width, this.Height));
+ int size; // To check whether the buffers were uploaded correctly.
+
+ // Generate handles.
+ GL.GenBuffers(1, out handle_vertex_buffer);
+ //GL.GenBuffers(1, out ibo);
+
+ // Upload the vertex data.
+ GL.BindBuffer(Version15.ArrayBuffer, handle_vertex_buffer);
+ GL.BufferData(Version15.ArrayBuffer, (IntPtr)shape.Vertices.Length, shape.Vertices, Version15.StaticDraw);
+ GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
+ GL.GetBufferParameter(Version15.ArrayBuffer, Version15.BufferSize, out size);
+ if (shape.Vertices.Length != size)
+ throw new ApplicationException("Vertex array not uploaded correctly");
+ /*
+ // Upload the index data.
+ GL.BindBuffer(GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER, ibo);
+ GL.BufferData(GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER, (IntPtr)shape.Indices.Length, shape.Indices, GL.Enums.VERSION_1_5.STATIC_DRAW);
+ GL.GetBufferParameter(GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER, GL.Enums.VERSION_1_5.BUFFER_SIZE, out size);
+ if (shape.Indices.Length != size)
+ throw new ApplicationException("Index array not uploaded correctly");
+ */
}
#endregion
- #region OnResize
+ #region OnResize override
- protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
+ protected override void OnResize(ResizeEventArgs e)
{
- base.OnResize(e);
-
GL.Viewport(0, 0, Width, Height);
double ratio = e.Width / (double)e.Height;
- GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
+ GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
Glu.Perspective(45.0, ratio, 1.0, 64.0);
}
#endregion
- #region OnUpdateFrame
+ #region OnUpdateFrame override
///
/// Prepares the next frame for rendering.
@@ -132,21 +113,7 @@ namespace Examples.Tutorial
public override void OnUpdateFrame(UpdateFrameEventArgs e)
{
if (Keyboard[OpenTK.Input.Key.Escape])
- {
this.Exit();
- return;
- }
-
- GL.MatrixMode(GL.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.5f;
}
#endregion
@@ -157,74 +124,21 @@ namespace Examples.Tutorial
{
base.OnRenderFrame(e);
- GL.Clear(
- GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT |
- GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
+ GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
- GL.BindBuffer(GL.Enums.VERSION_1_5.ARRAY_BUFFER, vbo);
- GL.VertexPointer(3, GL.Enums.VertexPointerType.FLOAT, 0, 0);
-
- GL.BindBuffer(GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER, ibo);
- GL.IndexPointer(GL.Enums.IndexPointerType.FLOAT, 0, 0);
+ GL.MatrixMode(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.Color3(1.0f, 1.0f, 1.0f);
- GL.DrawElements(
- GL.Enums.BeginMode.QUADS,
- idata.Length,
- GL.Enums.All.UNSIGNED_SHORT,
- idata);
-
- GL.BindBuffer(GL.Enums.VERSION_1_5.ARRAY_BUFFER, 0);
- GL.BindBuffer(GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER, 0);
+ GL.DrawElements(BeginMode.Triangles, shape.Indices.Length,
+ All.UnsignedInt, shape.Indices);
Context.SwapBuffers();
- Thread.Sleep(0);
- }
-
- #endregion
-
- #region LoadCube
-
- private void LoadCube()
- {
- int size; // To check whether the buffers were uploaded correctly.
- //GL.
- // First, generate the buffer objects
- GL.GenBuffers(1, out vbo);
- GL.GenBuffers(1, out ibo);
-
- // Upload the vertex data
- GL.BindBuffer(GL.Enums.VERSION_1_5.ARRAY_BUFFER, vbo);
- GL.BufferData(
- GL.Enums.VERSION_1_5.ARRAY_BUFFER,
- (IntPtr)(vdata.Length * 4),
- vdata,
- GL.Enums.VERSION_1_5.STATIC_DRAW);
- GL.GetBufferParameter(
- GL.Enums.VERSION_1_5.ARRAY_BUFFER,
- GL.Enums.VERSION_1_5.BUFFER_SIZE,
- out size);
- if (vdata.Length * 4 != size)
- {
- throw new ApplicationException("Vertex array not uploaded correctly");
- }
-
- // Upload the index data
- GL.BindBuffer(GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER, ibo);
- GL.BufferData(
- GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER,
- (IntPtr)(idata.Length * 2),
- idata,
- GL.Enums.VERSION_1_5.STATIC_DRAW
- );
- GL.GetBufferParameter(
- GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER,
- GL.Enums.VERSION_1_5.BUFFER_SIZE,
- out size);
- if (idata.Length * 2 != size)
- {
- throw new ApplicationException("Index array not uploaded correctly");
- }
}
#endregion
diff --git a/Source/Examples/Tutorial/T10_GLSL_Cube.cs b/Source/Examples/Tutorial/T10_GLSL_Cube.cs
index 7de25f2d..6d6dee46 100644
--- a/Source/Examples/Tutorial/T10_GLSL_Cube.cs
+++ b/Source/Examples/Tutorial/T10_GLSL_Cube.cs
@@ -16,6 +16,9 @@ using System.Threading;
using OpenTK.OpenGL;
using OpenTK;
+using System.Diagnostics;
+using System.IO;
+using OpenTK.OpenGL.Enums;
#endregion --- Using Directives ---
@@ -28,31 +31,12 @@ namespace Examples.Tutorial
{
#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;
-}
-"};
-
- #endregion
-
- static float angle;
+ static float angle = 0.0f, rotation_speed = 3.0f;
int vertex_shader_object, fragment_shader_object, shader_program;
+ int vertex_buffer_object, color_buffer_object, element_buffer_object;
- Shapes.Cube shape = new Examples.Shapes.Cube();
+ Shapes.Shape shape = //new Examples.Shapes.Plane(8, 8, 4.0f, 4.0f);
+ new Examples.Shapes.Cube();
#endregion
@@ -74,8 +58,6 @@ void main()
/// Not used.
public override void OnLoad(EventArgs e)
{
- base.OnLoad(e);
-
// Check for necessary capabilities:
if (!GL.SupportsExtension("VERSION_2_0"))
{
@@ -86,43 +68,58 @@ void main()
}
GL.ClearColor(Color.MidnightBlue);
- GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
+ GL.Enable(EnableCap.DepthTest);
- GL.EnableClientState(GL.Enums.EnableCap.VERTEX_ARRAY);
- GL.EnableClientState(GL.Enums.EnableCap.COLOR_ARRAY);
- GL.VertexPointer(3, GL.Enums.VertexPointerType.FLOAT, 0, shape.Vertices);
- GL.ColorPointer(4, GL.Enums.ColorPointerType.UNSIGNED_BYTE, 0, shape.Colors);
+ CreateVBO();
- int status;
+ //CreateShader();
- vertex_shader_object = GL.CreateShader(GL.Enums.VERSION_2_0.VERTEX_SHADER);
- fragment_shader_object = GL.CreateShader(GL.Enums.VERSION_2_0.FRAGMENT_SHADER);
+ int status_code, status_text_length;
+ StringBuilder info = new StringBuilder();
- unsafe { GL.ShaderSource(vertex_shader_object, vertex_shader_source.Length, vertex_shader_source, (int*)null); }
+ vertex_shader_object = GL.CreateShader(Version20.VertexShader);
+ fragment_shader_object = GL.CreateShader(Version20.FragmentShader);
+
+ using (StreamReader sr = new StreamReader("Data/Shaders/Simple_VS.glsl"))
+ {
+ string[] code = new string[] { sr.ReadToEnd() };
+#if MONO
+ unsafe { GL.ShaderSource(vertex_shader_object, vertex_shader_source.Length, vertex_shader_source, (int*)null); }
+#else
+ GL.ShaderSource(vertex_shader_object, code.Length, code, (int[])null);
+#endif
+ }
GL.CompileShader(vertex_shader_object);
- GL.GetShader(vertex_shader_object, GL.Enums.VERSION_2_0.COMPILE_STATUS, out status);
- if (status != (int)GL.Enums.Boolean.TRUE)
- {
- int length = 0;
- GL.GetShader(vertex_shader_object, GL.Enums.VERSION_2_0.INFO_LOG_LENGTH, out length);
- StringBuilder info = new StringBuilder(length);
- GL.GetShaderInfoLog(vertex_shader_object, info.Capacity, out length, info);
-
+ GL.GetShader(vertex_shader_object, Version20.CompileStatus, out status_code);
+ GL.GetShader(vertex_shader_object, Version20.InfoLogLength, out status_text_length);
+ info.Remove(0, info.Length);
+ info.EnsureCapacity(status_text_length);
+ GL.GetShaderInfoLog(vertex_shader_object, info.Capacity, out status_text_length, info);
+ Trace.WriteLine(info.ToString());
+
+ if (status_code != 1)
throw new Exception(info.ToString());
- }
- unsafe { GL.ShaderSource(fragment_shader_object, fragment_shader_source.Length, fragment_shader_source, (int*)null); }
+ using (StreamReader sr = new StreamReader("Data/Shaders/Simple_FS.glsl"))
+ {
+ string[] code = new string[] { sr.ReadToEnd() };
+#if MONO
+ unsafe { GL.ShaderSource(fragment_shader_object, fragment_shader_source.Length, fragment_shader_source, (int*)null); }
+#else
+ GL.ShaderSource(fragment_shader_object, code.Length, code, (int[])null);
+#endif
+ }
+
GL.CompileShader(fragment_shader_object);
- GL.GetShader(fragment_shader_object, GL.Enums.VERSION_2_0.COMPILE_STATUS, out status);
- if (status != (int)GL.Enums.Boolean.TRUE)
- {
- int length;
- GL.GetShader(vertex_shader_object, GL.Enums.VERSION_2_0.INFO_LOG_LENGTH, out length);
- StringBuilder info = new StringBuilder(length);
- GL.GetShaderInfoLog(fragment_shader_object, info.Capacity, out length, info);
+ GL.GetShader(fragment_shader_object, Version20.CompileStatus, out status_code);
+ GL.GetShader(vertex_shader_object, Version20.InfoLogLength, out status_text_length);
+ info.Remove(0, info.Length);
+ info.EnsureCapacity(status_text_length);
+ GL.GetShaderInfoLog(fragment_shader_object, info.Capacity, out status_text_length, info);
+ Trace.WriteLine(info.ToString());
+ if (status_code != 1)
throw new Exception(info.ToString());
- }
shader_program = GL.CreateProgram();
GL.AttachShader(shader_program, fragment_shader_object);
@@ -130,8 +127,37 @@ void main()
GL.LinkProgram(shader_program);
GL.UseProgram(shader_program);
+ }
+
+ private void CreateVBO()
+ {
+ int size;
+
+ GL.GenBuffers(1, out vertex_buffer_object);
+ GL.GenBuffers(1, out color_buffer_object);
+ GL.GenBuffers(1, out element_buffer_object);
+
+ // Upload the vertex data.
+ GL.BindBuffer(Version15.ArrayBuffer, vertex_buffer_object);
+ GL.BufferData(Version15.ArrayBuffer, (IntPtr)(shape.Vertices.Length * 3 * sizeof(float)), shape.Vertices, Version15.StaticDraw);
+ GL.GetBufferParameter(Version15.ArrayBuffer, Version15.BufferSize, out size);
+ if (size != shape.Vertices.Length * 3 * sizeof(Single))
+ throw new ApplicationException("Problem uploading vertex data to VBO");
+
+ // Upload the color data.
+ GL.BindBuffer(Version15.ArrayBuffer, color_buffer_object);
+ GL.BufferData(Version15.ArrayBuffer, (IntPtr)(shape.Colors.Length * sizeof(int)), shape.Colors, Version15.StaticDraw);
+ GL.GetBufferParameter(Version15.ArrayBuffer, Version15.BufferSize, out size);
+ if (shape.Colors.Length * sizeof(int) != size)
+ throw new ApplicationException("Problem uploading color data to VBO");
+
+ // Upload the index data (elements inside the vertex data, not color indices as per the IndexPointer function!)
+ GL.BindBuffer(Version15.ElementArrayBuffer, element_buffer_object);
+ GL.BufferData(Version15.ElementArrayBuffer, (IntPtr)(shape.Indices.Length * sizeof(Int32)), shape.Indices, Version15.StaticDraw);
+ GL.GetBufferParameter(Version15.ElementArrayBuffer, Version15.BufferSize, out size);
+ if (shape.Indices.Length * 4 != size)
+ throw new ApplicationException("Problem uploading index data to VBO");
- //OnResize(new OpenTK.Platform.ResizeEventArgs(this.Width, this.Height));
}
#endregion
@@ -146,6 +172,10 @@ void main()
GL.DeleteShader(fragment_shader_object);
if (vertex_shader_object != 0)
GL.DeleteShader(vertex_shader_object);
+ if (vertex_buffer_object != 0)
+ GL.DeleteBuffers(1, ref vertex_buffer_object);
+ if (element_buffer_object != 0)
+ GL.DeleteBuffers(1, ref element_buffer_object);
}
#endregion
@@ -161,13 +191,11 @@ void main()
///
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
{
- base.OnResize(e);
-
GL.Viewport(0, 0, Width, Height);
double ratio = e.Width / (double)e.Height;
- GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
+ GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
Glu.Perspective(45.0, ratio, 1.0, 64.0);
}
@@ -186,21 +214,11 @@ void main()
public override void OnUpdateFrame(UpdateFrameEventArgs e)
{
if (Keyboard[OpenTK.Input.Key.Escape])
- {
this.Exit();
- return;
- }
if ((Keyboard[OpenTK.Input.Key.AltLeft] || Keyboard[OpenTK.Input.Key.AltRight]) &&
Keyboard[OpenTK.Input.Key.Enter])
- {
Fullscreen = !Fullscreen;
- }
-
- //angle += 180.0f * (float)e.Time;
- angle += 3.0f;
- if (angle > 720.0f)
- angle -= 720.0f;
}
#endregion
@@ -212,19 +230,39 @@ void main()
///
public override void OnRenderFrame(RenderFrameEventArgs e)
{
- GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT | GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
+ GL.Clear(ClearBufferMask.ColorBufferBit |
+ ClearBufferMask.DepthBufferBit);
- GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW);
+ GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
- Glu.LookAt(
- 0.0, 5.0, 5.0,
- 0.0, 0.0, 0.0,
- 0.0, 1.0, 0.0
- );
+ Glu.LookAt(0.0, 5.0, 5.0,
+ 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0);
+
+ angle += rotation_speed * (float)e.ScaleFactor;
GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
- GL.DrawElements(GL.Enums.BeginMode.TRIANGLES, shape.Indices.Length,
- GL.Enums.All.UNSIGNED_SHORT, shape.Indices);
+ GL.EnableClientState(EnableCap.VertexArray);
+ GL.EnableClientState(EnableCap.ColorArray);
+
+ GL.BindBuffer(Version15.ArrayBuffer, vertex_buffer_object);
+ GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
+ GL.BindBuffer(Version15.ArrayBuffer, color_buffer_object);
+ GL.ColorPointer(4, ColorPointerType.UnsignedByte, 0, IntPtr.Zero);
+ GL.BindBuffer(Version15.ElementArrayBuffer, element_buffer_object);
+
+ GL.DrawElements(BeginMode.Triangles, shape.Indices.Length,
+ All.UnsignedInt, IntPtr.Zero);
+
+ //GL.DrawArrays(GL.Enums.BeginMode.POINTS, 0, shape.Vertices.Length);
+
+ GL.DisableClientState(EnableCap.VertexArray);
+ GL.DisableClientState(EnableCap.ColorArray);
+
+
+ //int error = GL.GetError();
+ //if (error != 0)
+ // Debug.Print(Glu.ErrorString(Glu.Enums.ErrorCode.INVALID_OPERATION));
Context.SwapBuffers();
}
@@ -243,8 +281,7 @@ void main()
///
public void Launch()
{
- // Lock UpdateFrame and RenderFrame at 60Hz.
- Run(60.0, 60.0);
+ Run(30.0, 0.0);
}
#endregion
diff --git a/Source/Examples/WinForms/W01_First_Window.cs b/Source/Examples/WinForms/W01_First_Window.cs
index c230f8a0..b24fcdc4 100644
--- a/Source/Examples/WinForms/W01_First_Window.cs
+++ b/Source/Examples/WinForms/W01_First_Window.cs
@@ -16,6 +16,7 @@ using System.Windows.Forms;
using OpenTK;
using OpenTK.OpenGL;
+using OpenTK.OpenGL.Enums;
#endregion
@@ -64,7 +65,7 @@ namespace Examples.WinForms
private void glControl1_Paint(object sender, PaintEventArgs e)
{
- GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT);
+ GL.Clear(ClearBufferMask.ColorBufferBit);
glControl1.SwapBuffers();
}
diff --git a/Source/Examples/WinForms/W02_Immediate_Mode_Cube.cs b/Source/Examples/WinForms/W02_Immediate_Mode_Cube.cs
index c8ce2e6a..c272a93c 100644
--- a/Source/Examples/WinForms/W02_Immediate_Mode_Cube.cs
+++ b/Source/Examples/WinForms/W02_Immediate_Mode_Cube.cs
@@ -19,6 +19,7 @@ using OpenTK.OpenGL;
//using Enums = OpenTK.OpenGL.GL.Enums;
using OpenTK.Platform;
using System.Threading;
+using OpenTK.OpenGL.Enums;
#endregion
@@ -48,12 +49,12 @@ namespace Examples.WinForms
glControl.Paint += new PaintEventHandler(glControl_Paint);
Text =
- GL.GetString(GL.Enums.StringName.VENDOR) + " " +
- GL.GetString(GL.Enums.StringName.RENDERER) + " " +
- GL.GetString(GL.Enums.StringName.VERSION);
+ GL.GetString(StringName.Vendor) + " " +
+ GL.GetString(StringName.Renderer) + " " +
+ GL.GetString(StringName.Version);
GL.ClearColor(Color.MidnightBlue);
- GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
+ GL.Enable(EnableCap.DepthTest);
Application.Idle += Application_Idle;
@@ -89,7 +90,7 @@ namespace Examples.WinForms
private void Render()
{
- GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW);
+ GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
Glu.LookAt(
0.0, 5.0, 5.0,
@@ -99,7 +100,7 @@ namespace Examples.WinForms
GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
angle += 0.5f;
- GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT | GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
+ GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
DrawCube();
@@ -122,7 +123,7 @@ namespace Examples.WinForms
double ratio = 0.0;
ratio = c.ClientSize.Width / (double)c.ClientSize.Height;
- GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
+ GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
Glu.Perspective(45.0, ratio, 1.0, 64.0);
}
@@ -156,7 +157,7 @@ namespace Examples.WinForms
private void DrawCube()
{
- GL.Begin(GL.Enums.BeginMode.QUADS);
+ GL.Begin(BeginMode.Quads);
GL.Color3(Color.Silver);
GL.Vertex3(-1.0f, -1.0f, -1.0f);
diff --git a/Source/Examples/WinForms/W03_Extensions.cs b/Source/Examples/WinForms/W03_Extensions.cs
index ec200fb9..9cca7d00 100644
--- a/Source/Examples/WinForms/W03_Extensions.cs
+++ b/Source/Examples/WinForms/W03_Extensions.cs
@@ -16,6 +16,7 @@ using OpenTK;
using System.Reflection;
using OpenTK.OpenGL;
using System.Threading;
+using OpenTK.OpenGL.Enums;
namespace Examples.WinForms
{
@@ -47,9 +48,9 @@ namespace Examples.WinForms
Application.Idle += StartAsync;
driver =
- GL.GetString(GL.Enums.StringName.VENDOR) + " " +
- GL.GetString(GL.Enums.StringName.RENDERER) + " " +
- GL.GetString(GL.Enums.StringName.VERSION);
+ GL.GetString(StringName.Vendor) + " " +
+ GL.GetString(StringName.Renderer) + " " +
+ GL.GetString(StringName.Version);
all = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic).Length;
this.Text = String.Format("Loading {0} functions...", all);