2007-07-23 00:15:18 +00:00
|
|
|
|
#region --- License ---
|
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license info
|
|
|
|
|
*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Using Directives ---
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
using OpenTK.Platform;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace OpenTK
|
|
|
|
|
{
|
|
|
|
|
// TODO: Document the GLControl class.
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2007-08-20 14:12:57 +00:00
|
|
|
|
/// Defines a UserControl with opengl rendering capabilities.
|
2007-07-23 00:15:18 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class GLControl : UserControl, IGLControl
|
|
|
|
|
{
|
|
|
|
|
#region --- Private Fields ---
|
|
|
|
|
|
|
|
|
|
private IGLControl glControl;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Contructors ---
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs a new GLControl.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public GLControl()
|
|
|
|
|
:this(new DisplayMode())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 14:12:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs a new GLControl, with the specified DisplayMode.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="mode">The DisplayMode of the control.</param>
|
2007-07-23 00:15:18 +00:00
|
|
|
|
public GLControl(DisplayMode mode)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2007-08-20 10:46:37 +00:00
|
|
|
|
|
2007-08-20 12:25:48 +00:00
|
|
|
|
this.Visible = false;
|
2007-08-20 10:46:37 +00:00
|
|
|
|
this.Fullscreen = mode.Fullscreen;
|
|
|
|
|
|
|
|
|
|
this.SetStyle(ControlStyles.UserPaint, true);
|
|
|
|
|
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
|
|
|
//this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
|
|
|
|
|
|
|
|
|
//Debug.Print("Creating GLControl.");
|
|
|
|
|
//this.CreateControl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
/*
|
|
|
|
|
CreateParams @params;
|
|
|
|
|
protected override CreateParams CreateParams
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (@params == null)
|
|
|
|
|
{
|
|
|
|
|
@params = base.CreateParams;
|
|
|
|
|
//@params.ClassStyle = (int)
|
|
|
|
|
// (OpenTK.Platform.Windows.API.WindowClassStyle.OwnDC |
|
|
|
|
|
// OpenTK.Platform.Windows.API.WindowClassStyle.HRedraw |
|
|
|
|
|
// OpenTK.Platform.Windows.API.WindowClassStyle.VRedraw);
|
|
|
|
|
//@params.Style = (int)
|
|
|
|
|
// (OpenTK.Platform.Windows.API.WindowStyle.ClipChildren);
|
|
|
|
|
// OpenTK.Platform.Windows.API.WindowStyle.ClipSiblings);
|
|
|
|
|
//@params.ExStyle = OpenTK.Platform.Windows.API.ExtendedWindowStyle.
|
|
|
|
|
}
|
|
|
|
|
return @params;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
#region --- Public Methods ---
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Forces the creation of the opengl rendering context.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void CreateContext()
|
|
|
|
|
{
|
2007-08-21 10:48:32 +00:00
|
|
|
|
try
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-21 10:48:32 +00:00
|
|
|
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT ||
|
|
|
|
|
Environment.OSVersion.Platform == PlatformID.Win32Windows)
|
|
|
|
|
{
|
|
|
|
|
glControl = new OpenTK.Platform.Windows.WinGLControl(this, new DisplayMode(Width, Height));
|
|
|
|
|
}
|
|
|
|
|
else if (Environment.OSVersion.Platform == PlatformID.Unix ||
|
|
|
|
|
Environment.OSVersion.Platform == (PlatformID)128) // some older versions of Mono reported 128.
|
|
|
|
|
{
|
|
|
|
|
glControl = new OpenTK.Platform.X11.X11GLControl(this);
|
|
|
|
|
//, new DisplayMode(this.Width, this.Height, new OpenTK.Platform.ColorDepth(1, 1, 1, 1), 1, 0, 0, 0, false, false, false, 0.0f));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new PlatformNotSupportedException(
|
|
|
|
|
"Your operating system is not currently supported. We are sorry for the inconvenience."
|
|
|
|
|
);
|
|
|
|
|
}
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
2007-08-21 10:48:32 +00:00
|
|
|
|
catch (Exception e)
|
2007-07-23 00:15:18 +00:00
|
|
|
|
{
|
2007-08-21 10:48:32 +00:00
|
|
|
|
Debug.Print("Could not create GLControl, error: {0}", e.ToString());
|
|
|
|
|
throw;
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-21 10:48:32 +00:00
|
|
|
|
this.Visible = true;
|
|
|
|
|
|
2007-08-20 10:46:37 +00:00
|
|
|
|
OpenTK.OpenGL.GL.LoadAll();
|
2007-08-20 14:12:57 +00:00
|
|
|
|
this.OnResize(EventArgs.Empty);
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Swaps the front and back buffers, and presents the rendered scene to the screen.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SwapBuffers()
|
|
|
|
|
{
|
|
|
|
|
Context.SwapBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Makes the underlying GLContext of this GLControl current. All OpenGL commands issued
|
|
|
|
|
/// from this point are interpreted by this GLContext.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void MakeCurrent()
|
|
|
|
|
{
|
|
|
|
|
Context.MakeCurrent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- Public Properties ---
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the AspectRatio of the control this GLContext object
|
|
|
|
|
/// renders to. This is usually used in a call to Glu.Perspective.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double AspectRatio
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this.Width / (double)this.Height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the display mode of the control.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Fullscreen
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2007-08-05 13:51:07 +00:00
|
|
|
|
return false;
|
|
|
|
|
//throw new NotImplementedException();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2007-08-05 13:51:07 +00:00
|
|
|
|
//throw new NotImplementedException();
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region --- IGLControl Members ---
|
|
|
|
|
|
|
|
|
|
#region public bool IsIdle
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the idle status of the control.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsIdle
|
|
|
|
|
{
|
2007-08-20 10:46:37 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (glControl == null)
|
|
|
|
|
this.CreateContext();
|
|
|
|
|
|
|
|
|
|
return glControl.IsIdle;
|
|
|
|
|
}
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public IGLContext Context
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the opengl context associated with this control.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IGLContext Context
|
|
|
|
|
{
|
2007-08-20 10:46:37 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (glControl == null)
|
|
|
|
|
this.CreateContext();
|
|
|
|
|
|
|
|
|
|
return glControl.Context;
|
|
|
|
|
}
|
2007-07-23 00:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region DisplayMode changes
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Selects the fullscreen DisplayMode closest to the DisplayMode requested.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="mode">
|
|
|
|
|
/// The fullscreen DisplayMode to match, or null to get the current screen DisplayMode.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <returns>The DisplayMode closest to the requested one, or null if no DisplayModes are available.</returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// <see cref="SetDisplayMode">SetDisplayMode</see>
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public DisplayMode SelectDisplayMode(DisplayMode mode)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
//return glWindow.SelectDisplayMode(mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Selects the fullscreen DisplayMode closest to the DisplayMode requested, accoriding to the specified
|
|
|
|
|
/// parameters.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="mode">
|
|
|
|
|
/// The fullscreen DisplayMode to match, or null to get the current screen DisplayMode.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="options">
|
|
|
|
|
/// The DisplayModeMatchOptions flags that indicate how to search for the requested DisplayMode.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// The DisplayMode closest to the requested one, or null if no DisplayModes are available or
|
|
|
|
|
/// DisplayModeMatchOptions.ExactMatch was passed.
|
|
|
|
|
/// </returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// <see cref="SetDisplayMode">SetDisplayMode</see>
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public DisplayMode SelectDisplayMode(DisplayMode mode, DisplayModeMatchOptions options)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
//return glWindow.SelectDisplayMode(mode, options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the requested DisplayMode.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="mode">
|
|
|
|
|
/// The fulscreen DisplayMode to set. Passing null will return the application to windowed
|
|
|
|
|
/// mode.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Use SelectDisplayMode to select one of the available fullscreen modes.
|
|
|
|
|
/// <para>
|
|
|
|
|
/// If the mode requested is not available, this function will throw a
|
|
|
|
|
/// <exception cref="DisplayModeNotAvailable">DisplayModeNotAvailable</exception> exception.
|
|
|
|
|
/// </para>
|
|
|
|
|
/// <para>
|
|
|
|
|
/// Pass null to return to windowed mode. The previous desktop DisplayMode will be automatically reset by this
|
|
|
|
|
/// function. This function cannot be used to permanently change the user's desktop DisplayMode.
|
|
|
|
|
/// </para>
|
|
|
|
|
/// <see cref="SelectDisplayMode(DisplayMode mode)">SelectDisplayMode</see>
|
|
|
|
|
/// <seealso cref="DisplayModeNotAvailable">DisplayModeNotAvailable exception</seealso>
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public void SetDisplayMode(DisplayMode mode)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
//glWindow.SetDisplayMode(mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|