Added Create and Destroy events to NativeGLWindow.

This commit is contained in:
the_fiddler 2007-08-06 11:22:18 +00:00
parent f30e7f6df8
commit 863a8e9557
17 changed files with 504 additions and 366 deletions

View file

@ -60,9 +60,9 @@ namespace Examples.Tests
GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
public override void OnRenderFrame()
public override void OnRenderFrame(EventArgs e)
{
base.OnRenderFrame();
base.OnRenderFrame(e);
GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT);
Context.SwapBuffers();
@ -73,8 +73,8 @@ namespace Examples.Tests
while (!Quit)
{
ProcessEvents();
OnUpdateFrame();
OnRenderFrame();
OnUpdateFrame(EventArgs.Empty);
OnRenderFrame(EventArgs.Empty);
Thread.Sleep(10);
}
}

View file

@ -35,18 +35,23 @@ namespace Examples.Tutorial
public T03_RotatingCube()
{
CreateWindow(new DisplayMode(800, 600));
Context.MakeCurrent();
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
GL.Enable(Enums.EnableCap.DEPTH_TEST);
this.OnResize(new ResizeEventArgs(this.Width, this.Height));
}
#endregion
#region Resize event handler
#region OnLoad
public override void OnLoad(EventArgs e)
{
base.OnLoad(e);
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
GL.Enable(Enums.EnableCap.DEPTH_TEST);
}
#endregion
#region OnResize
/// <summary>
/// Called when the user resizes the window.
@ -70,7 +75,7 @@ namespace Examples.Tutorial
#endregion
#region OnUpdateFrame function
#region OnUpdateFrame
/// <summary>
/// Prepares the next frame for rendering.
@ -79,7 +84,7 @@ namespace Examples.Tutorial
/// Place your control logic here. This is the place to respond to user input,
/// update object positions etc.
/// </remarks>
public override void OnUpdateFrame()
public override void OnUpdateFrame(EventArgs e)
{
if (Keyboard[0][OpenTK.Input.Key.Escape])
{
@ -107,12 +112,12 @@ namespace Examples.Tutorial
#endregion
#region OnRenderFrame function
#region OnRenderFrame
/// <summary>
/// Place your rendering code here.
/// </summary>
public override void OnRenderFrame()
public override void OnRenderFrame(EventArgs e)
{
GL.Clear(Enums.ClearBufferMask.COLOR_BUFFER_BIT | Enums.ClearBufferMask.DEPTH_BUFFER_BIT);

View file

@ -120,11 +120,25 @@ namespace Examples.Tutorial
#endregion
#region OnUpdateFrame
public override void OnUpdateFrame(EventArgs e)
{
base.OnUpdateFrame(e);
if (Keyboard[0][OpenTK.Input.Key.Escape])
{
this.Exit();
}
}
#endregion
#region OnRenderFrame
public override void OnRenderFrame()
public override void OnRenderFrame(EventArgs e)
{
base.OnRenderFrame();
base.OnRenderFrame(e);
GL.MatrixMode(Enums.MatrixMode.MODELVIEW);
GL.LoadIdentity();
@ -148,20 +162,6 @@ namespace Examples.Tutorial
#endregion
#region OnUpdateFrame
public override void OnUpdateFrame()
{
base.OnUpdateFrame();
if (Keyboard[0][OpenTK.Input.Key.Escape])
{
this.Exit();
}
}
#endregion
#endregion --- Event Handlers ---
}
}

View file

@ -73,8 +73,22 @@ namespace Examples.Tutorial
public T08_VBO()
{
this.CreateWindow(new DisplayMode(800, 600));
}
this.Context.MakeCurrent();
#endregion
#region OnLoad
public override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!GL.IsExtensionSupported("VERSION_1_4"))
{
System.Windows.Forms.MessageBox.Show("You need at least OpenGL 1.4 to run this example. Aborting.", "VBOs not supported",
System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
this.Exit();
}
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
@ -88,11 +102,59 @@ namespace Examples.Tutorial
#endregion
#region OnResize
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
{
base.OnResize(e);
GL.Viewport(0, 0, e.Width, e.Height);
double ratio = e.Width / (double)e.Height;
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
GL.LoadIdentity();
Glu.Perspective(45.0, ratio, 1.0, 64.0);
}
#endregion
#region OnUpdateFrame
/// <summary>
/// Prepares the next frame for rendering.
/// </summary>
/// <remarks>
/// Place your control logic here. This is the place to respond to user input,
/// update object positions etc.
/// </remarks>
public override void OnUpdateFrame(EventArgs e)
{
if (Keyboard[0][OpenTK.Input.Key.Escape])
{
this.Exit();
return;
}
GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW);
GL.LoadIdentity();
Glu.LookAt(
0.0, 5.0, 5.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0
);
//GL.Rotatef(angle, 0.0f, 1.0f, 0.0f);
//angle += 0.5f;
}
#endregion
#region OnRenderFrame
public override void OnRenderFrame()
public override void OnRenderFrame(EventArgs e)
{
base.OnRenderFrame();
base.OnRenderFrame(e);
GL.Clear(
GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT |
@ -119,54 +181,6 @@ namespace Examples.Tutorial
#endregion
#region OnUpdateFrame
/// <summary>
/// Prepares the next frame for rendering.
/// </summary>
/// <remarks>
/// Place your control logic here. This is the place to respond to user input,
/// update object positions etc.
/// </remarks>
public override void OnUpdateFrame()
{
if (Keyboard[0][OpenTK.Input.Key.Escape])
{
this.Exit();
return;
}
GL.MatrixMode(GL.Enums.MatrixMode.MODELVIEW);
GL.LoadIdentity();
Glu.LookAt(
0.0, 5.0, 5.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0
);
//GL.Rotatef(angle, 0.0f, 1.0f, 0.0f);
//angle += 0.5f;
}
#endregion
#region Resize event
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
{
base.OnResize(e);
GL.Viewport(0, 0, e.Width, e.Height);
double ratio = e.Width / (double)e.Height;
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
GL.LoadIdentity();
Glu.Perspective(45.0, ratio, 1.0, 64.0);
}
#endregion
#region LoadCube
private void LoadCube()

View file

@ -51,12 +51,62 @@ namespace Examples.Tutorial
public T10_GLSL_Cube()
{
this.CreateWindow(new OpenTK.Platform.DisplayMode(800, 600));
Context.MakeCurrent();
}
#endregion
#region public void Launch()
/// <summary>
/// Launches this example.
/// </summary>
/// <remarks>
/// Provides a simple way for the example launcher to launch the examples.
/// </remarks>
public void Launch()
{
Run();
}
#endregion
#region OnCreate
/// <summary>
/// This is the place to change window parameters.
/// </summary>
/// <param name="e">Not used.</param>
public override void OnCreate(EventArgs e)
{
base.OnCreate(e);
//Text =
// GL.GetString(Enums.StringName.VENDOR) + " " +
// GL.GetString(Enums.StringName.RENDERER) + " " +
// GL.GetString(Enums.StringName.VERSION);
}
#endregion
#region OnLoad
/// <summary>
/// This is the place to load resources that change little
/// during the lifetime of the GameWindow. In this case, we
/// check for GLSL support, and load the shaders.
/// </summary>
/// <param name="e">Not used.</param>
public override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Check for necessary capabilities:
if (!GL.IsExtensionSupported("VERSION_2_0"))
{
MessageBox.Show("You need at least OpenGL 2.0 to run this example. Aborting.", "GLSL not supported",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.Exit();
}
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
@ -106,25 +156,6 @@ namespace Examples.Tutorial
#endregion
#region public void Launch()
/// <summary>
/// Launches this example.
/// </summary>
/// <remarks>
/// Provides a simple way for the example launcher to launch the examples.
/// </remarks>
public void Launch()
{
//using (T10_GLSL_Cube ex = new T10_GLSL_Cube())
{
//ex.Run();
Run();
}
}
#endregion
#region OnResize
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
@ -145,9 +176,13 @@ namespace Examples.Tutorial
#region OnUpdateFrame
public override void OnUpdateFrame()
/// <summary>
/// Occurs when it is time to update the next frame.
/// </summary>
/// <param name="e">Not used yet.</param>
public override void OnUpdateFrame(EventArgs e)
{
base.OnUpdateFrame();
base.OnUpdateFrame(e);
if (Keyboard[0][OpenTK.Input.Key.Escape])
{
@ -169,9 +204,9 @@ namespace Examples.Tutorial
#region OnRenderFrame
public override void OnRenderFrame()
public override void OnRenderFrame(EventArgs e)
{
base.OnRenderFrame();
base.OnRenderFrame(e);
GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT | GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);

View file

@ -55,6 +55,12 @@ namespace OpenTK
glWindow.Resize += new ResizeEvent(glWindow_Resize);
glWindow.Create += new CreateEvent(glWindow_CreateInputDriver);
glWindow.Destroy += new DestroyEvent(glWindow_Destroy);
}
void glWindow_Destroy(object sender, EventArgs e)
{
this.isExiting = true;
}
void glWindow_CreateInputDriver(object sender, EventArgs e)
@ -98,27 +104,6 @@ namespace OpenTK
#region --- INativeGLWindow Members ---
#region public void CreateWindow(DisplayMode mode)
/// <summary>
/// Creates a new render window.
/// </summary>
/// <param name="mode">The DisplayMode of the render window.</param>
/// <exception cref="ApplicationException">Occurs when a render window already exists.</exception>
public void CreateWindow(DisplayMode mode)
{
if (!Exists)
{
glWindow.CreateWindow(mode);
}
else
{
throw new ApplicationException("A render window already exists");
}
}
#endregion
#region public void Exit()
/// <summary>
@ -219,6 +204,71 @@ namespace OpenTK
#endregion
#region public void CreateWindow(DisplayMode mode)
/// <summary>
/// Creates a new render window.
/// </summary>
/// <param name="mode">The DisplayMode of the render window.</param>
/// <exception cref="ApplicationException">Occurs when a render window already exists.</exception>
public void CreateWindow(DisplayMode mode)
{
if (!Exists)
{
glWindow.CreateWindow(mode);
}
else
{
throw new ApplicationException("A render window already exists");
}
}
#endregion
#region OnCreate
public event CreateEvent Create;
public virtual void OnCreate(EventArgs e)
{
if (this.Create != null)
{
this.Create(this, e);
}
}
#endregion
#region public void DestroyWindow()
public void DestroyWindow()
{
if (Exists)
{
glWindow.DestroyWindow();
}
else
{
throw new ApplicationException("Tried to destroy inexistent window.");
}
}
#endregion
#region OnDestroy
public virtual void OnDestroy(EventArgs e)
{
if (this.Destroy != null)
{
this.Destroy(this, e);
}
}
public event DestroyEvent Destroy;
#endregion
#endregion
#region --- IGameWindow Members ---
@ -242,17 +292,30 @@ namespace OpenTK
/// </remarks>
public virtual void Run()
{
this.OnLoad(EventArgs.Empty);
resizeEventArgs.Width = this.Width;
resizeEventArgs.Height = this.Height;
this.OnResize(resizeEventArgs);
Debug.Print("Entering main loop");
while (!this.Quit && !IsExiting)
{
this.ProcessEvents();
this.OnUpdateFrame();
this.OnRenderFrame();
if (!IsExiting)
{
this.OnUpdateFrame(EventArgs.Empty);
this.OnRenderFrame(EventArgs.Empty);
}
}
glWindow.Exit();
while (glWindow.Exists)
if (glWindow.Exists)
{
this.ProcessEvents();
glWindow.Exit();
while (glWindow.Exists)
{
this.ProcessEvents();
}
}
}
@ -280,21 +343,7 @@ namespace OpenTK
#endregion
#region public event CreateEvent Create;
public event CreateEvent Create;
private void OnCreate(EventArgs e)
{
if (this.Create != null)
{
this.Create(this, e);
}
}
#endregion
#region public virtual void OnRenderFrame()
#region public virtual void OnRenderFrame(EventArgs e)
/// <summary>
/// Raises the RenderFrame event. Override in derived classes to render a frame.
@ -303,7 +352,7 @@ namespace OpenTK
/// If overriden, the base.OnRenderFrame() function should be called, to ensure
/// listeners are notified of RenderFrame events.
/// </remarks>
public virtual void OnRenderFrame()
public virtual void OnRenderFrame(EventArgs e)
{
if (!this.Exists)
{
@ -312,12 +361,17 @@ namespace OpenTK
this.CreateWindow(mode);
}
if (RenderFrame != null)
RenderFrame(EventArgs.Empty);
RenderFrame(this, e);
}
/// <summary>
/// Occurs when it is time to render the next frame.
/// </summary>
public event RenderFrameEvent RenderFrame;
#endregion
#region public virtual void OnUpdateFrame()
#region public virtual void OnUpdateFrame(EventArgs e)
/// <summary>
/// Raises the UpdateFrame event. Override in derived classes to update a frame.
@ -326,7 +380,7 @@ namespace OpenTK
/// If overriden, the base.OnUpdateFrame() function should be called, to ensure
/// listeners are notified of UpdateFrame events.
/// </remarks>
public virtual void OnUpdateFrame()
public virtual void OnUpdateFrame(EventArgs e)
{
if (!this.Exists)
{
@ -335,20 +389,38 @@ namespace OpenTK
this.CreateWindow(mode);
}
if (UpdateFrame != null)
UpdateFrame(EventArgs.Empty);
UpdateFrame(this, e);
}
#endregion
/// <summary>
/// Occurs when it is time to update the next frame.
/// </summary>
public event UpdateFrameEvent UpdateFrame;
#endregion
#region public virtual void OnLoad(EventArgs e)
/// <summary>
/// Occurs when it is time to render the next frame.
/// Raises the Load event. Override to load resources that should
/// be maintained for the lifetime of the application.
/// </summary>
public event RenderFrameEvent RenderFrame;
public virtual void OnLoad(EventArgs e)
{
Debug.Print("Firing GameWindow.Load event.");
if (this.Load != null)
{
this.Load(this, e);
}
}
/// <summary>
/// Occurs after the GameWindow has been created, but before
/// entering the main loop.
/// </summary>
public event LoadEvent Load;
#endregion
#region public bool IsExiting
@ -446,6 +518,7 @@ namespace OpenTK
/// <param name="e">Contains the new Width and Height of the window.</param>
protected virtual void OnResize(ResizeEventArgs e)
{
Debug.Print("Firing GameWindow.Resize event: {0}.", e.ToString());
if (this.Resize != null)
this.Resize(this, e);
}

View file

@ -16,7 +16,7 @@ namespace OpenTK
if (Environment.OSVersion.Version.Major > 5 ||
(Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1))
{
inputDriver = new OpenTK.Platform.Windows.WinRawInput(parent.Handle);
inputDriver = new OpenTK.Platform.Windows.WinRawInput(parent as OpenTK.Platform.Windows.WindowInfo);
}
else if (Environment.OSVersion.Platform == PlatformID.Unix)
{

View file

@ -90,7 +90,7 @@ namespace OpenTK.OpenGL
#endregion private enum Platform
private static Platform platform = Platform.Unknown;
private static System.Collections.Generic.Dictionary<string, bool> AvailableExtensions;
private static System.Collections.Generic.Dictionary<string, bool> AvailableExtensions = new Dictionary<string, bool>();
#region internal static extern IntPtr glxGetProcAddressARB(string s);
// also linux, for our ARB-y friends
@ -295,8 +295,12 @@ Did you remember to copy OpenTK.OpenGL.dll.config to your binary's folder?
// Use cached results
if (useCache)
{
// Build cache if it is not available
if (AvailableExtensions == null)
// Build cache if it is not available. We assume that all drivers
// will support at least one extension to opengl 1.0 (for example
// opengl 1.1). This should hold true even for software contexts
// (microsoft's soft implementation is gl 1.1 compatible), at least
// for any system capable of running .Net/Mono.
if (AvailableExtensions.Count == 0)
{
ParseAvailableExtensions();
}
@ -305,8 +309,8 @@ Did you remember to copy OpenTK.OpenGL.dll.config to your binary's folder?
// strings "1.0" to "2.1" with "GL_VERSION_1_0" to "GL_VERSION_2_1"
if (AvailableExtensions.ContainsKey(name))
return AvailableExtensions[name];
else
return false;
return false;
}
// Do not use cached results
@ -340,8 +344,6 @@ Did you remember to copy OpenTK.OpenGL.dll.config to your binary's folder?
{
// Assumes there is a current context.
AvailableExtensions = new Dictionary<string, bool>();
string version_string = GL.GetString(OpenTK.OpenGL.GL.Enums.StringName.VERSION);
if (String.IsNullOrEmpty(version_string))
return; // this shoudn't happen
@ -350,42 +352,42 @@ Did you remember to copy OpenTK.OpenGL.dll.config to your binary's folder?
if (version.StartsWith("1.2"))
{
AvailableExtensions.Add("GL_VERSION_1_2", true);
AvailableExtensions.Add("VERSION_1_2", true);
}
else if (version.StartsWith("1.3"))
{
AvailableExtensions.Add("GL_VERSION_1_2", true);
AvailableExtensions.Add("GL_VERSION_1_3", true);
AvailableExtensions.Add("VERSION_1_2", true);
AvailableExtensions.Add("VERSION_1_3", true);
}
else if (version.StartsWith("1.4"))
{
AvailableExtensions.Add("GL_VERSION_1_2", true);
AvailableExtensions.Add("GL_VERSION_1_3", true);
AvailableExtensions.Add("GL_VERSION_1_4", true);
AvailableExtensions.Add("VERSION_1_2", true);
AvailableExtensions.Add("VERSION_1_3", true);
AvailableExtensions.Add("VERSION_1_4", true);
}
else if (version.StartsWith("1.5"))
{
AvailableExtensions.Add("GL_VERSION_1_2", true);
AvailableExtensions.Add("GL_VERSION_1_3", true);
AvailableExtensions.Add("GL_VERSION_1_4", true);
AvailableExtensions.Add("GL_VERSION_1_5", true);
AvailableExtensions.Add("VERSION_1_2", true);
AvailableExtensions.Add("VERSION_1_3", true);
AvailableExtensions.Add("VERSION_1_4", true);
AvailableExtensions.Add("VERSION_1_5", true);
}
else if (version.StartsWith("2.0"))
{
AvailableExtensions.Add("GL_VERSION_1_2", true);
AvailableExtensions.Add("GL_VERSION_1_3", true);
AvailableExtensions.Add("GL_VERSION_1_4", true);
AvailableExtensions.Add("GL_VERSION_1_5", true);
AvailableExtensions.Add("GL_VERSION_2_0", true);
AvailableExtensions.Add("VERSION_1_2", true);
AvailableExtensions.Add("VERSION_1_3", true);
AvailableExtensions.Add("VERSION_1_4", true);
AvailableExtensions.Add("VERSION_1_5", true);
AvailableExtensions.Add("VERSION_2_0", true);
}
else if (version.StartsWith("2.1"))
{
AvailableExtensions.Add("GL_VERSION_1_2", true);
AvailableExtensions.Add("GL_VERSION_1_3", true);
AvailableExtensions.Add("GL_VERSION_1_4", true);
AvailableExtensions.Add("GL_VERSION_1_5", true);
AvailableExtensions.Add("GL_VERSION_2_0", true);
AvailableExtensions.Add("GL_VERSION_2_1", true);
AvailableExtensions.Add("VERSION_1_2", true);
AvailableExtensions.Add("VERSION_1_3", true);
AvailableExtensions.Add("VERSION_1_4", true);
AvailableExtensions.Add("VERSION_1_5", true);
AvailableExtensions.Add("VERSION_2_0", true);
AvailableExtensions.Add("VERSION_2_1", true);
}
string extension_string = GL.GetString(OpenTK.OpenGL.GL.Enums.StringName.EXTENSIONS);
@ -428,7 +430,8 @@ Did you remember to copy OpenTK.OpenGL.dll.config to your binary's folder?
f.SetValue(null, GetDelegateForMethod(f.Name, f.FieldType));
}
ParseAvailableExtensions();
//ParseAvailableExtensions();
AvailableExtensions.Clear();
}
#endregion

View file

@ -14,12 +14,9 @@ namespace OpenTK.Platform
{
public interface IGLControl : IDisposable
{
event CreateEvent Create;
bool IsIdle { get; }
bool Fullscreen { get; set; }
IGLContext Context { get; }
}
public delegate void CreateEvent(object sender, EventArgs e);
}

View file

@ -9,16 +9,19 @@ namespace OpenTK.Platform
{
void Run();
void OnRenderFrame();
void OnUpdateFrame();
void OnRenderFrame(EventArgs e);
void OnUpdateFrame(EventArgs e);
void OnLoad(EventArgs e);
event UpdateFrameEvent UpdateFrame;
event RenderFrameEvent RenderFrame;
event LoadEvent Load;
bool IsExiting { get; }
IList<OpenTK.Input.Keyboard> Keyboard { get; }
}
public delegate void UpdateFrameEvent(EventArgs e);
public delegate void RenderFrameEvent(EventArgs e);
public delegate void UpdateFrameEvent(object sender, EventArgs e);
public delegate void RenderFrameEvent(object sender, EventArgs e);
public delegate void LoadEvent(object sender, EventArgs e);
}

View file

@ -10,11 +10,21 @@ namespace OpenTK.Platform
interface INativeGLWindow : IGLControl, IResizable
{
void CreateWindow(DisplayMode mode);
void DestroyWindow();
void ProcessEvents();
void Exit();
void OnCreate(EventArgs e);
void OnDestroy(EventArgs e);
bool Exists { get; }
bool Quit { get; }
IWindowInfo WindowInfo { get; }
event CreateEvent Create;
event DestroyEvent Destroy;
}
public delegate void CreateEvent(object sender, EventArgs e);
public delegate void DestroyEvent(object sender, EventArgs e);
}

View file

@ -27,5 +27,10 @@ namespace OpenTK.Platform
this.Width = width;
this.Height = height;
}
public override string ToString()
{
return String.Format("New size: {0}x{1}", Width, Height);
}
}
}

View file

@ -47,8 +47,6 @@ namespace OpenTK.Platform.Windows
#region --- IGLControl membmers ---
public event CreateEvent Create;
#region public bool IsIdle
public bool IsIdle

View file

@ -21,7 +21,7 @@ namespace OpenTK.Platform.Windows
/// Drives GameWindow on Windows.
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
/// </summary>
sealed class WinGLNative : NativeWindow, OpenTK.Platform.INativeGLWindow, IDisposable
sealed class WinGLNative : NativeWindow, INativeGLWindow, IDisposable
{
#region --- Fields ---
@ -32,7 +32,12 @@ namespace OpenTK.Platform.Windows
private bool disposed;
private bool quit;
private bool exists;
private WindowInfo info;
private WindowInfo window;
/// <summary>
/// For use in WndProc only.
/// </summary>
private int width, height;
#endregion
@ -51,11 +56,6 @@ namespace OpenTK.Platform.Windows
#region protected override void WndProc(ref Message m)
/// <summary>
/// For use in WndProc only.
/// </summary>
private int width, height;
/// <summary>
/// Processes incoming WM_* messages.
/// </summary>
@ -86,12 +86,6 @@ namespace OpenTK.Platform.Windows
mode.Width = Marshal.ReadInt32(m.LParam, (int)Marshal.OffsetOf(typeof(API.CreateStruct), "cx"));
mode.Height = Marshal.ReadInt32(m.LParam, (int)Marshal.OffsetOf(typeof(API.CreateStruct), "cy"));
info = new WindowInfo();
info.Handle = this.Handle;
info.Parent = null;
Debug.Print("Window handle: {0}", this.Handle);
// Raise the Create event
this.OnCreate(EventArgs.Empty);
return;
@ -101,14 +95,8 @@ namespace OpenTK.Platform.Windows
return;
case API.Constants.WM_DESTROY:
if (this.Handle != IntPtr.Zero)
{
Debug.Print("Window handle {0} destroyed.", this.Handle);
this.DestroyHandle();
exists = false;
}
API.PostQuitMessage(0);
return;
this.OnDestroy(EventArgs.Empty);
break;
case API.Constants.WM_QUIT:
quit = true;
@ -116,7 +104,6 @@ namespace OpenTK.Platform.Windows
return;
}
//base.WndProc(ref m);
DefWndProc(ref m);
}
@ -124,106 +111,6 @@ namespace OpenTK.Platform.Windows
#region --- INativeGLWindow Members ---
#region private void CreateWindow(DisplayMode mode)
public void CreateWindow(DisplayMode mode)
{
Debug.Print("Creating native window with mode: {0}", mode.ToString());
Debug.Indent();
CreateParams cp = new CreateParams();
cp.ClassStyle =
(int)API.WindowClassStyle.OwnDC |
(int)API.WindowClassStyle.VRedraw |
(int)API.WindowClassStyle.HRedraw | (int)API.WindowClassStyle.Ime;
cp.Style =
(int)API.WindowStyle.Visible |
(int)API.WindowStyle.ClipChildren |
(int)API.WindowStyle.ClipSiblings |
(int)API.WindowStyle.OverlappedWindow;
cp.Width = mode.Width;
cp.Height = mode.Height;
cp.Caption = "OpenTK Game Window";
// Keep in mind that some construction code runs in WM_CREATE,
// which is raised CreateHandle()
CreateHandle(cp);
glContext = new WinGLContext(
this.Handle,
new DisplayMode(
width, height,
new ColorDepth(32),
16, 0, 0, 2,
fullscreen,
false,
false,
0.0f
)
);
if (this.Handle != IntPtr.Zero && glContext != null)
{
Debug.WriteLine("Window creation was succesful.");
exists = true;
}
else
{
throw new ApplicationException(String.Format(
"Could not create native window and/or context. Handle: {0}, Context {1}",
this.Handle, this.Context.ToString()));
}
Debug.Unindent();
}
/*
private void CreateWindow()
{
WinApi.WindowClass wc = new WinApi.WindowClass();
wc.style =
WinApi.WindowClassStyle.HRedraw |
WinApi.WindowClassStyle.VRedraw |
WinApi.WindowClassStyle.OwnDC;
wc.WindowProcedure = new WinApi.WindowProcedureEventHandler(WndProc);
wc.Instance = instance;
//wc.ClassName = Marshal.StringToHGlobalAuto(className);
wc.ClassName = className;
classAtom = WinApi.RegisterClass(wc);
if (classAtom == 0)
{
throw new Exception("Could not register class, error: " + Marshal.GetLastWin32Error());
}
// Change for fullscreen!
handle = WinApi.CreateWindowEx(
WinApi.ExtendedWindowStyle.ApplicationWindow |
WinApi.ExtendedWindowStyle.OverlappedWindow |
WinApi.ExtendedWindowStyle.Topmost,
className,
//Marshal.StringToHGlobalAuto("OpenTK Game Window"),
"OpenTK Game Window",
WinApi.WindowStyle.OverlappedWindow |
WinApi.WindowStyle.ClipChildren |
WinApi.WindowStyle.ClipSiblings,
0, 0,
640, 480,
IntPtr.Zero,
IntPtr.Zero,
instance,
IntPtr.Zero
);
if (handle == IntPtr.Zero)
{
throw new Exception("Could not create window, error: " + Marshal.GetLastWin32Error());
}
}
*/
#endregion
#region public void Exit()
/// <summary>
@ -231,7 +118,7 @@ namespace OpenTK.Platform.Windows
/// </summary>
public void Exit()
{
API.PostMessage(this.Handle, API.Constants.WM_DESTROY, IntPtr.Zero, IntPtr.Zero);
DestroyWindow();
}
#endregion
@ -252,21 +139,7 @@ namespace OpenTK.Platform.Windows
Marshal.GetLastWin32Error()));
}
API.DispatchMessage(ref msg);
WndProc(ref msg);
}
}
#endregion
#region public event CreateEvent Create;
public event CreateEvent Create;
private void OnCreate(EventArgs e)
{
if (this.Create != null)
{
this.Create(this, e);
//WndProc(ref msg);
}
}
@ -338,11 +211,120 @@ namespace OpenTK.Platform.Windows
public IWindowInfo WindowInfo
{
get { return info; }
get { return window; }
}
#endregion
#region private void CreateWindow(DisplayMode mode)
public void CreateWindow(DisplayMode mode)
{
Debug.Print("Creating native window with mode: {0}", mode.ToString());
Debug.Indent();
CreateParams cp = new CreateParams();
cp.ClassStyle =
(int)API.WindowClassStyle.OwnDC |
(int)API.WindowClassStyle.VRedraw |
(int)API.WindowClassStyle.HRedraw | (int)API.WindowClassStyle.Ime;
cp.Style =
(int)API.WindowStyle.Visible |
(int)API.WindowStyle.ClipChildren |
(int)API.WindowStyle.ClipSiblings |
(int)API.WindowStyle.OverlappedWindow;
cp.Width = mode.Width;
cp.Height = mode.Height;
cp.Caption = "OpenTK Game Window";
// Keep in mind that some construction code runs in WM_CREATE,
// which is raised CreateHandle()
CreateHandle(cp);
if (this.Handle != IntPtr.Zero && glContext != null)
{
Debug.WriteLine("Window creation was succesful.");
exists = true;
}
else
{
throw new ApplicationException(String.Format(
"Could not create native window and/or context. Handle: {0}, Context {1}",
this.Handle, this.Context.ToString()));
}
Debug.Unindent();
}
#endregion
#region OnCreate
public event CreateEvent Create;
public void OnCreate(EventArgs e)
{
window = new WindowInfo();
window.Handle = this.Handle;
window.Parent = null;
Debug.Print("Window created: {0}", window);
glContext = new WinGLContext(
this.Handle,
new DisplayMode(
width, height,
new ColorDepth(32),
16, 0, 0, 2,
fullscreen,
false,
false,
0.0f
)
);
glContext.MakeCurrent();
if (this.Create != null)
{
this.Create(this, e);
}
}
#endregion
#region private void DestroyWindow()
public void DestroyWindow()
{
Debug.Print("Destroying window: {0}", window.ToString());
API.PostMessage(this.Handle, API.Constants.WM_DESTROY, IntPtr.Zero, IntPtr.Zero);
}
#endregion
#region OnDestroy
public void OnDestroy(EventArgs e)
{
if (this.Handle != IntPtr.Zero)
{
Debug.Print("Window handle {0} destroyed.", this.Handle);
//this.DestroyHandle(); // Destroyed automatically by DefWndProc
exists = false;
}
API.PostQuitMessage(0);
if (this.Destroy != null)
{
this.Destroy(this, e);
}
}
public event DestroyEvent Destroy;
#endregion
#endregion
#region --- IDisposable Members ---

View file

@ -29,18 +29,17 @@ namespace OpenTK.Platform.Windows
/// </summary>
private static int deviceCount;
private WinRawKeyboard keyboardDriver;
#region --- Constructors ---
internal WinRawInput(IntPtr parentHandle)
internal WinRawInput(WindowInfo parent)
{
Debug.WriteLine("Initalizing windows raw input driver.");
Debug.Indent();
AssignHandle(parentHandle);
Debug.Print("Input window attached to parent {0}", this.Handle);
AssignHandle(parent.Handle);
Debug.Print("Input window attached to parent {0}", parent);
keyboardDriver = new WinRawKeyboard(this.Handle);
Debug.Unindent();
@ -48,6 +47,8 @@ namespace OpenTK.Platform.Windows
#endregion
#region internal static int DeviceCount
internal static int DeviceCount
{
get
@ -57,6 +58,8 @@ namespace OpenTK.Platform.Windows
}
}
#endregion
#region protected override void WndProc(ref Message msg)
int size = 0;

View file

@ -31,7 +31,7 @@ namespace OpenTK.Platform.Windows
public override string ToString()
{
return String.Format("Windows.WindowInfo: Handle {0}, Parent {1}",
return String.Format("Windows.WindowInfo: Handle {0}, Parent ({1})",
this.Handle, this.Parent != null ? this.Parent.ToString() : "null");
}

View file

@ -149,7 +149,7 @@ namespace OpenTK.Platform.X11
Debug.WriteLine("Mapped window.");
//glContext.MakeCurrent();
glContext.MakeCurrent();
Debug.WriteLine("Our shiny new context is now current - ready to rock 'n' roll!");
Debug.Unindent();
@ -165,10 +165,8 @@ namespace OpenTK.Platform.X11
{
Debug.WriteLine("X11GLNative shutdown sequence initiated.");
quit = true;
Functions.XUnmapWindow(window.Display, window.Handle);
Functions.XDestroyWindow(window.Display, window.Handle);
window = null;
glContext.Dispose();
glContext = null;
}
#endregion
@ -203,10 +201,8 @@ namespace OpenTK.Platform.X11
break;
case XEventName.DestroyNotify:
//glContext.Dispose();
//window = null;
//glContext = null;
//quit = true;
glContext.Dispose();
quit = true;
Debug.WriteLine("Window destroyed, shutting down.");
break;
@ -239,21 +235,6 @@ namespace OpenTK.Platform.X11
#endregion
#region public event CreateEvent Create;
public event CreateEvent Create;
private void OnCreate(EventArgs e)
{
if (this.Create != null)
{
Debug.Print("Create event fired from window: {0}", window.ToString());
this.Create(this, e);
}
}
#endregion
#region public bool Exists
/// <summary>
@ -333,6 +314,33 @@ namespace OpenTK.Platform.X11
#endregion
public void DestroyWindow()
{
throw new Exception("The method or operation is not implemented.");
}
#region OnCreate
public event CreateEvent Create;
public void OnCreate(EventArgs e)
{
if (this.Create != null)
{
Debug.Print("Create event fired from window: {0}", window.ToString());
this.Create(this, e);
}
}
#endregion
public void OnDestroy(EventArgs e)
{
throw new Exception("The method or operation is not implemented.");
}
public event DestroyEvent Destroy;
#endregion
#region --- IResizable Members ---
@ -446,5 +454,7 @@ namespace OpenTK.Platform.X11
}
#endregion
}
}