mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 11:55:31 +00:00
Improved GLControl event handling on initialization sequence (Resize event is now raised after loading the GL class).
Improved WinForms.Cube example to hook the GLControl events instead of the parent Form's ones. Improved Debug output in X11GLContext and X11GLControl
This commit is contained in:
parent
3b5d61a337
commit
7d5087f1f8
|
@ -33,8 +33,6 @@ namespace Examples.WinForms
|
|||
public Cube()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Application.Idle += Application_Idle;
|
||||
|
||||
this.ShowDialog();
|
||||
}
|
||||
|
@ -94,6 +92,12 @@ namespace Examples.WinForms
|
|||
{
|
||||
base.OnLoad(e);
|
||||
|
||||
glControl.KeyDown += new KeyEventHandler(glControl_KeyDown);
|
||||
glControl.Resize += new EventHandler(glControl_Resize);
|
||||
glControl.Paint += new PaintEventHandler(glControl_Paint);
|
||||
|
||||
glControl.CreateContext();
|
||||
|
||||
Text =
|
||||
GL.GetString(GL.Enums.StringName.VENDOR) + " " +
|
||||
GL.GetString(GL.Enums.StringName.RENDERER) + " " +
|
||||
|
@ -102,30 +106,24 @@ namespace Examples.WinForms
|
|||
GL.ClearColor(0.1f, 0.1f, 0.5f, 0.0f);
|
||||
GL.Enable(GL.Enums.EnableCap.DEPTH_TEST);
|
||||
|
||||
glControl.KeyDown += new KeyEventHandler(Cube_KeyDown);
|
||||
|
||||
OnResize(e);
|
||||
Application.Idle += Application_Idle;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Resize event handler
|
||||
#region GLControl.Resize event handler
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
void glControl_Resize(object sender, EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
OpenTK.GLControl c = sender as OpenTK.GLControl;
|
||||
|
||||
if (ClientSize.Height == 0)
|
||||
ClientSize = new System.Drawing.Size(ClientSize.Width, 1);
|
||||
if (c.ClientSize.Height == 0)
|
||||
c.ClientSize = new System.Drawing.Size(c.ClientSize.Width, 1);
|
||||
|
||||
GL.Viewport(0, 0, ClientSize.Width, ClientSize.Height);
|
||||
GL.Viewport(0, 0, c.ClientSize.Width, c.ClientSize.Height);
|
||||
|
||||
double ratio = 0.0;
|
||||
ratio = ClientSize.Width / (double)ClientSize.Height;
|
||||
//if (ClientSize.Width > ClientSize.Height)
|
||||
// ratio = ClientSize.Width / (double)ClientSize.Height;
|
||||
//else
|
||||
// ratio = ClientSize.Height / (double)ClientSize.Width;
|
||||
ratio = c.ClientSize.Width / (double)c.ClientSize.Height;
|
||||
|
||||
GL.MatrixMode(GL.Enums.MatrixMode.PROJECTION);
|
||||
GL.LoadIdentity();
|
||||
|
@ -134,20 +132,9 @@ namespace Examples.WinForms
|
|||
|
||||
#endregion
|
||||
|
||||
#region Paint event handler
|
||||
#region GLControl.KeyDown event handler
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
|
||||
Render();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region KeyDown event handler
|
||||
|
||||
void Cube_KeyDown(object sender, KeyEventArgs e)
|
||||
void glControl_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Alt && e.Shift)
|
||||
{
|
||||
|
@ -163,6 +150,15 @@ namespace Examples.WinForms
|
|||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GLControl.Paint event handler
|
||||
|
||||
void glControl_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
Render();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region private void DrawCube()
|
||||
|
|
|
@ -39,34 +39,35 @@ namespace Examples.WinForms
|
|||
|
||||
private void redButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
//GL.ClearColor(0.7f, 0.0f, 0.0f, 0.0f);
|
||||
//glControl1.Invalidate();
|
||||
GL.ClearColor(0.7f, 0.0f, 0.0f, 0.0f);
|
||||
glControl1.Invalidate();
|
||||
}
|
||||
|
||||
private void greenButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
//GL.ClearColor(0.0f, 0.5f, 0.0f, 0.0f);
|
||||
//glControl1.Invalidate();
|
||||
GL.ClearColor(0.0f, 0.5f, 0.0f, 0.0f);
|
||||
glControl1.Invalidate();
|
||||
}
|
||||
|
||||
private void blueButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
//GL.ClearColor(0.0f, 0.0f, 0.7f, 0.0f);
|
||||
//glControl1.Invalidate();
|
||||
GL.ClearColor(0.0f, 0.0f, 0.7f, 0.0f);
|
||||
glControl1.Invalidate();
|
||||
}
|
||||
|
||||
private void glControl1_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
//GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT);
|
||||
//glControl1.SwapBuffers();
|
||||
System.Diagnostics.Debug.Print("Paint");
|
||||
GL.Clear(GL.Enums.ClearBufferMask.COLOR_BUFFER_BIT);
|
||||
glControl1.SwapBuffers();
|
||||
}
|
||||
|
||||
private void glControl1_Resize(object sender, OpenTK.Platform.ResizeEventArgs e)
|
||||
{
|
||||
//if (glControl1.ClientSize.Height == 0)
|
||||
// glControl1.ClientSize = new System.Drawing.Size(glControl1.ClientSize.Width, 1);
|
||||
if (glControl1.ClientSize.Height == 0)
|
||||
glControl1.ClientSize = new System.Drawing.Size(glControl1.ClientSize.Width, 1);
|
||||
|
||||
//GL.Viewport(0, 0, glControl1.ClientSize.Width, glControl1.ClientSize.Height);
|
||||
GL.Viewport(0, 0, glControl1.ClientSize.Width, glControl1.ClientSize.Height);
|
||||
}
|
||||
|
||||
private void glControl1_KeyDown(object sender, KeyEventArgs e)
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace OpenTK
|
|||
// TODO: Document the GLControl class.
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Defines a UserControl with opengl rendering capabilities.
|
||||
/// </summary>
|
||||
public partial class GLControl : UserControl, IGLControl
|
||||
{
|
||||
|
@ -43,6 +43,10 @@ namespace OpenTK
|
|||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new GLControl, with the specified DisplayMode.
|
||||
/// </summary>
|
||||
/// <param name="mode">The DisplayMode of the control.</param>
|
||||
public GLControl(DisplayMode mode)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
@ -88,9 +92,6 @@ namespace OpenTK
|
|||
/// </summary>
|
||||
public void CreateContext()
|
||||
{
|
||||
Debug.Print("Creating opengl context");
|
||||
Debug.Indent();
|
||||
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT ||
|
||||
Environment.OSVersion.Platform == PlatformID.Win32Windows)
|
||||
{
|
||||
|
@ -109,8 +110,7 @@ namespace OpenTK
|
|||
}
|
||||
|
||||
OpenTK.OpenGL.GL.LoadAll();
|
||||
|
||||
Debug.Unindent();
|
||||
this.OnResize(EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -142,10 +142,10 @@ visual = Glx.ChooseVisual(windowInfo.Display, windowInfo.Screen, attrib);
|
|||
Debug.WriteLine(direct ? "Context is direct." : "Context is indirect.");
|
||||
|
||||
context = Glx.CreateContext(windowInfo.Display, visual, shareHandle, direct);
|
||||
Debug.Unindent();
|
||||
if (context != IntPtr.Zero)
|
||||
{
|
||||
Debug.WriteLine(String.Format("New opengl context created. (id: {0})", context));
|
||||
Debug.Unindent();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -97,6 +97,8 @@ namespace OpenTK.Platform.X11
|
|||
*/
|
||||
//glContext.MakeCurrent();
|
||||
//OpenTK.OpenGL.GL.LoadAll();
|
||||
|
||||
Debug.Unindent();
|
||||
}
|
||||
|
||||
void c_HandleCreated(object sender, EventArgs e)
|
||||
|
@ -104,11 +106,12 @@ namespace OpenTK.Platform.X11
|
|||
UserControl c = (sender as UserControl);
|
||||
Debug.Print("GLControl handle created, creating X11GLContext.");
|
||||
Debug.Indent();
|
||||
glContext.windowInfo.Handle = info.Handle = (sender as UserControl).Handle;
|
||||
|
||||
try
|
||||
{
|
||||
glContext.windowInfo.Handle = info.Handle = (sender as UserControl).Handle;
|
||||
glContext.CreateContext(null, true);
|
||||
glContext.MakeCurrent();
|
||||
}
|
||||
catch (ApplicationException expt)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue