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:
parent
499d396690
commit
6fb1fe1e1b
8 changed files with 179 additions and 31 deletions
1
Source/Examples/ExampleLauncher.Designer.cs
generated
1
Source/Examples/ExampleLauncher.Designer.cs
generated
|
@ -66,6 +66,7 @@
|
|||
this.MinimumSize = new System.Drawing.Size(300, 300);
|
||||
this.Name = "ExampleLauncher";
|
||||
this.Text = "OpenTK Example Launcher";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ExampleLauncher_FormClosing);
|
||||
this.Load += new System.EventHandler(this.ExampleLauncher_Load);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
|
|
|
@ -38,6 +38,21 @@ namespace Examples
|
|||
|
||||
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
|
||||
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
|
||||
foreach (Type type in types)
|
||||
|
@ -159,36 +174,19 @@ namespace Examples
|
|||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
try
|
||||
using (Form exampleLauncher = new ExampleLauncher())
|
||||
{
|
||||
if (File.Exists("debug.log"))
|
||||
File.Delete("debug.log");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show("Could not access debug.log", e.ToString());
|
||||
Application.EnableVisualStyles();
|
||||
Application.Run(exampleLauncher);
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Listeners.Clear();
|
||||
Debug.Listeners.Add(new TextWriterTraceListener("debug.log"));
|
||||
Debug.Listeners.Add(new ConsoleTraceListener());
|
||||
Debug.AutoFlush = true;
|
||||
|
||||
try
|
||||
{
|
||||
using (Form exampleLauncher = new ExampleLauncher())
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.Run(exampleLauncher);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Debug.Flush();
|
||||
Debug.Close();
|
||||
Trace.Flush();
|
||||
Trace.Close();
|
||||
}
|
||||
private void ExampleLauncher_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
Debug.Flush();
|
||||
Debug.Close();
|
||||
Trace.Flush();
|
||||
Trace.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Diagnostics;
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.OpenGL;
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace Examples.Tutorial
|
|||
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);
|
||||
|
||||
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.GetShader(vertex_shader_object, GL.Enums.VERSION_2_0.COMPILE_STATUS, out status);
|
||||
if (status != (int)GL.Enums.Boolean.TRUE)
|
||||
|
@ -99,7 +99,7 @@ namespace Examples.Tutorial
|
|||
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.GetShader(fragment_shader_object, GL.Enums.VERSION_2_0.COMPILE_STATUS, out status);
|
||||
if (status != (int)GL.Enums.Boolean.TRUE)
|
||||
|
|
59
Source/Examples/WinForms/W03_Extensions.Designer.cs
generated
Normal file
59
Source/Examples/WinForms/W03_Extensions.Designer.cs
generated
Normal 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;
|
||||
}
|
||||
}
|
77
Source/Examples/WinForms/W03_Extensions.cs
Normal file
77
Source/Examples/WinForms/W03_Extensions.cs
Normal 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
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ using System.Text;
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Reflection;
|
||||
using OpenTK.Platform;
|
||||
using System.Diagnostics;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -236,10 +237,21 @@ namespace OpenTK.OpenGL
|
|||
public static void LoadAll()
|
||||
{
|
||||
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)
|
||||
{
|
||||
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();
|
||||
rebuildExtensionList = true;
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace OpenTK.Platform.X11
|
|||
Debug.Print("Native window driver: {0}", this.ToString());
|
||||
window = new WindowInfo();
|
||||
|
||||
Utilities.ThrowOnX11Error = true;
|
||||
//Utilities.ThrowOnX11Error = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
Loading…
Reference in a new issue