Updated T10_GLSL_Cube to remove NRE exception on Mono 1.2.x.

Added debug info to the GL.LoadAll function.
Added W03_Extensions.cs example.
This commit is contained in:
the_fiddler 2007-09-02 13:34:44 +00:00
parent 499d396690
commit 6fb1fe1e1b
8 changed files with 179 additions and 31 deletions

View file

@ -66,6 +66,7 @@
this.MinimumSize = new System.Drawing.Size(300, 300); this.MinimumSize = new System.Drawing.Size(300, 300);
this.Name = "ExampleLauncher"; this.Name = "ExampleLauncher";
this.Text = "OpenTK Example Launcher"; this.Text = "OpenTK Example Launcher";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ExampleLauncher_FormClosing);
this.Load += new System.EventHandler(this.ExampleLauncher_Load); this.Load += new System.EventHandler(this.ExampleLauncher_Load);
this.ResumeLayout(false); this.ResumeLayout(false);

View file

@ -38,6 +38,21 @@ namespace Examples
public void ExampleLauncher_Load(object sender, EventArgs e) public void ExampleLauncher_Load(object sender, EventArgs e)
{ {
try
{
if (File.Exists("debug.log"))
File.Delete("debug.log");
}
catch (Exception expt)
{
MessageBox.Show("Could not access debug.log", expt.ToString());
}
Debug.Listeners.Clear();
Debug.Listeners.Add(new TextWriterTraceListener("debug.log"));
Debug.Listeners.Add(new ConsoleTraceListener());
Debug.AutoFlush = true;
// Get all examples // Get all examples
Type[] types = Assembly.GetExecutingAssembly().GetTypes(); Type[] types = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type type in types) foreach (Type type in types)
@ -159,36 +174,19 @@ namespace Examples
[STAThread] [STAThread]
static void Main() static void Main()
{ {
try using (Form exampleLauncher = new ExampleLauncher())
{ {
if (File.Exists("debug.log")) Application.EnableVisualStyles();
File.Delete("debug.log"); Application.Run(exampleLauncher);
}
catch (Exception e)
{
MessageBox.Show("Could not access debug.log", e.ToString());
} }
}
Debug.Listeners.Clear(); private void ExampleLauncher_FormClosing(object sender, FormClosingEventArgs e)
Debug.Listeners.Add(new TextWriterTraceListener("debug.log")); {
Debug.Listeners.Add(new ConsoleTraceListener()); Debug.Flush();
Debug.AutoFlush = true; Debug.Close();
Trace.Flush();
try Trace.Close();
{
using (Form exampleLauncher = new ExampleLauncher())
{
Application.EnableVisualStyles();
Application.Run(exampleLauncher);
}
}
finally
{
Debug.Flush();
Debug.Close();
Trace.Flush();
Trace.Close();
}
} }
} }
} }

View file

@ -8,6 +8,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Drawing; using System.Drawing;
using System.Diagnostics;
using OpenTK; using OpenTK;
using OpenTK.OpenGL; using OpenTK.OpenGL;

View file

@ -86,7 +86,7 @@ namespace Examples.Tutorial
vertex_shader_object = (uint)GL.CreateShader(GL.Enums.VERSION_2_0.VERTEX_SHADER); vertex_shader_object = (uint)GL.CreateShader(GL.Enums.VERSION_2_0.VERTEX_SHADER);
fragment_shader_object = (uint)GL.CreateShader(GL.Enums.VERSION_2_0.FRAGMENT_SHADER); fragment_shader_object = (uint)GL.CreateShader(GL.Enums.VERSION_2_0.FRAGMENT_SHADER);
GL.ShaderSource(vertex_shader_object, vertex_shader_source.Length, vertex_shader_source, (int[])null); unsafe { GL.ShaderSource(vertex_shader_object, vertex_shader_source.Length, vertex_shader_source, (int*)null); }
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, GL.Enums.VERSION_2_0.COMPILE_STATUS, out status);
if (status != (int)GL.Enums.Boolean.TRUE) if (status != (int)GL.Enums.Boolean.TRUE)
@ -99,7 +99,7 @@ namespace Examples.Tutorial
throw new Exception(info.ToString()); throw new Exception(info.ToString());
} }
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); GL.CompileShader(fragment_shader_object);
GL.GetShader(fragment_shader_object, GL.Enums.VERSION_2_0.COMPILE_STATUS, out status); GL.GetShader(fragment_shader_object, GL.Enums.VERSION_2_0.COMPILE_STATUS, out status);
if (status != (int)GL.Enums.Boolean.TRUE) if (status != (int)GL.Enums.Boolean.TRUE)

View file

@ -0,0 +1,59 @@
namespace Examples.WinForms
{
partial class W03_Extensions
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(0, 0);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(284, 264);
this.listBox1.TabIndex = 0;
//
// W03_Extensions
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 264);
this.Controls.Add(this.listBox1);
this.Name = "W03_Extensions";
this.Text = "W03_Extensions";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListBox listBox1;
}
}

View file

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using OpenTK;
using System.Reflection;
using OpenTK.OpenGL;
namespace Examples.WinForms
{
public partial class W03_Extensions : Form//, IExample
{
GLControl glControl = new GLControl();
Assembly assembly;
Type glClass;
Type delegatesClass;
Type importsClass;
public W03_Extensions()
{
InitializeComponent();
assembly = Assembly.Load("OpenTK");
glClass = assembly.GetType("OpenTK.OpenGL.GL");
delegatesClass = glClass.GetNestedType("Delegates", BindingFlags.Static | BindingFlags.NonPublic);
importsClass = glClass.GetNestedType("Imports", BindingFlags.Static | BindingFlags.NonPublic);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
glControl.CreateContext();
FieldInfo[] v = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic);
int i = 0, supported = 0;
try
{
foreach (FieldInfo f in v)
{
Delegate d = GL.GetDelegate(f.Name, f.FieldType);
f.SetValue(null, d);
this.listBox1.Items.Add(String.Format("{0}/{1} {2}: {3}",
(++i).ToString(), v.Length, d != null ? "ok" : "failed", f.Name));
if (d != null)
{
++supported;
}
}
this.Text = String.Format("Supported extensions: {0}", supported);
}
catch (Exception expt)
{
MessageBox.Show("An error occured while loading extensions", "Extension loading failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
throw;
}
}
#region IExample Members
public void Launch()
{
}
#endregion
}
}

View file

@ -12,6 +12,7 @@ using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Reflection; using System.Reflection;
using OpenTK.Platform; using OpenTK.Platform;
using System.Diagnostics;
#endregion #endregion
@ -236,10 +237,21 @@ namespace OpenTK.OpenGL
public static void LoadAll() public static void LoadAll()
{ {
FieldInfo[] v = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic); FieldInfo[] v = delegatesClass.GetFields(BindingFlags.Static | BindingFlags.NonPublic);
int supported = 0;
Debug.Print("Will now try to load all {0} opengl functions.", v.Length);
foreach (FieldInfo f in v) foreach (FieldInfo f in v)
{ {
f.SetValue(null, GetDelegate(f.Name, f.FieldType)); Delegate d = GetDelegate(f.Name, f.FieldType);
if (d != null)
{
++supported;
}
f.SetValue(null, d);
} }
Debug.Print("Total supported functions: {0}.", supported);
AvailableExtensions.Clear(); AvailableExtensions.Clear();
rebuildExtensionList = true; rebuildExtensionList = true;

View file

@ -56,7 +56,7 @@ namespace OpenTK.Platform.X11
Debug.Print("Native window driver: {0}", this.ToString()); Debug.Print("Native window driver: {0}", this.ToString());
window = new WindowInfo(); window = new WindowInfo();
Utilities.ThrowOnX11Error = true; //Utilities.ThrowOnX11Error = true;
} }
#endregion #endregion