Added Create and Destroy events to NativeGLWindow.
This commit is contained in:
parent
f30e7f6df8
commit
863a8e9557
17 changed files with 504 additions and 366 deletions
|
@ -60,9 +60,9 @@ namespace Examples.Tests
|
||||||
GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
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);
|
GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT);
|
||||||
Context.SwapBuffers();
|
Context.SwapBuffers();
|
||||||
|
@ -73,8 +73,8 @@ namespace Examples.Tests
|
||||||
while (!Quit)
|
while (!Quit)
|
||||||
{
|
{
|
||||||
ProcessEvents();
|
ProcessEvents();
|
||||||
OnUpdateFrame();
|
OnUpdateFrame(EventArgs.Empty);
|
||||||
OnRenderFrame();
|
OnRenderFrame(EventArgs.Empty);
|
||||||
Thread.Sleep(10);
|
Thread.Sleep(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,18 +35,23 @@ namespace Examples.Tutorial
|
||||||
public T03_RotatingCube()
|
public T03_RotatingCube()
|
||||||
{
|
{
|
||||||
CreateWindow(new DisplayMode(800, 600));
|
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
|
#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>
|
/// <summary>
|
||||||
/// Called when the user resizes the window.
|
/// Called when the user resizes the window.
|
||||||
|
@ -70,7 +75,7 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region OnUpdateFrame function
|
#region OnUpdateFrame
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prepares the next frame for rendering.
|
/// 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,
|
/// Place your control logic here. This is the place to respond to user input,
|
||||||
/// update object positions etc.
|
/// update object positions etc.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public override void OnUpdateFrame()
|
public override void OnUpdateFrame(EventArgs e)
|
||||||
{
|
{
|
||||||
if (Keyboard[0][OpenTK.Input.Key.Escape])
|
if (Keyboard[0][OpenTK.Input.Key.Escape])
|
||||||
{
|
{
|
||||||
|
@ -107,12 +112,12 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region OnRenderFrame function
|
#region OnRenderFrame
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Place your rendering code here.
|
/// Place your rendering code here.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void OnRenderFrame()
|
public override void OnRenderFrame(EventArgs e)
|
||||||
{
|
{
|
||||||
GL.Clear(Enums.ClearBufferMask.COLOR_BUFFER_BIT | Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
|
GL.Clear(Enums.ClearBufferMask.COLOR_BUFFER_BIT | Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
|
|
@ -120,11 +120,25 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region OnUpdateFrame
|
||||||
|
|
||||||
|
public override void OnUpdateFrame(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnUpdateFrame(e);
|
||||||
|
|
||||||
|
if (Keyboard[0][OpenTK.Input.Key.Escape])
|
||||||
|
{
|
||||||
|
this.Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region OnRenderFrame
|
#region OnRenderFrame
|
||||||
|
|
||||||
public override void OnRenderFrame()
|
public override void OnRenderFrame(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnRenderFrame();
|
base.OnRenderFrame(e);
|
||||||
|
|
||||||
GL.MatrixMode(Enums.MatrixMode.MODELVIEW);
|
GL.MatrixMode(Enums.MatrixMode.MODELVIEW);
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
|
@ -148,20 +162,6 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region OnUpdateFrame
|
|
||||||
|
|
||||||
public override void OnUpdateFrame()
|
|
||||||
{
|
|
||||||
base.OnUpdateFrame();
|
|
||||||
|
|
||||||
if (Keyboard[0][OpenTK.Input.Key.Escape])
|
|
||||||
{
|
|
||||||
this.Exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion --- Event Handlers ---
|
#endregion --- Event Handlers ---
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -73,8 +73,22 @@ namespace Examples.Tutorial
|
||||||
public T08_VBO()
|
public T08_VBO()
|
||||||
{
|
{
|
||||||
this.CreateWindow(new DisplayMode(800, 600));
|
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.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
|
||||||
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
|
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
|
||||||
|
@ -88,11 +102,59 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
#endregion
|
#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
|
#region OnRenderFrame
|
||||||
|
|
||||||
public override void OnRenderFrame()
|
public override void OnRenderFrame(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnRenderFrame();
|
base.OnRenderFrame(e);
|
||||||
|
|
||||||
GL.Clear(
|
GL.Clear(
|
||||||
GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT |
|
GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT |
|
||||||
|
@ -119,54 +181,6 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
#endregion
|
#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
|
#region LoadCube
|
||||||
|
|
||||||
private void LoadCube()
|
private void LoadCube()
|
||||||
|
|
|
@ -51,12 +51,62 @@ namespace Examples.Tutorial
|
||||||
public T10_GLSL_Cube()
|
public T10_GLSL_Cube()
|
||||||
{
|
{
|
||||||
this.CreateWindow(new OpenTK.Platform.DisplayMode(800, 600));
|
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 =
|
//Text =
|
||||||
// GL.GetString(Enums.StringName.VENDOR) + " " +
|
// GL.GetString(Enums.StringName.VENDOR) + " " +
|
||||||
// GL.GetString(Enums.StringName.RENDERER) + " " +
|
// GL.GetString(Enums.StringName.RENDERER) + " " +
|
||||||
// GL.GetString(Enums.StringName.VERSION);
|
// 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.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
|
||||||
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
|
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
|
||||||
|
@ -106,25 +156,6 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
#endregion
|
#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
|
#region OnResize
|
||||||
|
|
||||||
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
||||||
|
@ -145,9 +176,13 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
#region OnUpdateFrame
|
#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])
|
if (Keyboard[0][OpenTK.Input.Key.Escape])
|
||||||
{
|
{
|
||||||
|
@ -169,9 +204,9 @@ namespace Examples.Tutorial
|
||||||
|
|
||||||
#region OnRenderFrame
|
#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);
|
GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT | GL.Enums.ClearBufferMask.DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,12 @@ namespace OpenTK
|
||||||
|
|
||||||
glWindow.Resize += new ResizeEvent(glWindow_Resize);
|
glWindow.Resize += new ResizeEvent(glWindow_Resize);
|
||||||
glWindow.Create += new CreateEvent(glWindow_CreateInputDriver);
|
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)
|
void glWindow_CreateInputDriver(object sender, EventArgs e)
|
||||||
|
@ -98,27 +104,6 @@ namespace OpenTK
|
||||||
|
|
||||||
#region --- INativeGLWindow Members ---
|
#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()
|
#region public void Exit()
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -219,6 +204,71 @@ namespace OpenTK
|
||||||
|
|
||||||
#endregion
|
#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
|
#endregion
|
||||||
|
|
||||||
#region --- IGameWindow Members ---
|
#region --- IGameWindow Members ---
|
||||||
|
@ -242,17 +292,30 @@ namespace OpenTK
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual void Run()
|
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)
|
while (!this.Quit && !IsExiting)
|
||||||
{
|
{
|
||||||
this.ProcessEvents();
|
this.ProcessEvents();
|
||||||
this.OnUpdateFrame();
|
if (!IsExiting)
|
||||||
this.OnRenderFrame();
|
{
|
||||||
|
this.OnUpdateFrame(EventArgs.Empty);
|
||||||
|
this.OnRenderFrame(EventArgs.Empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glWindow.Exit();
|
if (glWindow.Exists)
|
||||||
while (glWindow.Exists)
|
|
||||||
{
|
{
|
||||||
this.ProcessEvents();
|
glWindow.Exit();
|
||||||
|
while (glWindow.Exists)
|
||||||
|
{
|
||||||
|
this.ProcessEvents();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,21 +343,7 @@ namespace OpenTK
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region public event CreateEvent Create;
|
#region public virtual void OnRenderFrame(EventArgs e)
|
||||||
|
|
||||||
public event CreateEvent Create;
|
|
||||||
|
|
||||||
private void OnCreate(EventArgs e)
|
|
||||||
{
|
|
||||||
if (this.Create != null)
|
|
||||||
{
|
|
||||||
this.Create(this, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public virtual void OnRenderFrame()
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raises the RenderFrame event. Override in derived classes to render a frame.
|
/// 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
|
/// If overriden, the base.OnRenderFrame() function should be called, to ensure
|
||||||
/// listeners are notified of RenderFrame events.
|
/// listeners are notified of RenderFrame events.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual void OnRenderFrame()
|
public virtual void OnRenderFrame(EventArgs e)
|
||||||
{
|
{
|
||||||
if (!this.Exists)
|
if (!this.Exists)
|
||||||
{
|
{
|
||||||
|
@ -312,12 +361,17 @@ namespace OpenTK
|
||||||
this.CreateWindow(mode);
|
this.CreateWindow(mode);
|
||||||
}
|
}
|
||||||
if (RenderFrame != null)
|
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
|
#endregion
|
||||||
|
|
||||||
#region public virtual void OnUpdateFrame()
|
#region public virtual void OnUpdateFrame(EventArgs e)
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raises the UpdateFrame event. Override in derived classes to update a frame.
|
/// 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
|
/// If overriden, the base.OnUpdateFrame() function should be called, to ensure
|
||||||
/// listeners are notified of UpdateFrame events.
|
/// listeners are notified of UpdateFrame events.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual void OnUpdateFrame()
|
public virtual void OnUpdateFrame(EventArgs e)
|
||||||
{
|
{
|
||||||
if (!this.Exists)
|
if (!this.Exists)
|
||||||
{
|
{
|
||||||
|
@ -335,20 +389,38 @@ namespace OpenTK
|
||||||
this.CreateWindow(mode);
|
this.CreateWindow(mode);
|
||||||
}
|
}
|
||||||
if (UpdateFrame != null)
|
if (UpdateFrame != null)
|
||||||
UpdateFrame(EventArgs.Empty);
|
UpdateFrame(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when it is time to update the next frame.
|
/// Occurs when it is time to update the next frame.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event UpdateFrameEvent UpdateFrame;
|
public event UpdateFrameEvent UpdateFrame;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region public virtual void OnLoad(EventArgs e)
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </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
|
#region public bool IsExiting
|
||||||
|
|
||||||
|
@ -446,6 +518,7 @@ namespace OpenTK
|
||||||
/// <param name="e">Contains the new Width and Height of the window.</param>
|
/// <param name="e">Contains the new Width and Height of the window.</param>
|
||||||
protected virtual void OnResize(ResizeEventArgs e)
|
protected virtual void OnResize(ResizeEventArgs e)
|
||||||
{
|
{
|
||||||
|
Debug.Print("Firing GameWindow.Resize event: {0}.", e.ToString());
|
||||||
if (this.Resize != null)
|
if (this.Resize != null)
|
||||||
this.Resize(this, e);
|
this.Resize(this, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace OpenTK
|
||||||
if (Environment.OSVersion.Version.Major > 5 ||
|
if (Environment.OSVersion.Version.Major > 5 ||
|
||||||
(Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1))
|
(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)
|
else if (Environment.OSVersion.Platform == PlatformID.Unix)
|
||||||
{
|
{
|
||||||
|
|
|
@ -90,7 +90,7 @@ namespace OpenTK.OpenGL
|
||||||
#endregion private enum Platform
|
#endregion private enum Platform
|
||||||
|
|
||||||
private static Platform platform = Platform.Unknown;
|
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);
|
#region internal static extern IntPtr glxGetProcAddressARB(string s);
|
||||||
// also linux, for our ARB-y friends
|
// 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
|
// Use cached results
|
||||||
if (useCache)
|
if (useCache)
|
||||||
{
|
{
|
||||||
// Build cache if it is not available
|
// Build cache if it is not available. We assume that all drivers
|
||||||
if (AvailableExtensions == null)
|
// 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();
|
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"
|
// strings "1.0" to "2.1" with "GL_VERSION_1_0" to "GL_VERSION_2_1"
|
||||||
if (AvailableExtensions.ContainsKey(name))
|
if (AvailableExtensions.ContainsKey(name))
|
||||||
return AvailableExtensions[name];
|
return AvailableExtensions[name];
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not use cached results
|
// 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.
|
// Assumes there is a current context.
|
||||||
|
|
||||||
AvailableExtensions = new Dictionary<string, bool>();
|
|
||||||
|
|
||||||
string version_string = GL.GetString(OpenTK.OpenGL.GL.Enums.StringName.VERSION);
|
string version_string = GL.GetString(OpenTK.OpenGL.GL.Enums.StringName.VERSION);
|
||||||
if (String.IsNullOrEmpty(version_string))
|
if (String.IsNullOrEmpty(version_string))
|
||||||
return; // this shoudn't happen
|
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"))
|
if (version.StartsWith("1.2"))
|
||||||
{
|
{
|
||||||
AvailableExtensions.Add("GL_VERSION_1_2", true);
|
AvailableExtensions.Add("VERSION_1_2", true);
|
||||||
}
|
}
|
||||||
else if (version.StartsWith("1.3"))
|
else if (version.StartsWith("1.3"))
|
||||||
{
|
{
|
||||||
AvailableExtensions.Add("GL_VERSION_1_2", true);
|
AvailableExtensions.Add("VERSION_1_2", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_1_3", true);
|
AvailableExtensions.Add("VERSION_1_3", true);
|
||||||
}
|
}
|
||||||
else if (version.StartsWith("1.4"))
|
else if (version.StartsWith("1.4"))
|
||||||
{
|
{
|
||||||
AvailableExtensions.Add("GL_VERSION_1_2", true);
|
AvailableExtensions.Add("VERSION_1_2", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_1_3", true);
|
AvailableExtensions.Add("VERSION_1_3", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_1_4", true);
|
AvailableExtensions.Add("VERSION_1_4", true);
|
||||||
}
|
}
|
||||||
else if (version.StartsWith("1.5"))
|
else if (version.StartsWith("1.5"))
|
||||||
{
|
{
|
||||||
AvailableExtensions.Add("GL_VERSION_1_2", true);
|
AvailableExtensions.Add("VERSION_1_2", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_1_3", true);
|
AvailableExtensions.Add("VERSION_1_3", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_1_4", true);
|
AvailableExtensions.Add("VERSION_1_4", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_1_5", true);
|
AvailableExtensions.Add("VERSION_1_5", true);
|
||||||
}
|
}
|
||||||
else if (version.StartsWith("2.0"))
|
else if (version.StartsWith("2.0"))
|
||||||
{
|
{
|
||||||
AvailableExtensions.Add("GL_VERSION_1_2", true);
|
AvailableExtensions.Add("VERSION_1_2", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_1_3", true);
|
AvailableExtensions.Add("VERSION_1_3", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_1_4", true);
|
AvailableExtensions.Add("VERSION_1_4", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_1_5", true);
|
AvailableExtensions.Add("VERSION_1_5", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_2_0", true);
|
AvailableExtensions.Add("VERSION_2_0", true);
|
||||||
}
|
}
|
||||||
else if (version.StartsWith("2.1"))
|
else if (version.StartsWith("2.1"))
|
||||||
{
|
{
|
||||||
AvailableExtensions.Add("GL_VERSION_1_2", true);
|
AvailableExtensions.Add("VERSION_1_2", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_1_3", true);
|
AvailableExtensions.Add("VERSION_1_3", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_1_4", true);
|
AvailableExtensions.Add("VERSION_1_4", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_1_5", true);
|
AvailableExtensions.Add("VERSION_1_5", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_2_0", true);
|
AvailableExtensions.Add("VERSION_2_0", true);
|
||||||
AvailableExtensions.Add("GL_VERSION_2_1", true);
|
AvailableExtensions.Add("VERSION_2_1", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
string extension_string = GL.GetString(OpenTK.OpenGL.GL.Enums.StringName.EXTENSIONS);
|
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));
|
f.SetValue(null, GetDelegateForMethod(f.Name, f.FieldType));
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseAvailableExtensions();
|
//ParseAvailableExtensions();
|
||||||
|
AvailableExtensions.Clear();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,9 @@ namespace OpenTK.Platform
|
||||||
{
|
{
|
||||||
public interface IGLControl : IDisposable
|
public interface IGLControl : IDisposable
|
||||||
{
|
{
|
||||||
event CreateEvent Create;
|
|
||||||
|
|
||||||
bool IsIdle { get; }
|
bool IsIdle { get; }
|
||||||
bool Fullscreen { get; set; }
|
bool Fullscreen { get; set; }
|
||||||
IGLContext Context { get; }
|
IGLContext Context { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void CreateEvent(object sender, EventArgs e);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,16 +9,19 @@ namespace OpenTK.Platform
|
||||||
{
|
{
|
||||||
void Run();
|
void Run();
|
||||||
|
|
||||||
void OnRenderFrame();
|
void OnRenderFrame(EventArgs e);
|
||||||
void OnUpdateFrame();
|
void OnUpdateFrame(EventArgs e);
|
||||||
|
void OnLoad(EventArgs e);
|
||||||
|
|
||||||
event UpdateFrameEvent UpdateFrame;
|
event UpdateFrameEvent UpdateFrame;
|
||||||
event RenderFrameEvent RenderFrame;
|
event RenderFrameEvent RenderFrame;
|
||||||
|
event LoadEvent Load;
|
||||||
|
|
||||||
bool IsExiting { get; }
|
bool IsExiting { get; }
|
||||||
IList<OpenTK.Input.Keyboard> Keyboard { get; }
|
IList<OpenTK.Input.Keyboard> Keyboard { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void UpdateFrameEvent(EventArgs e);
|
public delegate void UpdateFrameEvent(object sender, EventArgs e);
|
||||||
public delegate void RenderFrameEvent(EventArgs e);
|
public delegate void RenderFrameEvent(object sender, EventArgs e);
|
||||||
|
public delegate void LoadEvent(object sender, EventArgs e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,21 @@ namespace OpenTK.Platform
|
||||||
interface INativeGLWindow : IGLControl, IResizable
|
interface INativeGLWindow : IGLControl, IResizable
|
||||||
{
|
{
|
||||||
void CreateWindow(DisplayMode mode);
|
void CreateWindow(DisplayMode mode);
|
||||||
|
void DestroyWindow();
|
||||||
void ProcessEvents();
|
void ProcessEvents();
|
||||||
void Exit();
|
void Exit();
|
||||||
|
|
||||||
|
void OnCreate(EventArgs e);
|
||||||
|
void OnDestroy(EventArgs e);
|
||||||
|
|
||||||
bool Exists { get; }
|
bool Exists { get; }
|
||||||
bool Quit { get; }
|
bool Quit { get; }
|
||||||
IWindowInfo WindowInfo { 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,5 +27,10 @@ namespace OpenTK.Platform
|
||||||
this.Width = width;
|
this.Width = width;
|
||||||
this.Height = height;
|
this.Height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return String.Format("New size: {0}x{1}", Width, Height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,6 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
#region --- IGLControl membmers ---
|
#region --- IGLControl membmers ---
|
||||||
|
|
||||||
public event CreateEvent Create;
|
|
||||||
|
|
||||||
#region public bool IsIdle
|
#region public bool IsIdle
|
||||||
|
|
||||||
public bool IsIdle
|
public bool IsIdle
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace OpenTK.Platform.Windows
|
||||||
/// Drives GameWindow on Windows.
|
/// Drives GameWindow on Windows.
|
||||||
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
sealed class WinGLNative : NativeWindow, OpenTK.Platform.INativeGLWindow, IDisposable
|
sealed class WinGLNative : NativeWindow, INativeGLWindow, IDisposable
|
||||||
{
|
{
|
||||||
#region --- Fields ---
|
#region --- Fields ---
|
||||||
|
|
||||||
|
@ -32,7 +32,12 @@ namespace OpenTK.Platform.Windows
|
||||||
private bool disposed;
|
private bool disposed;
|
||||||
private bool quit;
|
private bool quit;
|
||||||
private bool exists;
|
private bool exists;
|
||||||
private WindowInfo info;
|
private WindowInfo window;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// For use in WndProc only.
|
||||||
|
/// </summary>
|
||||||
|
private int width, height;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -51,11 +56,6 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
#region protected override void WndProc(ref Message m)
|
#region protected override void WndProc(ref Message m)
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// For use in WndProc only.
|
|
||||||
/// </summary>
|
|
||||||
private int width, height;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Processes incoming WM_* messages.
|
/// Processes incoming WM_* messages.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -86,12 +86,6 @@ namespace OpenTK.Platform.Windows
|
||||||
mode.Width = Marshal.ReadInt32(m.LParam, (int)Marshal.OffsetOf(typeof(API.CreateStruct), "cx"));
|
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"));
|
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
|
// Raise the Create event
|
||||||
this.OnCreate(EventArgs.Empty);
|
this.OnCreate(EventArgs.Empty);
|
||||||
return;
|
return;
|
||||||
|
@ -101,14 +95,8 @@ namespace OpenTK.Platform.Windows
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case API.Constants.WM_DESTROY:
|
case API.Constants.WM_DESTROY:
|
||||||
if (this.Handle != IntPtr.Zero)
|
this.OnDestroy(EventArgs.Empty);
|
||||||
{
|
break;
|
||||||
Debug.Print("Window handle {0} destroyed.", this.Handle);
|
|
||||||
this.DestroyHandle();
|
|
||||||
exists = false;
|
|
||||||
}
|
|
||||||
API.PostQuitMessage(0);
|
|
||||||
return;
|
|
||||||
|
|
||||||
case API.Constants.WM_QUIT:
|
case API.Constants.WM_QUIT:
|
||||||
quit = true;
|
quit = true;
|
||||||
|
@ -116,7 +104,6 @@ namespace OpenTK.Platform.Windows
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//base.WndProc(ref m);
|
|
||||||
DefWndProc(ref m);
|
DefWndProc(ref m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,106 +111,6 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
#region --- INativeGLWindow Members ---
|
#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()
|
#region public void Exit()
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -231,7 +118,7 @@ namespace OpenTK.Platform.Windows
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Exit()
|
public void Exit()
|
||||||
{
|
{
|
||||||
API.PostMessage(this.Handle, API.Constants.WM_DESTROY, IntPtr.Zero, IntPtr.Zero);
|
DestroyWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -252,21 +139,7 @@ namespace OpenTK.Platform.Windows
|
||||||
Marshal.GetLastWin32Error()));
|
Marshal.GetLastWin32Error()));
|
||||||
}
|
}
|
||||||
API.DispatchMessage(ref msg);
|
API.DispatchMessage(ref msg);
|
||||||
WndProc(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,11 +211,120 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
public IWindowInfo WindowInfo
|
public IWindowInfo WindowInfo
|
||||||
{
|
{
|
||||||
get { return info; }
|
get { return window; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#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
|
#endregion
|
||||||
|
|
||||||
#region --- IDisposable Members ---
|
#region --- IDisposable Members ---
|
||||||
|
|
|
@ -29,18 +29,17 @@ namespace OpenTK.Platform.Windows
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static int deviceCount;
|
private static int deviceCount;
|
||||||
|
|
||||||
|
|
||||||
private WinRawKeyboard keyboardDriver;
|
private WinRawKeyboard keyboardDriver;
|
||||||
|
|
||||||
#region --- Constructors ---
|
#region --- Constructors ---
|
||||||
|
|
||||||
internal WinRawInput(IntPtr parentHandle)
|
internal WinRawInput(WindowInfo parent)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Initalizing windows raw input driver.");
|
Debug.WriteLine("Initalizing windows raw input driver.");
|
||||||
Debug.Indent();
|
Debug.Indent();
|
||||||
|
|
||||||
AssignHandle(parentHandle);
|
AssignHandle(parent.Handle);
|
||||||
Debug.Print("Input window attached to parent {0}", this.Handle);
|
Debug.Print("Input window attached to parent {0}", parent);
|
||||||
keyboardDriver = new WinRawKeyboard(this.Handle);
|
keyboardDriver = new WinRawKeyboard(this.Handle);
|
||||||
|
|
||||||
Debug.Unindent();
|
Debug.Unindent();
|
||||||
|
@ -48,6 +47,8 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region internal static int DeviceCount
|
||||||
|
|
||||||
internal static int DeviceCount
|
internal static int DeviceCount
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -57,6 +58,8 @@ namespace OpenTK.Platform.Windows
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region protected override void WndProc(ref Message msg)
|
#region protected override void WndProc(ref Message msg)
|
||||||
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
public override string ToString()
|
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");
|
this.Handle, this.Parent != null ? this.Parent.ToString() : "null");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -149,7 +149,7 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
Debug.WriteLine("Mapped window.");
|
Debug.WriteLine("Mapped window.");
|
||||||
|
|
||||||
//glContext.MakeCurrent();
|
glContext.MakeCurrent();
|
||||||
|
|
||||||
Debug.WriteLine("Our shiny new context is now current - ready to rock 'n' roll!");
|
Debug.WriteLine("Our shiny new context is now current - ready to rock 'n' roll!");
|
||||||
Debug.Unindent();
|
Debug.Unindent();
|
||||||
|
@ -165,10 +165,8 @@ namespace OpenTK.Platform.X11
|
||||||
{
|
{
|
||||||
Debug.WriteLine("X11GLNative shutdown sequence initiated.");
|
Debug.WriteLine("X11GLNative shutdown sequence initiated.");
|
||||||
quit = true;
|
quit = true;
|
||||||
|
Functions.XUnmapWindow(window.Display, window.Handle);
|
||||||
Functions.XDestroyWindow(window.Display, window.Handle);
|
Functions.XDestroyWindow(window.Display, window.Handle);
|
||||||
window = null;
|
|
||||||
glContext.Dispose();
|
|
||||||
glContext = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -203,10 +201,8 @@ namespace OpenTK.Platform.X11
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XEventName.DestroyNotify:
|
case XEventName.DestroyNotify:
|
||||||
//glContext.Dispose();
|
glContext.Dispose();
|
||||||
//window = null;
|
quit = true;
|
||||||
//glContext = null;
|
|
||||||
//quit = true;
|
|
||||||
Debug.WriteLine("Window destroyed, shutting down.");
|
Debug.WriteLine("Window destroyed, shutting down.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -239,21 +235,6 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
#endregion
|
#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
|
#region public bool Exists
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -333,6 +314,33 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
#endregion
|
#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
|
#endregion
|
||||||
|
|
||||||
#region --- IResizable Members ---
|
#region --- IResizable Members ---
|
||||||
|
@ -446,5 +454,7 @@ namespace OpenTK.Platform.X11
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue