Added new GameWindow constructors that specify the desired GraphicsContext (OpenGL) version and flags.

This commit is contained in:
the_fiddler 2009-03-07 10:49:32 +00:00
parent 9981b92e5a
commit 0759beaebf
5 changed files with 37 additions and 28 deletions

View file

@ -149,6 +149,25 @@ namespace OpenTK
/// <param name="options">GameWindow options regarding window appearance and behavior.</param>
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device)
: this(width, height, mode, title, options, device, 1, 0, GraphicsContextFlags.Default)
{ }
#endregion
#region public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device, int major, int minor, GraphicsContextFlags flags)
/// <summary>Constructs a new GameWindow with the specified attributes.</summary>
/// <param name="width">The width of the GameWindow in pixels.</param>
/// <param name="height">The height of the GameWindow in pixels.</param>
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
/// <param name="title">The title of the GameWindow.</param>
/// <param name="options">GameWindow options regarding window appearance and behavior.</param>
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
/// <param name="major">The major version for the OpenGL GraphicsContext.</param>
/// <param name="major">The minor version for the OpenGL GraphicsContext.</param>
/// <param name="flags">The GraphicsContextFlags version for the OpenGL GraphicsContext.</param>
public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device,
int major, int minor, GraphicsContextFlags flags)
{
if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
if (height <= 0) throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
@ -157,12 +176,12 @@ namespace OpenTK
if (device == null)
device = DisplayDevice.Default;
glWindow = Platform.Factory.CreateNativeGLWindow();
glWindow = Platform.Factory.CreateNativeGLWindow();
glWindow.Destroy += glWindow_Destroy;
try
{
glWindow.CreateWindow(width, height, mode, out glContext);
glWindow.CreateWindow(width, height, mode, major, minor, flags, out glContext);
glContext.MakeCurrent(this.WindowInfo);
(glContext as IGraphicsContextInternal).LoadAll();
}
@ -173,30 +192,23 @@ namespace OpenTK
glWindow.DestroyWindow();
throw;
}
this.Title = title;
if ((options & GameWindowFlags.Fullscreen) != 0)
{
device.ChangeResolution(width, height, mode.ColorFormat.BitsPerPixel, 0);
this.WindowState = WindowState.Fullscreen;
//throw new NotImplementedException();
}
this.VSync = VSyncMode.On; //VSyncMode.Adaptive;
glWindow.Resize += new ResizeEvent(glWindow_Resize);
glWindow.Resize += delegate(object sender, ResizeEventArgs e) { OnResizeInternal(e); };
}
void glWindow_Resize(object sender, ResizeEventArgs e)
{
Debug.Print("glWindow_Resize event fired.");
OnResizeInternal(e);
}
#endregion
#region Obsolete
/// <summary>
/// Constructs a new GameWindow, and opens a render window with the specified DisplayMode.
@ -218,6 +230,8 @@ namespace OpenTK
#endregion
#endregion
#region --- Private Methods ---
#region void glWindow_Destroy(object sender, EventArgs e)

View file

@ -15,12 +15,9 @@ using OpenTK.Graphics;
namespace OpenTK.Platform
{
/// <summary>
/// This interface supports OpenTK, and is not intended for use by OpenTK programs.
/// </summary>
internal interface INativeGLWindow : IResizable, IDisposable
{
void CreateWindow(int width, int height, GraphicsMode mode, out IGraphicsContext context);
void CreateWindow(int width, int height, GraphicsMode mode, int major, int minor, GraphicsContextFlags flags, out IGraphicsContext context);
void DestroyWindow();
void ProcessEvents();
void PointToClient(ref System.Drawing.Point p);
@ -32,9 +29,7 @@ namespace OpenTK.Platform
string Title { get; set; }
bool Visible { get; set; }
bool IsIdle { get; }
//IGraphicsContext Context { get; }
IInputDriver InputDriver { get; }
//bool Fullscreen { get; set; }
WindowState WindowState { get; set; }
WindowBorder WindowBorder { get; set; }

View file

@ -574,14 +574,14 @@ namespace OpenTK.Platform.MacOS
#region INativeGLWindow Members
public void CreateWindow(int width, int height, OpenTK.Graphics.GraphicsMode mode, out OpenTK.Graphics.IGraphicsContext context)
public void CreateWindow(int width, int height, OpenTK.Graphics.GraphicsMode mode, int major, int minor, GraphicsContextFlags flags, out OpenTK.Graphics.IGraphicsContext context)
{
Rect r = new Rect(0, 0, (short)width, (short)height);
CreateNativeWindow(mWindowClass, mWindowAttrib, r);
Show();
this.context = new Graphics.GraphicsContext(mode, window);
this.context = new Graphics.GraphicsContext(mode, window, major, minor, flags);
this.context.MakeCurrent(window);
context = this.context;

View file

@ -311,7 +311,7 @@ namespace OpenTK.Platform.Windows
#region public void CreateWindow(int width, int height, GraphicsMode mode, out IGraphicsContext context)
public void CreateWindow(int width, int height, GraphicsMode mode, out IGraphicsContext context)
public void CreateWindow(int width, int height, GraphicsMode mode, int major, int minor, GraphicsContextFlags flags, out IGraphicsContext context)
{
Debug.Print("Creating native window.");
Debug.Indent();
@ -370,7 +370,7 @@ namespace OpenTK.Platform.Windows
Functions.SetWindowPos(this.Handle, IntPtr.Zero, Left, Top, rect.right - rect.left,
rect.bottom - rect.top, SetWindowPosFlags.SHOWWINDOW);
context = new GraphicsContext(mode, window);
context = new GraphicsContext(mode, window, major, minor, flags);
Cursor.Current = Cursors.Default;

View file

@ -199,9 +199,9 @@ namespace OpenTK.Platform.X11
#region --- INativeGLWindow Members ---
#region public void CreateWindow(int width, int height, GraphicsMode mode, out IGraphicsContext context)
#region CreateWindow
public void CreateWindow(int width, int height, GraphicsMode mode, out IGraphicsContext context)
public void CreateWindow(int width, int height, GraphicsMode mode, int major, int minor, GraphicsContextFlags flags, out IGraphicsContext context)
{
if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
if (height <= 0) throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");
@ -244,7 +244,7 @@ namespace OpenTK.Platform.X11
//XVisualInfo vis = window.VisualInfo;
//Glx.CreateContext(window.Display, ref vis, IntPtr.Zero, true);
}
context = new GraphicsContext(mode, window);
context = new GraphicsContext(mode, window, major, minor, flags);
// Set the window hints
SetWindowMinMax(_min_width, _min_height, -1, -1);