mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-25 07:55:39 +00:00
Updated to follow the new naming conventions. Fonts tutorial is broken.
This commit is contained in:
parent
2d2eaf4db7
commit
75cd2b0994
|
@ -64,6 +64,8 @@ namespace Examples
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region public void ExampleLauncher_Load(object sender, EventArgs e)
|
||||||
|
|
||||||
public void ExampleLauncher_Load(object sender, EventArgs e)
|
public void ExampleLauncher_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -119,27 +121,7 @@ namespace Examples
|
||||||
this.listBox1.SelectedIndex = 0;
|
this.listBox1.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchGameWindow(object example)
|
#endregion
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RunExample()
|
private void RunExample()
|
||||||
{
|
{
|
||||||
|
@ -150,31 +132,22 @@ namespace Examples
|
||||||
Debug.Print("Launching example: {0}", example.ToString());
|
Debug.Print("Launching example: {0}", example.ToString());
|
||||||
this.Visible = false;
|
this.Visible = false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
if (example.BaseType == typeof(GameWindow))
|
if (example.BaseType == typeof(GameWindow))
|
||||||
{
|
{
|
||||||
LaunchGameWindow(example);
|
using (GameWindow gw = (GameWindow)(example.GetConstructor(Type.EmptyTypes).Invoke(null)))
|
||||||
|
{
|
||||||
|
(gw as IExample).Launch();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (example.BaseType == typeof(Form))
|
else if (example.BaseType == typeof(Form))
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using (Form f = (Form)example.GetConstructor(Type.EmptyTypes).Invoke(null))
|
using (Form f = (Form)example.GetConstructor(Type.EmptyTypes).Invoke(null))
|
||||||
{
|
{
|
||||||
f.ShowDialog(this);
|
f.ShowDialog(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception expt)
|
|
||||||
{
|
|
||||||
MessageBox.Show(
|
|
||||||
String.Format(
|
|
||||||
"Stacktrace:{0}{1}{0}{0}Inner exception:{0}{2}",
|
|
||||||
System.Environment.NewLine,
|
|
||||||
expt.StackTrace,
|
|
||||||
expt.InnerException
|
|
||||||
),
|
|
||||||
expt.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Console application.
|
// Console application.
|
||||||
|
@ -182,6 +155,22 @@ namespace Examples
|
||||||
ex.Launch();
|
ex.Launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception expt)
|
||||||
|
{
|
||||||
|
#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();
|
GC.Collect();
|
||||||
GC.WaitForPendingFinalizers();
|
GC.WaitForPendingFinalizers();
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
|
|
|
@ -13,6 +13,7 @@ using System.Windows.Forms;
|
||||||
|
|
||||||
using OpenTK.OpenGL;
|
using OpenTK.OpenGL;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
|
using OpenTK.OpenGL.Enums;
|
||||||
|
|
||||||
namespace Examples.Tests
|
namespace Examples.Tests
|
||||||
{
|
{
|
||||||
|
@ -92,10 +93,7 @@ namespace Examples.Tests
|
||||||
Trace.Write("Timing OpenTK.OpenGL core functions (void*): ");
|
Trace.Write("Timing OpenTK.OpenGL core functions (void*): ");
|
||||||
timer.Start();
|
timer.Start();
|
||||||
for (int i = 0; ++i < num_calls; )
|
for (int i = 0; ++i < num_calls; )
|
||||||
{
|
GL.CallLists(v.Length, ListNameType.Float, v);
|
||||||
GL.CallLists(v.Length, GL.Enums.ListNameType.FLOAT, v);
|
|
||||||
|
|
||||||
}
|
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
||||||
timer.Reset();
|
timer.Reset();
|
||||||
|
@ -103,9 +101,8 @@ namespace Examples.Tests
|
||||||
Trace.Write("Timing OpenTK.OpenGL extension functions: ");
|
Trace.Write("Timing OpenTK.OpenGL extension functions: ");
|
||||||
timer.Start();
|
timer.Start();
|
||||||
for (int i = 0; ++i < num_calls; )
|
for (int i = 0; ++i < num_calls; )
|
||||||
{
|
GL.Arb.ActiveTexture(ArbMultitexture.Texture0Arb);
|
||||||
GL.ARB.ActiveTexture(GL.Enums.ARB_multitexture.TEXTURE0_ARB);
|
|
||||||
}
|
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
||||||
timer.Reset();
|
timer.Reset();
|
||||||
|
@ -139,7 +136,7 @@ namespace Examples.Tests
|
||||||
timer.Start();
|
timer.Start();
|
||||||
for (int i = 0; ++i < num_calls; )
|
for (int i = 0; ++i < num_calls; )
|
||||||
{
|
{
|
||||||
glCallLists(v.Length, GL.Enums.ListNameType.FLOAT, v);
|
glCallLists(v.Length, ListNameType.Float, v);
|
||||||
}
|
}
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
Trace.WriteLine(String.Format("{0} ns", timer.Elapsed.TotalMilliseconds * (1000000.0 / (double)num_calls)));
|
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);
|
extern static void glVertex2fv(float[] v);
|
||||||
|
|
||||||
[DllImport("opengl32.dll", EntryPoint = "glCallLists"), SuppressUnmanagedCodeSecurity]
|
[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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ using OpenTK.Fonts;
|
||||||
using OpenTK.OpenGL;
|
using OpenTK.OpenGL;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using OpenTK.OpenGL.Enums;
|
||||||
|
|
||||||
namespace Examples.Tutorial
|
namespace Examples.Tutorial
|
||||||
{
|
{
|
||||||
|
@ -36,9 +37,9 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
public override void OnLoad(EventArgs e)
|
public override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
GL.Enable(GL.Enums.EnableCap.TEXTURE_2D);
|
GL.Enable(EnableCap.Texture2d);
|
||||||
GL.Enable(GL.Enums.EnableCap.BLEND);
|
GL.Enable(EnableCap.Blend);
|
||||||
GL.BlendFunc(GL.Enums.BlendingFactorSrc.SRC_ALPHA, GL.Enums.BlendingFactorDest.ONE_MINUS_SRC_ALPHA);
|
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
|
||||||
|
|
||||||
//serif.LoadGlyphs("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz,.!?;()\'- ");
|
//serif.LoadGlyphs("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz,.!?;()\'- ");
|
||||||
serif.LoadGlyphs("A");
|
serif.LoadGlyphs("A");
|
||||||
|
@ -92,13 +93,13 @@ namespace Examples.Tutorial
|
||||||
current_position = initial_position;
|
current_position = initial_position;
|
||||||
scroll_position = current_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.LoadIdentity();
|
||||||
GL.Ortho(0.0, Width, Height, 0.0, 0.0, 1.0);
|
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.LoadIdentity();
|
||||||
|
|
||||||
GL.Translate(0.0f, scroll_position, 0.0f);
|
GL.Translate(0.0f, scroll_position, 0.0f);
|
||||||
|
@ -110,13 +111,13 @@ namespace Examples.Tutorial
|
||||||
int texture;
|
int texture;
|
||||||
serif.GlyphData('A', ref rect, out width, out height, out 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.Enable(EnableCap.Blend);
|
||||||
GL.BlendFunc(GL.Enums.BlendingFactorSrc.SRC_ALPHA, GL.Enums.BlendingFactorDest.ONE_MINUS_SRC_ALPHA);
|
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
|
||||||
|
|
||||||
//GL.Color4(Color.White);
|
//GL.Color4(Color.White);
|
||||||
GL.Begin(GL.Enums.BeginMode.QUADS);
|
GL.Begin(BeginMode.Quads);
|
||||||
|
|
||||||
GL.TexCoord2(rect.Left, rect.Top);
|
GL.TexCoord2(rect.Left, rect.Top);
|
||||||
GL.Vertex2(0.0, 0.0);
|
GL.Vertex2(0.0, 0.0);
|
||||||
|
|
|
@ -13,6 +13,7 @@ using System.Diagnostics;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.OpenGL;
|
using OpenTK.OpenGL;
|
||||||
using OpenTK.Fonts;
|
using OpenTK.Fonts;
|
||||||
|
using OpenTK.OpenGL.Enums;
|
||||||
|
|
||||||
namespace Examples.Tutorial
|
namespace Examples.Tutorial
|
||||||
{
|
{
|
||||||
|
@ -22,10 +23,7 @@ namespace Examples.Tutorial
|
||||||
public class T01_Simple_Window : GameWindow, IExample
|
public class T01_Simple_Window : GameWindow, IExample
|
||||||
{
|
{
|
||||||
public T01_Simple_Window() : base(new DisplayMode(800, 600), "OpenTK | Tutorial 1: Simple Window")
|
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
|
#region OnLoad
|
||||||
|
|
||||||
|
@ -51,7 +49,7 @@ namespace Examples.Tutorial
|
||||||
{
|
{
|
||||||
GL.Viewport(0, 0, e.Width, e.Height);
|
GL.Viewport(0, 0, e.Width, e.Height);
|
||||||
|
|
||||||
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
|
GL.MatrixMode(MatrixMode.Projection);
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);
|
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);
|
||||||
|
|
||||||
|
@ -86,9 +84,9 @@ namespace Examples.Tutorial
|
||||||
/// <remarks>There is no need to call the base implementation.</remarks>
|
/// <remarks>There is no need to call the base implementation.</remarks>
|
||||||
public override void OnRenderFrame(RenderFrameEventArgs e)
|
public override void OnRenderFrame(RenderFrameEventArgs e)
|
||||||
{
|
{
|
||||||
GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT);
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||||
/*
|
|
||||||
GL.Begin(GL.Enums.BeginMode.TRIANGLES);
|
GL.Begin(BeginMode.Triangles);
|
||||||
|
|
||||||
GL.Color3(Color.SpringGreen);
|
GL.Color3(Color.SpringGreen);
|
||||||
GL.Vertex2(-1.0f, 1.0f);
|
GL.Vertex2(-1.0f, 1.0f);
|
||||||
|
@ -99,19 +97,6 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
GL.End();
|
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();
|
this.SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ using OpenTK.OpenGL;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
using OpenTK.Fonts;
|
using OpenTK.Fonts;
|
||||||
|
using OpenTK.OpenGL.Enums;
|
||||||
|
|
||||||
namespace Examples.Tutorial
|
namespace Examples.Tutorial
|
||||||
{
|
{
|
||||||
|
@ -27,7 +28,8 @@ namespace Examples.Tutorial
|
||||||
float angle = 0.0f;
|
float angle = 0.0f;
|
||||||
|
|
||||||
Shapes.Shape shape = new Examples.Shapes.Plane(16, 16, 2.0f, 2.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
|
#region Constructor
|
||||||
|
|
||||||
|
@ -57,14 +59,14 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
public override void OnLoad(EventArgs e)
|
public override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
GL.Enable(GL.Enums.EnableCap.TEXTURE_2D);
|
GL.Enable(EnableCap.Texture2d);
|
||||||
|
|
||||||
GL.ClearColor(Color.CadetBlue);
|
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.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);
|
//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;
|
double ratio = e.Width / (double)e.Height;
|
||||||
|
|
||||||
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
|
GL.MatrixMode(MatrixMode.Projection);
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
||||||
}
|
}
|
||||||
|
@ -139,9 +141,9 @@ namespace Examples.Tutorial
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void OnRenderFrame(RenderFrameEventArgs e)
|
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();
|
GL.LoadIdentity();
|
||||||
Glu.LookAt(
|
Glu.LookAt(
|
||||||
0.0, 5.0, 5.0,
|
0.0, 5.0, 5.0,
|
||||||
|
@ -155,10 +157,8 @@ namespace Examples.Tutorial
|
||||||
angle -= 360.0f;
|
angle -= 360.0f;
|
||||||
GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
|
GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
GL.DrawElements(GL.Enums.BeginMode.TRIANGLES, shape.Indices.Length,
|
GL.DrawElements(BeginMode.Triangles, shape.Indices.Length,
|
||||||
GL.Enums.All.UNSIGNED_INT, shape.Indices);
|
All.UnsignedInt, shape.Indices);
|
||||||
|
|
||||||
// GL.DrawArrays(GL.Enums.BeginMode.LINES, 0, shape.Vertices.Length);
|
|
||||||
|
|
||||||
//GL.Begin(GL.Enums.BeginMode.TRIANGLES);
|
//GL.Begin(GL.Enums.BeginMode.TRIANGLES);
|
||||||
|
|
||||||
|
@ -170,10 +170,10 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
GL.PushMatrix();
|
GL.PushMatrix();
|
||||||
|
|
||||||
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
|
GL.MatrixMode(MatrixMode.Projection);
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 1.0);
|
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.LoadIdentity();
|
||||||
|
|
||||||
//GL.Translate(0.7f, 1.0f, 0.0f);
|
//GL.Translate(0.7f, 1.0f, 0.0f);
|
||||||
|
|
|
@ -14,6 +14,7 @@ using System.Drawing;
|
||||||
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.OpenGL;
|
using OpenTK.OpenGL;
|
||||||
|
using OpenTK.OpenGL.Enums;
|
||||||
using OpenTK.Platform;
|
using OpenTK.Platform;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -36,10 +37,8 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
#region --- Constructors ---
|
#region --- Constructors ---
|
||||||
|
|
||||||
public T03_Immediate_Mode_Cube()
|
public T03_Immediate_Mode_Cube() : base(new DisplayMode(800, 600), "OpenTK Tutorial: Immediate mode rendering")
|
||||||
{
|
{ }
|
||||||
CreateWindow(new DisplayMode(800, 600));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ namespace Examples.Tutorial
|
||||||
base.OnLoad(e);
|
base.OnLoad(e);
|
||||||
|
|
||||||
GL.ClearColor(Color.MidnightBlue);
|
GL.ClearColor(Color.MidnightBlue);
|
||||||
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
|
GL.Enable(EnableCap.DepthTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -72,7 +71,7 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
double ratio = e.Width / (double)e.Height;
|
double ratio = e.Width / (double)e.Height;
|
||||||
|
|
||||||
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
|
GL.MatrixMode(MatrixMode.Projection);
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
||||||
}
|
}
|
||||||
|
@ -117,15 +116,14 @@ namespace Examples.Tutorial
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void OnRenderFrame(RenderFrameEventArgs e)
|
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();
|
GL.LoadIdentity();
|
||||||
Glu.LookAt(
|
Glu.LookAt(0.0, 5.0, 5.0,
|
||||||
0.0, 5.0, 5.0,
|
|
||||||
0.0, 0.0, 0.0,
|
0.0, 0.0, 0.0,
|
||||||
0.0, 1.0, 0.0
|
0.0, 1.0, 0.0);
|
||||||
);
|
|
||||||
GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
|
GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
DrawCube();
|
DrawCube();
|
||||||
|
@ -140,7 +138,7 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
private void DrawCube()
|
private void DrawCube()
|
||||||
{
|
{
|
||||||
GL.Begin(GL.Enums.BeginMode.QUADS);
|
GL.Begin(BeginMode.Quads);
|
||||||
|
|
||||||
GL.Color3(Color.Silver);
|
GL.Color3(Color.Silver);
|
||||||
GL.Vertex3(-1.0f, -1.0f, -1.0f);
|
GL.Vertex3(-1.0f, -1.0f, -1.0f);
|
||||||
|
|
|
@ -12,6 +12,7 @@ using System.Drawing;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.OpenGL;
|
using OpenTK.OpenGL;
|
||||||
using Examples.Shapes;
|
using Examples.Shapes;
|
||||||
|
using OpenTK.OpenGL.Enums;
|
||||||
|
|
||||||
namespace Examples.Tutorial
|
namespace Examples.Tutorial
|
||||||
{
|
{
|
||||||
|
@ -38,31 +39,31 @@ namespace Examples.Tutorial
|
||||||
base.OnLoad(e);
|
base.OnLoad(e);
|
||||||
|
|
||||||
GL.ClearColor(Color.MidnightBlue);
|
GL.ClearColor(Color.MidnightBlue);
|
||||||
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
|
GL.Enable(EnableCap.DepthTest);
|
||||||
//GL.Enable(GL.Enums.EnableCap.CULL_FACE);
|
//GL.Enable(GL.Enums.EnableCap.CULL_FACE);
|
||||||
|
|
||||||
GL.EnableClientState(GL.Enums.EnableCap.VERTEX_ARRAY);
|
GL.EnableClientState(EnableCap.VertexArray);
|
||||||
GL.EnableClientState(GL.Enums.EnableCap.NORMAL_ARRAY);
|
GL.EnableClientState(EnableCap.NormalArray);
|
||||||
GL.VertexPointer(3, GL.Enums.VertexPointerType.FLOAT, 0, shape.Vertices);
|
GL.VertexPointer(3, VertexPointerType.Float, 0, shape.Vertices);
|
||||||
GL.NormalPointer(GL.Enums.NormalPointerType.FLOAT, 0, shape.Normals);
|
GL.NormalPointer(NormalPointerType.Float, 0, shape.Normals);
|
||||||
|
|
||||||
// Enable Light 0 and set its parameters.
|
// 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(LightName.Light0, 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(LightName.Light0, 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(LightName.Light0, 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(LightName.Light0, 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.Lightv(LightName.Light0, LightParameter.SpotExponent, 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.LightModelv(LightModelParameter.LightModelAmbient, new float[] { 0.2f, 0.2f, 0.2f, 1.0f });
|
||||||
GL.LightModel(GL.Enums.LightModelParameter.LIGHT_MODEL_TWO_SIDE, 1);
|
GL.LightModel(LightModelParameter.LightModelTwoSide, 1);
|
||||||
GL.LightModel(GL.Enums.LightModelParameter.LIGHT_MODEL_LOCAL_VIEWER, 1);
|
GL.LightModel(LightModelParameter.LightModelLocalViewer, 1);
|
||||||
GL.Enable(GL.Enums.EnableCap.LIGHTING);
|
GL.Enable(EnableCap.Lighting);
|
||||||
GL.Enable(GL.Enums.EnableCap.LIGHT0);
|
GL.Enable(EnableCap.Light0);
|
||||||
|
|
||||||
// Use GL.Material to set your object's material parameters..
|
// 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(MaterialFace.Front, 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(MaterialFace.Front, 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(MaterialFace.Front, 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 });
|
GL.Materialv(MaterialFace.Front, MaterialParameter.Emission, new float[] { 0.0f, 0.0f, 0.0f, 1.0f });
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -84,7 +85,7 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
double ratio = e.Width / (double)e.Height;
|
double ratio = e.Width / (double)e.Height;
|
||||||
|
|
||||||
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
|
GL.MatrixMode(MatrixMode.Projection);
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
||||||
}
|
}
|
||||||
|
@ -139,18 +140,18 @@ namespace Examples.Tutorial
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void OnRenderFrame(RenderFrameEventArgs e)
|
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();
|
GL.LoadIdentity();
|
||||||
Glu.LookAt(
|
Glu.LookAt(0.0, 0.0, -7.5 + zoom,
|
||||||
0.0, 0.0, -7.5 + zoom,
|
|
||||||
0.0, 0.0, 0.0,
|
0.0, 0.0, 0.0,
|
||||||
0.0, 1.0, 0.0);
|
0.0, 1.0, 0.0);
|
||||||
GL.Rotate(x_angle, 0.0f, 1.0f, 0.0f);
|
GL.Rotate(x_angle, 0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
GL.DrawElements(GL.Enums.BeginMode.TRIANGLES, shape.Indices.Length,
|
//GL.DrawElements(GL.Enums.BeginMode.TRIANGLES, shape.Indices.Length,
|
||||||
GL.Enums.All.UNSIGNED_INT, shape.Indices);
|
// GL.Enums.All.UNSIGNED_INT, shape.Indices);
|
||||||
|
GL.DrawArrays(BeginMode.Points, 0, shape.Vertices.Length);
|
||||||
|
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,12 @@ using System.Data;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using OpenTK.OpenGL;
|
|
||||||
using Enums = OpenTK.OpenGL.GL.Enums;
|
|
||||||
using OpenTK;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
|
using OpenTK;
|
||||||
|
using OpenTK.OpenGL;
|
||||||
|
using OpenTK.OpenGL.Enums;
|
||||||
|
|
||||||
#endregion --- Using Directives ---
|
#endregion --- Using Directives ---
|
||||||
|
|
||||||
namespace Examples.Tutorial
|
namespace Examples.Tutorial
|
||||||
|
@ -46,9 +46,9 @@ namespace Examples.Tutorial
|
||||||
public override void OnLoad(EventArgs e)
|
public override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
|
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();
|
GL.LoadIdentity();
|
||||||
|
|
||||||
// Build some display lists.
|
// Build some display lists.
|
||||||
|
@ -57,7 +57,7 @@ namespace Examples.Tutorial
|
||||||
for (int i = 0; i < num_lists; i++)
|
for (int i = 0; i < num_lists; i++)
|
||||||
{
|
{
|
||||||
lists[i] = first_list + 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);
|
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.Rotate(c * 360.0f, 0.0, 0.0, 1.0);
|
||||||
GL.Translate(5.0, 0.0, 0.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);
|
||||||
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;
|
double ratio = 0.0;
|
||||||
ratio = this.Width / (double)this.Height;
|
ratio = this.Width / (double)this.Height;
|
||||||
|
|
||||||
GL.MatrixMode(Enums.MatrixMode.PROJECTION);
|
GL.MatrixMode(MatrixMode.Projection);
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
||||||
}
|
}
|
||||||
|
@ -126,15 +126,15 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
public override void OnRenderFrame(RenderFrameEventArgs e)
|
public override void OnRenderFrame(RenderFrameEventArgs e)
|
||||||
{
|
{
|
||||||
GL.MatrixMode(Enums.MatrixMode.MODELVIEW);
|
GL.MatrixMode(MatrixMode.Modelview);
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
Glu.LookAt(
|
Glu.LookAt(
|
||||||
0.0, 0.0, 16.0,
|
0.0, 0.0, 16.0,
|
||||||
0.0, 0.0, 0.0,
|
0.0, 0.0, 0.0,
|
||||||
0.0, 1.0, 0.0);
|
0.0, 1.0, 0.0);
|
||||||
|
|
||||||
GL.Clear(Enums.ClearBufferMask.COLOR_BUFFER_BIT | Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
|
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||||
GL.CallLists(num_lists, Enums.ListNameType.INT, lists);
|
GL.CallLists(num_lists, ListNameType.Int, lists);
|
||||||
|
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,71 +14,31 @@ using OpenTK;
|
||||||
using OpenTK.OpenGL;
|
using OpenTK.OpenGL;
|
||||||
using OpenTK.Platform;
|
using OpenTK.Platform;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using OpenTK.OpenGL.Enums;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Examples.Tutorial
|
namespace Examples.Tutorial
|
||||||
{
|
{
|
||||||
public class T08_VBO : OpenTK.GameWindow /*, IExample */
|
public class T08_VBO : GameWindow, IExample
|
||||||
{
|
{
|
||||||
#region --- Private Fields ---
|
#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;
|
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
|
#endregion
|
||||||
|
|
||||||
#region --- Constructor ---
|
#region --- Constructor ---
|
||||||
|
|
||||||
public T08_VBO()
|
public T08_VBO() : base(new DisplayMode(800, 600), "OpenTK Tutorial 08: Vertex Buffer Objects") { }
|
||||||
{
|
|
||||||
this.CreateWindow(new DisplayMode(800, 600));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region OnLoad
|
#region OnLoad override
|
||||||
|
|
||||||
public override void OnLoad(EventArgs e)
|
public override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -92,35 +52,56 @@ namespace Examples.Tutorial
|
||||||
}
|
}
|
||||||
|
|
||||||
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
|
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
|
||||||
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.INDEX_ARRAY);
|
//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
|
#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);
|
GL.Viewport(0, 0, Width, Height);
|
||||||
|
|
||||||
double ratio = e.Width / (double)e.Height;
|
double ratio = e.Width / (double)e.Height;
|
||||||
|
|
||||||
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
|
GL.MatrixMode(MatrixMode.Projection);
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region OnUpdateFrame
|
#region OnUpdateFrame override
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prepares the next frame for rendering.
|
/// Prepares the next frame for rendering.
|
||||||
|
@ -132,21 +113,7 @@ namespace Examples.Tutorial
|
||||||
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
||||||
{
|
{
|
||||||
if (Keyboard[OpenTK.Input.Key.Escape])
|
if (Keyboard[OpenTK.Input.Key.Escape])
|
||||||
{
|
|
||||||
this.Exit();
|
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
|
#endregion
|
||||||
|
@ -157,74 +124,21 @@ namespace Examples.Tutorial
|
||||||
{
|
{
|
||||||
base.OnRenderFrame(e);
|
base.OnRenderFrame(e);
|
||||||
|
|
||||||
GL.Clear(
|
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||||
GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT |
|
|
||||||
GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
GL.BindBuffer(GL.Enums.VERSION_1_5.ARRAY_BUFFER, vbo);
|
GL.MatrixMode(MatrixMode.Modelview);
|
||||||
GL.VertexPointer(3, GL.Enums.VertexPointerType.FLOAT, 0, 0);
|
GL.LoadIdentity();
|
||||||
|
Glu.LookAt(
|
||||||
GL.BindBuffer(GL.Enums.VERSION_1_5.ELEMENT_ARRAY_BUFFER, ibo);
|
0.0, 5.0, 5.0,
|
||||||
GL.IndexPointer(GL.Enums.IndexPointerType.FLOAT, 0, 0);
|
0.0, 0.0, 0.0,
|
||||||
|
0.0, 1.0, 0.0
|
||||||
|
);
|
||||||
|
|
||||||
GL.Color3(1.0f, 1.0f, 1.0f);
|
GL.Color3(1.0f, 1.0f, 1.0f);
|
||||||
GL.DrawElements(
|
GL.DrawElements(BeginMode.Triangles, shape.Indices.Length,
|
||||||
GL.Enums.BeginMode.QUADS,
|
All.UnsignedInt, shape.Indices);
|
||||||
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);
|
|
||||||
|
|
||||||
Context.SwapBuffers();
|
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
|
#endregion
|
||||||
|
|
|
@ -16,6 +16,9 @@ using System.Threading;
|
||||||
|
|
||||||
using OpenTK.OpenGL;
|
using OpenTK.OpenGL;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using OpenTK.OpenGL.Enums;
|
||||||
|
|
||||||
#endregion --- Using Directives ---
|
#endregion --- Using Directives ---
|
||||||
|
|
||||||
|
@ -28,31 +31,12 @@ namespace Examples.Tutorial
|
||||||
{
|
{
|
||||||
#region --- Fields ---
|
#region --- Fields ---
|
||||||
|
|
||||||
#region Shaders
|
static float angle = 0.0f, rotation_speed = 3.0f;
|
||||||
|
|
||||||
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;
|
|
||||||
int vertex_shader_object, fragment_shader_object, shader_program;
|
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
|
#endregion
|
||||||
|
|
||||||
|
@ -74,8 +58,6 @@ void main()
|
||||||
/// <param name="e">Not used.</param>
|
/// <param name="e">Not used.</param>
|
||||||
public override void OnLoad(EventArgs e)
|
public override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnLoad(e);
|
|
||||||
|
|
||||||
// Check for necessary capabilities:
|
// Check for necessary capabilities:
|
||||||
if (!GL.SupportsExtension("VERSION_2_0"))
|
if (!GL.SupportsExtension("VERSION_2_0"))
|
||||||
{
|
{
|
||||||
|
@ -86,52 +68,96 @@ void main()
|
||||||
}
|
}
|
||||||
|
|
||||||
GL.ClearColor(Color.MidnightBlue);
|
GL.ClearColor(Color.MidnightBlue);
|
||||||
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
|
GL.Enable(EnableCap.DepthTest);
|
||||||
|
|
||||||
GL.EnableClientState(GL.Enums.EnableCap.VERTEX_ARRAY);
|
CreateVBO();
|
||||||
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);
|
|
||||||
|
|
||||||
int status;
|
//CreateShader();
|
||||||
|
|
||||||
vertex_shader_object = GL.CreateShader(GL.Enums.VERSION_2_0.VERTEX_SHADER);
|
int status_code, status_text_length;
|
||||||
fragment_shader_object = GL.CreateShader(GL.Enums.VERSION_2_0.FRAGMENT_SHADER);
|
StringBuilder info = new StringBuilder();
|
||||||
|
|
||||||
|
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); }
|
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.CompileShader(vertex_shader_object);
|
||||||
GL.GetShader(vertex_shader_object, GL.Enums.VERSION_2_0.COMPILE_STATUS, out status);
|
GL.GetShader(vertex_shader_object, Version20.CompileStatus, out status_code);
|
||||||
if (status != (int)GL.Enums.Boolean.TRUE)
|
GL.GetShader(vertex_shader_object, Version20.InfoLogLength, out status_text_length);
|
||||||
{
|
info.Remove(0, info.Length);
|
||||||
int length = 0;
|
info.EnsureCapacity(status_text_length);
|
||||||
GL.GetShader(vertex_shader_object, GL.Enums.VERSION_2_0.INFO_LOG_LENGTH, out length);
|
GL.GetShaderInfoLog(vertex_shader_object, info.Capacity, out status_text_length, info);
|
||||||
StringBuilder info = new StringBuilder(length);
|
Trace.WriteLine(info.ToString());
|
||||||
GL.GetShaderInfoLog(vertex_shader_object, info.Capacity, out length, info);
|
|
||||||
|
|
||||||
|
if (status_code != 1)
|
||||||
throw new Exception(info.ToString());
|
throw new Exception(info.ToString());
|
||||||
}
|
|
||||||
|
|
||||||
|
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); }
|
unsafe { GL.ShaderSource(fragment_shader_object, fragment_shader_source.Length, fragment_shader_source, (int*)null); }
|
||||||
GL.CompileShader(fragment_shader_object);
|
#else
|
||||||
GL.GetShader(fragment_shader_object, GL.Enums.VERSION_2_0.COMPILE_STATUS, out status);
|
GL.ShaderSource(fragment_shader_object, code.Length, code, (int[])null);
|
||||||
if (status != (int)GL.Enums.Boolean.TRUE)
|
#endif
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
throw new Exception(info.ToString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GL.CompileShader(fragment_shader_object);
|
||||||
|
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();
|
shader_program = GL.CreateProgram();
|
||||||
GL.AttachShader(shader_program, fragment_shader_object);
|
GL.AttachShader(shader_program, fragment_shader_object);
|
||||||
GL.AttachShader(shader_program, vertex_shader_object);
|
GL.AttachShader(shader_program, vertex_shader_object);
|
||||||
|
|
||||||
GL.LinkProgram(shader_program);
|
GL.LinkProgram(shader_program);
|
||||||
GL.UseProgram(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
|
#endregion
|
||||||
|
@ -146,6 +172,10 @@ void main()
|
||||||
GL.DeleteShader(fragment_shader_object);
|
GL.DeleteShader(fragment_shader_object);
|
||||||
if (vertex_shader_object != 0)
|
if (vertex_shader_object != 0)
|
||||||
GL.DeleteShader(vertex_shader_object);
|
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
|
#endregion
|
||||||
|
@ -161,13 +191,11 @@ void main()
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnResize(e);
|
|
||||||
|
|
||||||
GL.Viewport(0, 0, Width, Height);
|
GL.Viewport(0, 0, Width, Height);
|
||||||
|
|
||||||
double ratio = e.Width / (double)e.Height;
|
double ratio = e.Width / (double)e.Height;
|
||||||
|
|
||||||
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
|
GL.MatrixMode(MatrixMode.Projection);
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
||||||
}
|
}
|
||||||
|
@ -186,23 +214,13 @@ void main()
|
||||||
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
||||||
{
|
{
|
||||||
if (Keyboard[OpenTK.Input.Key.Escape])
|
if (Keyboard[OpenTK.Input.Key.Escape])
|
||||||
{
|
|
||||||
this.Exit();
|
this.Exit();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((Keyboard[OpenTK.Input.Key.AltLeft] || Keyboard[OpenTK.Input.Key.AltRight]) &&
|
if ((Keyboard[OpenTK.Input.Key.AltLeft] || Keyboard[OpenTK.Input.Key.AltRight]) &&
|
||||||
Keyboard[OpenTK.Input.Key.Enter])
|
Keyboard[OpenTK.Input.Key.Enter])
|
||||||
{
|
|
||||||
Fullscreen = !Fullscreen;
|
Fullscreen = !Fullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
//angle += 180.0f * (float)e.Time;
|
|
||||||
angle += 3.0f;
|
|
||||||
if (angle > 720.0f)
|
|
||||||
angle -= 720.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region OnRenderFrame
|
#region OnRenderFrame
|
||||||
|
@ -212,19 +230,39 @@ void main()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void OnRenderFrame(RenderFrameEventArgs e)
|
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();
|
GL.LoadIdentity();
|
||||||
Glu.LookAt(
|
Glu.LookAt(0.0, 5.0, 5.0,
|
||||||
0.0, 5.0, 5.0,
|
|
||||||
0.0, 0.0, 0.0,
|
0.0, 0.0, 0.0,
|
||||||
0.0, 1.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.Rotate(angle, 0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
GL.DrawElements(GL.Enums.BeginMode.TRIANGLES, shape.Indices.Length,
|
GL.EnableClientState(EnableCap.VertexArray);
|
||||||
GL.Enums.All.UNSIGNED_SHORT, shape.Indices);
|
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();
|
Context.SwapBuffers();
|
||||||
}
|
}
|
||||||
|
@ -243,8 +281,7 @@ void main()
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public void Launch()
|
public void Launch()
|
||||||
{
|
{
|
||||||
// Lock UpdateFrame and RenderFrame at 60Hz.
|
Run(30.0, 0.0);
|
||||||
Run(60.0, 60.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -16,6 +16,7 @@ using System.Windows.Forms;
|
||||||
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.OpenGL;
|
using OpenTK.OpenGL;
|
||||||
|
using OpenTK.OpenGL.Enums;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ namespace Examples.WinForms
|
||||||
|
|
||||||
private void glControl1_Paint(object sender, PaintEventArgs e)
|
private void glControl1_Paint(object sender, PaintEventArgs e)
|
||||||
{
|
{
|
||||||
GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT);
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||||
glControl1.SwapBuffers();
|
glControl1.SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ using OpenTK.OpenGL;
|
||||||
//using Enums = OpenTK.OpenGL.GL.Enums;
|
//using Enums = OpenTK.OpenGL.GL.Enums;
|
||||||
using OpenTK.Platform;
|
using OpenTK.Platform;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using OpenTK.OpenGL.Enums;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -48,12 +49,12 @@ namespace Examples.WinForms
|
||||||
glControl.Paint += new PaintEventHandler(glControl_Paint);
|
glControl.Paint += new PaintEventHandler(glControl_Paint);
|
||||||
|
|
||||||
Text =
|
Text =
|
||||||
GL.GetString(GL.Enums.StringName.VENDOR) + " " +
|
GL.GetString(StringName.Vendor) + " " +
|
||||||
GL.GetString(GL.Enums.StringName.RENDERER) + " " +
|
GL.GetString(StringName.Renderer) + " " +
|
||||||
GL.GetString(GL.Enums.StringName.VERSION);
|
GL.GetString(StringName.Version);
|
||||||
|
|
||||||
GL.ClearColor(Color.MidnightBlue);
|
GL.ClearColor(Color.MidnightBlue);
|
||||||
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
|
GL.Enable(EnableCap.DepthTest);
|
||||||
|
|
||||||
Application.Idle += Application_Idle;
|
Application.Idle += Application_Idle;
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ namespace Examples.WinForms
|
||||||
|
|
||||||
private void Render()
|
private void Render()
|
||||||
{
|
{
|
||||||
GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW);
|
GL.MatrixMode(MatrixMode.Modelview);
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
Glu.LookAt(
|
Glu.LookAt(
|
||||||
0.0, 5.0, 5.0,
|
0.0, 5.0, 5.0,
|
||||||
|
@ -99,7 +100,7 @@ namespace Examples.WinForms
|
||||||
GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
|
GL.Rotate(angle, 0.0f, 1.0f, 0.0f);
|
||||||
angle += 0.5f;
|
angle += 0.5f;
|
||||||
|
|
||||||
GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT | GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
|
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||||
|
|
||||||
DrawCube();
|
DrawCube();
|
||||||
|
|
||||||
|
@ -122,7 +123,7 @@ namespace Examples.WinForms
|
||||||
double ratio = 0.0;
|
double ratio = 0.0;
|
||||||
ratio = c.ClientSize.Width / (double)c.ClientSize.Height;
|
ratio = c.ClientSize.Width / (double)c.ClientSize.Height;
|
||||||
|
|
||||||
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
|
GL.MatrixMode(MatrixMode.Projection);
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
Glu.Perspective(45.0, ratio, 1.0, 64.0);
|
||||||
}
|
}
|
||||||
|
@ -156,7 +157,7 @@ namespace Examples.WinForms
|
||||||
|
|
||||||
private void DrawCube()
|
private void DrawCube()
|
||||||
{
|
{
|
||||||
GL.Begin(GL.Enums.BeginMode.QUADS);
|
GL.Begin(BeginMode.Quads);
|
||||||
|
|
||||||
GL.Color3(Color.Silver);
|
GL.Color3(Color.Silver);
|
||||||
GL.Vertex3(-1.0f, -1.0f, -1.0f);
|
GL.Vertex3(-1.0f, -1.0f, -1.0f);
|
||||||
|
|
|
@ -16,6 +16,7 @@ using OpenTK;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using OpenTK.OpenGL;
|
using OpenTK.OpenGL;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using OpenTK.OpenGL.Enums;
|
||||||
|
|
||||||
namespace Examples.WinForms
|
namespace Examples.WinForms
|
||||||
{
|
{
|
||||||
|
@ -47,9 +48,9 @@ namespace Examples.WinForms
|
||||||
Application.Idle += StartAsync;
|
Application.Idle += StartAsync;
|
||||||
|
|
||||||
driver =
|
driver =
|
||||||
GL.GetString(GL.Enums.StringName.VENDOR) + " " +
|
GL.GetString(StringName.Vendor) + " " +
|
||||||
GL.GetString(GL.Enums.StringName.RENDERER) + " " +
|
GL.GetString(StringName.Renderer) + " " +
|
||||||
GL.GetString(GL.Enums.StringName.VERSION);
|
GL.GetString(StringName.Version);
|
||||||
|
|
||||||
all = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic).Length;
|
all = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic).Length;
|
||||||
this.Text = String.Format("Loading {0} functions...", all);
|
this.Text = String.Format("Loading {0} functions...", all);
|
||||||
|
|
Loading…
Reference in a new issue