Added ExampleAttribute to all examples. Improved Textures example. Modified several other examples.
This commit is contained in:
parent
c72890769a
commit
7be851a68a
14 changed files with 348 additions and 260 deletions
|
@ -15,13 +15,27 @@ namespace Examples
|
|||
{
|
||||
public readonly string Title;
|
||||
public readonly ExampleCategory Category;
|
||||
public readonly int Order;
|
||||
public readonly int Difficulty;
|
||||
public readonly bool Visible = true;
|
||||
|
||||
public ExampleAttribute(string title, ExampleCategory category, int order)
|
||||
public ExampleAttribute(string title, ExampleCategory category, int difficulty)
|
||||
{
|
||||
this.Title = title;
|
||||
this.Category = category;
|
||||
this.Order = order;
|
||||
this.Difficulty = difficulty;
|
||||
}
|
||||
|
||||
public ExampleAttribute(string title, ExampleCategory category, int difficulty, bool visible)
|
||||
{
|
||||
this.Title = title;
|
||||
this.Category = category;
|
||||
this.Difficulty = difficulty;
|
||||
this.Visible = visible;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} {1}: {2}", Category, Difficulty, Title);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +43,7 @@ namespace Examples
|
|||
{
|
||||
OpenGL,
|
||||
OpenAL,
|
||||
OpenTK,
|
||||
Tutorial,
|
||||
GLSL,
|
||||
WinForms,
|
||||
Test,
|
||||
|
|
|
@ -36,20 +36,18 @@ namespace Examples
|
|||
/// </summary>
|
||||
class ExampleInfo
|
||||
{
|
||||
public string Name;
|
||||
public string Description;
|
||||
public Type Example;
|
||||
public ExampleAttribute Attributes;
|
||||
|
||||
public ExampleInfo(string name, string description, Type example)
|
||||
public ExampleInfo(Type example, ExampleAttribute attr)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
Example = example;
|
||||
Attributes = attr;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
return Attributes.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,29 +86,24 @@ namespace Examples
|
|||
StringBuilder sb = new StringBuilder();
|
||||
foreach (Type type in types)
|
||||
{
|
||||
if (type.GetInterface("IExample") != null)
|
||||
{
|
||||
sb.Append(type.Namespace);
|
||||
sb.Replace("Examples.", String.Empty);
|
||||
sb.Append(" ");
|
||||
int order;
|
||||
try
|
||||
{
|
||||
FieldInfo info = type.GetField("order");
|
||||
order = (int)info.GetValue(null);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
Debug.Print("Example {0} does not have ordering info", type.FullName);
|
||||
order = 0;
|
||||
}
|
||||
if (order < 10)
|
||||
sb.Append("0"); // To keep items sorted nicely.
|
||||
sb.Append(order.ToString());
|
||||
sb.Append(": ");
|
||||
sb.Append(type.Name);
|
||||
object[] attributes = type.GetCustomAttributes(false);
|
||||
ExampleAttribute example = null;
|
||||
foreach (object attr in attributes)
|
||||
if (attr is ExampleAttribute)
|
||||
example = (ExampleAttribute)attr;
|
||||
|
||||
listBox1.Items.Add(new ExampleInfo(sb.ToString(), "", type));
|
||||
if (example != null && example.Visible == true)
|
||||
{
|
||||
sb.Append(example.Category);
|
||||
sb.Append(" ");
|
||||
if (example.Difficulty < 10)
|
||||
sb.Append("0"); // To keep items nicely sorted.
|
||||
sb.Append(example.Difficulty);
|
||||
sb.Append(": ");
|
||||
//sb.Append(type.Name);
|
||||
sb.Append(example.Title);
|
||||
|
||||
listBox1.Items.Add(new ExampleInfo(type, example));
|
||||
|
||||
// Clean the StringBuilder for the next pass.
|
||||
sb.Remove(0, sb.Length);
|
||||
|
@ -123,61 +116,57 @@ namespace Examples
|
|||
|
||||
#endregion
|
||||
|
||||
#region private void RunExample()
|
||||
|
||||
private void RunExample()
|
||||
{
|
||||
if (listBox1.SelectedItem != null)
|
||||
{
|
||||
Type example = (listBox1.SelectedItem as ExampleInfo).Example;
|
||||
try
|
||||
{
|
||||
ExampleInfo info = (ExampleInfo)listBox1.SelectedItem;
|
||||
Type example = info.Example;
|
||||
|
||||
Debug.Print("Launching example: {0}", example.ToString());
|
||||
this.Visible = false;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Console application.
|
||||
IExample ex = (IExample)example.GetConstructor(Type.EmptyTypes).Invoke(null);
|
||||
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
|
||||
|
||||
}
|
||||
example.GetMethod("Main").Invoke(null, null);
|
||||
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
|
||||
}
|
||||
catch (TargetInvocationException expt)
|
||||
{
|
||||
string ex_info;
|
||||
if (expt.InnerException != null)
|
||||
ex_info = expt.InnerException.ToString();
|
||||
else
|
||||
ex_info = expt.ToString();
|
||||
MessageBox.Show(ex_info, "An OpenTK example encountered an error.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
|
||||
Debug.Print(expt.ToString());
|
||||
#if DEBUG
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
catch (NullReferenceException expt)
|
||||
{
|
||||
MessageBox.Show(expt.ToString(), "The Example launcher failed to load the example.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.Visible = true;
|
||||
this.TopMost = true; // Bring the ExampleLauncher window to front
|
||||
this.TopMost = false; // but don't allow the user to cover it with other windows.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Launcher events
|
||||
|
||||
private void listBox1_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
|
@ -199,6 +188,16 @@ namespace Examples
|
|||
RunExample();
|
||||
}
|
||||
|
||||
private void ExampleLauncher_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
Debug.Flush();
|
||||
Debug.Close();
|
||||
Trace.Flush();
|
||||
Trace.Close();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
|
@ -211,13 +210,5 @@ namespace Examples
|
|||
Application.Run(exampleLauncher);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExampleLauncher_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
Debug.Flush();
|
||||
Debug.Close();
|
||||
Trace.Flush();
|
||||
Trace.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,15 +22,22 @@ namespace Examples.Tutorial
|
|||
/// <summary>
|
||||
/// Tests Font loading and rendering.
|
||||
/// </summary>
|
||||
class Fonts : GameWindow, IExample
|
||||
[Example("Fonts", ExampleCategory.Tutorial, 3)]
|
||||
class Fonts : GameWindow
|
||||
{
|
||||
public Fonts() : base(new DisplayMode(800, 600), String.Format("OpenTK | Tutorial {0}: Fonts", order))
|
||||
public Fonts() : base(new DisplayMode(800, 600))
|
||||
{ }
|
||||
|
||||
#region --- Fields ---
|
||||
|
||||
ITextPrinter printer = new TextPrinter();
|
||||
const string text = "Hello, world!";
|
||||
|
||||
TextHandle[] handles; // Used to cache the strings we want to print.
|
||||
|
||||
// Load some different TextureFont sizes to compare their quality.
|
||||
// You'll never need to load that many fonts in your application,
|
||||
// 3 or 4 should be more than enough.
|
||||
TextureFont[] fonts = new TextureFont[]
|
||||
{
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 8.0f)),
|
||||
|
@ -73,7 +80,10 @@ namespace Examples.Tutorial
|
|||
new TextureFont(new Font(FontFamily.GenericSansSerif, 36.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 38.0f)),
|
||||
};
|
||||
TextHandle[] handles; // Used to cache the strings we want to print.
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnLoad
|
||||
|
||||
/// <summary>
|
||||
/// To maintain high rendering performance, we need to cache the text
|
||||
|
@ -95,6 +105,10 @@ namespace Examples.Tutorial
|
|||
printer.Prepare(text, fonts[i], out handles[i]);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnUnload
|
||||
|
||||
/// <summary>
|
||||
/// It is important that we need to call the Dispose() methods to reclaim of
|
||||
/// each and every TextHandle and TextureFont to reclaim the unamanged
|
||||
|
@ -109,17 +123,29 @@ namespace Examples.Tutorial
|
|||
f.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnResize
|
||||
|
||||
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
||||
{
|
||||
GL.Viewport(0, 0, Width, Height);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnUpdateFrame
|
||||
|
||||
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
||||
{
|
||||
if (Keyboard[Key.Escape])
|
||||
this.Exit();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnRenderFrame
|
||||
|
||||
/// <summary>
|
||||
/// To render pixel-perfect text, we have to setup a 2d display projection
|
||||
/// with a width/height that corresponds to our current Viewport.
|
||||
|
@ -167,14 +193,23 @@ namespace Examples.Tutorial
|
|||
SwapBuffers();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IExample Members
|
||||
#region public static void Main()
|
||||
|
||||
public static readonly int order = 6;
|
||||
|
||||
public void Launch()
|
||||
/// <summary>
|
||||
/// Entry point of this example.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
Run(30.0, 0.0);
|
||||
using (Fonts example = new Fonts())
|
||||
{
|
||||
// Get the title and category of this example using reflection.
|
||||
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
||||
example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||
example.Run(30.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -20,9 +20,10 @@ namespace Examples.Tutorial
|
|||
/// <summary>
|
||||
/// Demonstrates the GameWindow class.
|
||||
/// </summary>
|
||||
public class T01_Simple_Window : GameWindow, IExample
|
||||
[Example("Simple Window", ExampleCategory.Tutorial, 1)]
|
||||
public class T01_Simple_Window : GameWindow
|
||||
{
|
||||
public T01_Simple_Window() : base(new DisplayMode(800, 600), "OpenTK | Tutorial 1: Simple Window")
|
||||
public T01_Simple_Window() : base(new DisplayMode(800, 600))
|
||||
{ }
|
||||
|
||||
#region OnLoad
|
||||
|
@ -102,18 +103,22 @@ namespace Examples.Tutorial
|
|||
|
||||
#endregion
|
||||
|
||||
#region IExample Members
|
||||
#region public static void Main()
|
||||
|
||||
/// <summary>
|
||||
/// Only used by the ExampleLauncher application, no need to add a Launch() method in your code.
|
||||
/// Add a call to Run() in your Main() function instead.
|
||||
/// Entry point of this example.
|
||||
/// </summary>
|
||||
public void Launch()
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
this.Run(30.0, 5.0);
|
||||
using (T01_Simple_Window example = new T01_Simple_Window())
|
||||
{
|
||||
// Get the title and category of this example using reflection.
|
||||
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
||||
example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||
example.Run(30.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly int order = 1;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -21,8 +21,10 @@ namespace Examples.Tutorial
|
|||
{
|
||||
/// <summary>
|
||||
/// Demonstrates Vertex Arrays (in system memory). Example is incomplete (documentation).
|
||||
/// Broken since release 0.3.12.
|
||||
/// </summary>
|
||||
class T02_Vertex_Arrays : GameWindow, IExample
|
||||
[Example("Vertex Arrays", ExampleCategory.OpenGL, 5, false)]
|
||||
class T02_Vertex_Arrays : GameWindow
|
||||
{
|
||||
float rotation_speed = 3.0f;
|
||||
float angle = 0.0f;
|
||||
|
|
|
@ -24,20 +24,19 @@ namespace Examples.Tutorial
|
|||
/// <summary>
|
||||
/// Demonstrates immediate mode rendering. Example is incomplete, and will probably go away in the future.
|
||||
/// </summary>
|
||||
public class T03_Immediate_Mode_Cube : OpenTK.GameWindow, IExample
|
||||
[Example("Immediate mode", ExampleCategory.Tutorial, 2)]
|
||||
public class T03_Immediate_Mode_Cube : GameWindow
|
||||
{
|
||||
#region --- Fields ---
|
||||
|
||||
/// <summary>
|
||||
/// Denotes the cube rotation.
|
||||
/// </summary>
|
||||
float angle = 0.0f;
|
||||
float rotation_speed = 3.0f;
|
||||
float angle;
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Constructors ---
|
||||
#region --- Constructor ---
|
||||
|
||||
public T03_Immediate_Mode_Cube() : base(new DisplayMode(800, 600), "OpenTK Tutorial: Immediate mode rendering")
|
||||
public T03_Immediate_Mode_Cube() : base(new DisplayMode(800, 600))
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
@ -48,7 +47,7 @@ namespace Examples.Tutorial
|
|||
{
|
||||
base.OnLoad(e);
|
||||
|
||||
GL.ClearColor(Color.MidnightBlue);
|
||||
GL.ClearColor(Color.SteelBlue);
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
}
|
||||
|
||||
|
@ -89,22 +88,11 @@ namespace Examples.Tutorial
|
|||
/// </remarks>
|
||||
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 += 3.0f;
|
||||
if (angle > 720.0f)
|
||||
angle -= 720.0f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -124,12 +112,12 @@ namespace Examples.Tutorial
|
|||
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);
|
||||
|
||||
DrawCube();
|
||||
|
||||
Context.SwapBuffers();
|
||||
Thread.Sleep(0);
|
||||
this.SwapBuffers();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -182,21 +170,23 @@ namespace Examples.Tutorial
|
|||
|
||||
#endregion
|
||||
|
||||
#region public void Launch()
|
||||
#region public static void Main()
|
||||
|
||||
/// <summary>
|
||||
/// Launches this example.
|
||||
/// Entry point of this example.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Provides a simple way for the example launcher to launch the examples.
|
||||
/// </remarks>
|
||||
public void Launch()
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
Run(85.0, 0.0);
|
||||
using (T03_Immediate_Mode_Cube example = new T03_Immediate_Mode_Cube())
|
||||
{
|
||||
// Get the title and category of this example using reflection.
|
||||
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
||||
example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||
example.Run(30.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static readonly int order = 3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ using OpenTK.OpenGL.Enums;
|
|||
|
||||
namespace Examples.Tutorial
|
||||
{
|
||||
public class T07_Display_Lists_Flower : GameWindow, IExample
|
||||
[Example("Display Lists", ExampleCategory.Tutorial, 3)]
|
||||
public class T07_Display_Lists_Flower : GameWindow
|
||||
{
|
||||
#region --- Fields ---
|
||||
|
||||
|
@ -35,7 +36,7 @@ namespace Examples.Tutorial
|
|||
#region --- Constructors ---
|
||||
|
||||
public T07_Display_Lists_Flower()
|
||||
: base(new DisplayMode(800, 600), "OpenTK | T07: Display Lists")
|
||||
: base(new DisplayMode(800, 600))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -141,21 +142,23 @@ namespace Examples.Tutorial
|
|||
|
||||
#endregion
|
||||
|
||||
#region public void Launch()
|
||||
#region public static void Main()
|
||||
|
||||
/// <summary>
|
||||
/// Launches this example.
|
||||
/// Entry point of this example.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Provides a simple way for the example launcher to launch the examples.
|
||||
/// </remarks>
|
||||
public void Launch()
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
this.Run(30.0, 5.0);
|
||||
using (T07_Display_Lists_Flower example = new T07_Display_Lists_Flower())
|
||||
{
|
||||
// Get the title and category of this example using reflection.
|
||||
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
||||
example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||
example.Run(30.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static readonly int order = 7;
|
||||
}
|
||||
}
|
|
@ -27,8 +27,8 @@ namespace Examples.Tutorial
|
|||
/// <summary>
|
||||
/// Demonstrates how to load and use a simple OpenGL shader program. Example is incomplete (documentation).
|
||||
/// </summary>
|
||||
[Example("OpenTK | GLSL Example 1", ExampleCategory.GLSL, 1)]
|
||||
public class T10_GLSL_Cube : GameWindow, IExample
|
||||
[Example("First shader", ExampleCategory.GLSL, 1)]
|
||||
public class T10_GLSL_Cube : GameWindow
|
||||
{
|
||||
#region --- Fields ---
|
||||
|
||||
|
@ -43,10 +43,8 @@ namespace Examples.Tutorial
|
|||
#region --- Constructors ---
|
||||
|
||||
public T10_GLSL_Cube()
|
||||
: base(new DisplayMode(800, 600), T10_GLSL_Cube.Title)
|
||||
{
|
||||
|
||||
}
|
||||
: base(new DisplayMode(800, 600))
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -81,6 +79,10 @@ namespace Examples.Tutorial
|
|||
out shader_program);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreateShaders
|
||||
|
||||
void CreateShaders(string vs, string fs,
|
||||
out int vertexObject, out int fragmentObject,
|
||||
out int program)
|
||||
|
@ -117,6 +119,8 @@ namespace Examples.Tutorial
|
|||
GL.UseProgram(program);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region private void CreateVBO()
|
||||
|
||||
void CreateVBO()
|
||||
|
@ -151,8 +155,6 @@ namespace Examples.Tutorial
|
|||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnUnload
|
||||
|
||||
public override void OnUnload(EventArgs e)
|
||||
|
@ -255,25 +257,22 @@ namespace Examples.Tutorial
|
|||
|
||||
#endregion
|
||||
|
||||
#region Example members
|
||||
|
||||
#region public void Launch()
|
||||
#region public static void Main()
|
||||
|
||||
/// <summary>
|
||||
/// Launches this example.
|
||||
/// Entry point of this example.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Provides a simple way for the example launcher to launch the examples.
|
||||
/// </remarks>
|
||||
public void Launch()
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
Run(30.0, 0.0);
|
||||
using (T10_GLSL_Cube example = new T10_GLSL_Cube())
|
||||
{
|
||||
// Get the title and category of this example using reflection.
|
||||
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
||||
example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||
example.Run(30.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
static readonly ExampleAttribute info = typeof(T10_GLSL_Cube).GetCustomAttributes(false)[0] as ExampleAttribute;
|
||||
static readonly string Title = info.Title;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -22,13 +22,14 @@ namespace Examples.Tutorial
|
|||
/// <summary>
|
||||
/// Shows how to render and scroll large amounts of text.
|
||||
/// </summary>
|
||||
public class Text : GameWindow, IExample
|
||||
[Example("Text", ExampleCategory.Tutorial, 4)]
|
||||
public class Text : GameWindow
|
||||
{
|
||||
TextureFont serif = new TextureFont(new Font(FontFamily.GenericSerif, 24.0f));
|
||||
TextHandle poem_handle;
|
||||
ITextPrinter text = new TextPrinter();
|
||||
|
||||
public Text() : base(new DisplayMode(800, 600), String.Format("OpenTK | Tutorial {0}: Text", order))
|
||||
public Text() : base(new DisplayMode(800, 600))
|
||||
{ }
|
||||
|
||||
string poem = new StreamReader("Data/Poem.txt").ReadToEnd();
|
||||
|
@ -138,13 +139,21 @@ namespace Examples.Tutorial
|
|||
|
||||
#endregion
|
||||
|
||||
#region --- IExample Members ---
|
||||
#region public static void Main()
|
||||
|
||||
public static readonly int order = 7;
|
||||
|
||||
public void Launch()
|
||||
/// <summary>
|
||||
/// Entry point of this example.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
Run(30.0, 0.0);
|
||||
using (Text example = new Text())
|
||||
{
|
||||
// Get the title and category of this example using reflection.
|
||||
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
||||
example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||
example.Run(30.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -23,13 +23,13 @@ namespace Examples.Tutorial
|
|||
/// <summary>
|
||||
/// Demonstrates simple OpenGL Texturing.
|
||||
/// </summary>
|
||||
public class Textures : GameWindow, IExample
|
||||
[Example("Texture mapping", ExampleCategory.Tutorial, 5)]
|
||||
public class Textures : GameWindow
|
||||
{
|
||||
Bitmap bitmap = new Bitmap("Data\\metal.jpg");
|
||||
Bitmap bitmap = new Bitmap("Data\\logo-dark.jpg");
|
||||
int texture;
|
||||
TextureFont sans = new TextureFont(new Font(FontFamily.GenericSansSerif, 24.0f));
|
||||
|
||||
public Textures() : base(new DisplayMode(800, 600), "OpenTK | Tutorial 5: Texturing") { }
|
||||
public Textures() : base(new DisplayMode(800, 600)) { }
|
||||
|
||||
#region OnLoad
|
||||
|
||||
|
@ -39,18 +39,16 @@ namespace Examples.Tutorial
|
|||
/// <param name="e">Not used.</param>
|
||||
public override void OnLoad(EventArgs e)
|
||||
{
|
||||
GL.ClearColor(Color.MidnightBlue);
|
||||
GL.ClearColor(Color.SteelBlue);
|
||||
GL.Enable(EnableCap.Texture2d);
|
||||
|
||||
GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
|
||||
|
||||
//bitmap = new OpenTK.Fonts.Renderer().bmp;
|
||||
//bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
|
||||
GL.GenTextures(1, out texture);
|
||||
GL.BindTexture(TextureTarget.Texture2d, texture);
|
||||
|
||||
BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
|
||||
ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
|
||||
ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
|
||||
GL.TexImage2D(TextureTarget.Texture2d, 0, PixelInternalFormat.Three, bitmap.Width, bitmap.Height, 0,
|
||||
OpenTK.OpenGL.Enums.PixelFormat.Bgr, PixelType.UnsignedByte, data.Scan0);
|
||||
|
@ -63,6 +61,15 @@ namespace Examples.Tutorial
|
|||
|
||||
#endregion
|
||||
|
||||
#region OnUnload
|
||||
|
||||
public override void OnUnload(EventArgs e)
|
||||
{
|
||||
GL.DeleteTextures(1, ref texture);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnResize
|
||||
|
||||
/// <summary>
|
||||
|
@ -72,7 +79,7 @@ namespace Examples.Tutorial
|
|||
/// <remarks>There is no need to call the base implementation.</remarks>
|
||||
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
||||
{
|
||||
GL.Viewport(0, 0, e.Width, e.Height);
|
||||
GL.Viewport(0, 0, Width, Height);
|
||||
|
||||
GL.MatrixMode(MatrixMode.Projection);
|
||||
GL.LoadIdentity();
|
||||
|
@ -107,40 +114,41 @@ namespace Examples.Tutorial
|
|||
{
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||
|
||||
GL.MatrixMode(MatrixMode.Modelview);
|
||||
GL.LoadIdentity();
|
||||
GL.BindTexture(TextureTarget.Texture2d, texture);
|
||||
|
||||
GL.Begin(BeginMode.Quads);
|
||||
|
||||
GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(-0.8f + 0.0375f, -0.8f + 0.0375f);
|
||||
GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(0.8f + 0.0375f, -0.8f + 0.0375f);
|
||||
GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(0.8f + 0.0375f, 0.8f + 0.0375f);
|
||||
GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-0.8f + 0.0375f, 0.8f + 0.0375f);
|
||||
GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(-0.6f, -0.4f);
|
||||
GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(0.6f, -0.4f);
|
||||
GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(0.6f, 0.4f);
|
||||
GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-0.6f, 0.4f);
|
||||
|
||||
GL.End();
|
||||
|
||||
//sans.
|
||||
GL.Scale(2.0f / Width, 2.0f / Height, 1.0f);
|
||||
//sans.Print('A');
|
||||
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IExample Members
|
||||
#region public static void Main()
|
||||
|
||||
/// <summary>
|
||||
/// Only used by the ExampleLauncher application, no need to add a Launch() method in your code.
|
||||
/// Add a call to Run() in your Main() function instead.
|
||||
/// Entry point of this example.
|
||||
/// </summary>
|
||||
public void Launch()
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
this.Run(10.0, 5.0);
|
||||
using (Textures example = new Textures())
|
||||
{
|
||||
// Get the title and category of this example using reflection.
|
||||
ExampleAttribute info = ((ExampleAttribute)typeof(Textures).GetCustomAttributes(false)[0]);
|
||||
example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||
example.Run(30.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static readonly int order = 5;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,8 @@ using OpenTK.OpenGL.Enums;
|
|||
|
||||
namespace Examples.WinForms
|
||||
{
|
||||
public partial class W01_First_Window : Form, IExample
|
||||
[Example("Simple GLControl", ExampleCategory.WinForms, 1)]
|
||||
public partial class W01_First_Window : Form
|
||||
{
|
||||
public W01_First_Window()
|
||||
{
|
||||
|
@ -38,6 +39,8 @@ namespace Examples.WinForms
|
|||
}
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
|
@ -87,14 +90,24 @@ namespace Examples.WinForms
|
|||
}
|
||||
}
|
||||
|
||||
#region IExample Members
|
||||
#endregion
|
||||
|
||||
public void Launch()
|
||||
#region public static void Main()
|
||||
|
||||
/// <summary>
|
||||
/// Entry point of this example.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
|
||||
using (W01_First_Window example = new W01_First_Window())
|
||||
{
|
||||
// Get the title and category of this example using reflection.
|
||||
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
||||
example.Text = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||
example.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly int order = 1;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
this.glControl.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.glControl.Location = new System.Drawing.Point(0, 0);
|
||||
this.glControl.Name = "glControl";
|
||||
this.glControl.Size = new System.Drawing.Size(624, 444);
|
||||
this.glControl.Size = new System.Drawing.Size(784, 564);
|
||||
this.glControl.TabIndex = 0;
|
||||
this.glControl.VSync = false;
|
||||
this.glControl.Layout += new System.Windows.Forms.LayoutEventHandler(this.glControl_Layout);
|
||||
|
@ -46,7 +46,7 @@
|
|||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(624, 444);
|
||||
this.ClientSize = new System.Drawing.Size(784, 564);
|
||||
this.Controls.Add(this.glControl);
|
||||
this.Name = "W02_Immediate_Mode_Cube";
|
||||
this.Text = "Cube";
|
||||
|
|
|
@ -25,7 +25,8 @@ using OpenTK.OpenGL.Enums;
|
|||
|
||||
namespace Examples.WinForms
|
||||
{
|
||||
public partial class W02_Immediate_Mode_Cube : Form, IExample
|
||||
[Example("GLControl game loop", ExampleCategory.WinForms, 2)]
|
||||
public partial class W02_Immediate_Mode_Cube : Form
|
||||
{
|
||||
static float angle = 0.0f;
|
||||
|
||||
|
@ -86,29 +87,6 @@ namespace Examples.WinForms
|
|||
|
||||
#endregion
|
||||
|
||||
#region private void Render()
|
||||
|
||||
private void Render()
|
||||
{
|
||||
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.Rotate(angle, 0.0f, 1.0f, 0.0f);
|
||||
angle += 0.5f;
|
||||
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
DrawCube();
|
||||
|
||||
glControl.SwapBuffers();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GLControl.Resize event handler
|
||||
|
||||
void glControl_Resize(object sender, EventArgs e)
|
||||
|
@ -151,6 +129,29 @@ namespace Examples.WinForms
|
|||
Render();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region private void Render()
|
||||
|
||||
private void Render()
|
||||
{
|
||||
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.Rotate(angle, 0.0f, 1.0f, 0.0f);
|
||||
angle += 0.5f;
|
||||
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
DrawCube();
|
||||
|
||||
glControl.SwapBuffers();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region private void DrawCube()
|
||||
|
@ -201,20 +202,28 @@ namespace Examples.WinForms
|
|||
|
||||
#endregion
|
||||
|
||||
#region IExample Members
|
||||
|
||||
public void Launch()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static readonly int order = 2;
|
||||
|
||||
#endregion
|
||||
|
||||
private void glControl_Layout(object sender, LayoutEventArgs e)
|
||||
{
|
||||
glControl_Resize(sender, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#region public static void Main()
|
||||
|
||||
/// <summary>
|
||||
/// Entry point of this example.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
using (W02_Immediate_Mode_Cube example = new W02_Immediate_Mode_Cube())
|
||||
{
|
||||
// Get the title and category of this example using reflection.
|
||||
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
||||
example.Text = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||
example.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,11 @@ using OpenTK.OpenGL.Enums;
|
|||
|
||||
namespace Examples.WinForms
|
||||
{
|
||||
public partial class W03_Extensions : Form, IExample
|
||||
[Example("Extensions", ExampleCategory.WinForms, 3)]
|
||||
public partial class W03_Extensions : Form
|
||||
{
|
||||
GLControl glControl = new GLControl();
|
||||
Assembly assembly;
|
||||
//GLControl glControl = new GLControl();
|
||||
GLContext context;
|
||||
Type glClass;
|
||||
Type delegatesClass;
|
||||
Type importsClass;
|
||||
|
@ -34,18 +35,22 @@ namespace Examples.WinForms
|
|||
{
|
||||
InitializeComponent();
|
||||
|
||||
assembly = Assembly.Load("OpenTK");
|
||||
glClass = assembly.GetType("OpenTK.OpenGL.GL");
|
||||
glClass = typeof(GL);
|
||||
delegatesClass = glClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
importsClass = glClass.GetNestedType("Imports", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
|
||||
glControl.Load += new EventHandler(glControl_Load);
|
||||
glControl.CreateControl();
|
||||
//glControl.CreateControl();
|
||||
Application.Idle += StartAsync;
|
||||
}
|
||||
|
||||
void glControl_Load(object sender, EventArgs e)
|
||||
void StartAsync(object sender, EventArgs e)
|
||||
{
|
||||
Application.Idle += StartAsync;
|
||||
Application.Idle -= StartAsync;
|
||||
|
||||
context = new GLContext(new DisplayMode(), new OpenTK.Platform.WindowInfo(this));
|
||||
context.CreateContext();
|
||||
|
||||
//while (!glControl.Created)
|
||||
|
||||
driver =
|
||||
GL.GetString(StringName.Vendor) + " " +
|
||||
|
@ -54,11 +59,6 @@ namespace Examples.WinForms
|
|||
|
||||
all = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic).Length;
|
||||
this.Text = String.Format("Loading {0} functions...", all);
|
||||
}
|
||||
|
||||
void StartAsync(object sender, EventArgs e)
|
||||
{
|
||||
Application.Idle -= StartAsync;
|
||||
|
||||
this.backgroundWorker1.RunWorkerAsync();
|
||||
}
|
||||
|
@ -74,9 +74,7 @@ namespace Examples.WinForms
|
|||
{
|
||||
object d = f.GetValue(delegatesClass);
|
||||
if (d != null)
|
||||
{
|
||||
++supported;
|
||||
}
|
||||
|
||||
backgroundWorker1.ReportProgress((int)(((float)i / all) * 100.0f),
|
||||
String.Format("({0}/{1}) {2}:\t{3}", (++i).ToString(), all, d != null ? "ok" : "failed", f.Name));
|
||||
|
@ -88,6 +86,7 @@ namespace Examples.WinForms
|
|||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
|
||||
{
|
||||
listBox1.Items.Add(e.UserState as string);
|
||||
|
@ -105,18 +104,29 @@ namespace Examples.WinForms
|
|||
*/
|
||||
}
|
||||
|
||||
#region IExample Members
|
||||
|
||||
public void Launch() { }
|
||||
|
||||
public static readonly int order = 3;
|
||||
|
||||
#endregion
|
||||
|
||||
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
this.Text = String.Format("{0}: {1}/{2} OpenGL functions supported.",
|
||||
driver, supported, all);
|
||||
}
|
||||
|
||||
#region public static void Main()
|
||||
|
||||
/// <summary>
|
||||
/// Entry point of this example.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
using (W03_Extensions example = new W03_Extensions())
|
||||
{
|
||||
// Get the title and category of this example using reflection.
|
||||
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
||||
example.Text = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||
example.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue