diff --git a/Source/Examples/Tests/MathSpeed.cs b/Source/Examples/Tests/MathSpeed.cs index d0ba07e8..d10c7157 100644 --- a/Source/Examples/Tests/MathSpeed.cs +++ b/Source/Examples/Tests/MathSpeed.cs @@ -12,7 +12,7 @@ using OpenTK.Math; namespace Examples.Tests { - [Example("Math speed test", ExampleCategory.Test, 2, false)] + [Example("Math speed test", ExampleCategory.Test, 2/*, false*/)] public class MathSpeed { public static void Main() @@ -31,7 +31,7 @@ namespace Examples.Tests Vector3.Add(ref a, ref b, out res); res = a + b; res = Vector3.Zero; - + /* watch.Reset(); watch.Start(); for (int i = 100000000; --i != 0; ) @@ -63,6 +63,29 @@ namespace Examples.Tests watch.Stop(); res += res; // To make sure the whole for-loop isn't optimized-out Trace.WriteLine(String.Format("Vector3.Add(ref a, ref b, out res)\t{0}ns", (watch.Elapsed.TotalSeconds / 10.0).ToString())); +*/ + a = Vector3.UnitX; + b = Vector3.UnitY; + res = Vector3.Add(ref a, ref b); + Trace.WriteLine(res.ToString()); + + a = Vector3.UnitX; + b = Vector3.UnitY; + Vector3.Add(a, b, out res); + Trace.WriteLine(res.ToString()); + + Vector2Im q = new Vector2(0.0f, 1.0f); + Vector2Im p = new Vector2(2.0f, 3.0f); + Vector2Im s = Vector2.Add(p, q); + p = s + q; + } + + static Vector3 pos = new Vector3(); + + static Vector3 Pos + { + get { return pos; } + set { pos = value; } } } } diff --git a/Source/Examples/Tutorial/Text.cs b/Source/Examples/Tutorial/Text.cs index a78063c3..502de8dc 100644 --- a/Source/Examples/Tutorial/Text.cs +++ b/Source/Examples/Tutorial/Text.cs @@ -120,6 +120,9 @@ namespace Examples.Tutorial else if (scroll_speed < 0.0f && current_position < warparound_position) current_position = initial_position; + TextHandle t = null; + text.Prepare((1.0 / e.Time).ToString(), serif, out t); + // TextPrinter.Begin() sets up a 2d orthographic projection, with the x axis // moving from 0 to viewport.Width (left to right) and the y axis from // 0 to viewport.Height (top to bottom). This is the typical coordinate system @@ -127,6 +130,13 @@ namespace Examples.Tutorial // TextPrinter.End() restores your previous projection/modelview matrices. text.Begin(); + using (t) + { + //text.Begin(); + text.Draw(t); + //text.End(); + } + GL.Translate(0.0f, current_position, 0.0f); text.Draw(poem_handle); diff --git a/Source/OpenTK/GLContext.cs b/Source/OpenTK/GLContext.cs index dbe5e6cd..8332b73b 100644 --- a/Source/OpenTK/GLContext.cs +++ b/Source/OpenTK/GLContext.cs @@ -17,10 +17,16 @@ namespace OpenTK /// public class GLContext : IGLContext { - /// - /// The actual render context implementation for the underlying platform. - /// - private IGLContext implementation; + IGLContext implementation; // The actual render context implementation for the underlying platform. + List dispose_queue = new List(); + + static SortedList available_contexts = + new SortedList(); // Contains all available OpenGL contexts. + + delegate IntPtr GetCurrentContextDelegate(); + static GetCurrentContextDelegate StaticGetCurrentContext; + + #region public GLContext(DisplayMode mode, IWindowInfo window) /// /// Constructs a new GLContext with the specified DisplayMode, and bound to the specified IWindowInfo. @@ -29,6 +35,9 @@ namespace OpenTK /// public GLContext(DisplayMode mode, IWindowInfo window) { + if (available_contexts.Count == 0) + available_contexts.Add(0, new WeakReference(null)); + switch (Environment.OSVersion.Platform) { case PlatformID.Unix: @@ -48,6 +57,17 @@ namespace OpenTK } } + #endregion + + #region public static IGLContext CurrentContext + + public static GLContext CurrentContext + { + get { return (GLContext)available_contexts[StaticGetCurrentContext().ToInt64()].Target; } + } + + #endregion + #region --- IGLContext Members --- /// @@ -79,7 +99,7 @@ namespace OpenTK /// public void CreateContext() { - implementation.CreateContext(); + CreateContext(true, null); } /// @@ -99,7 +119,7 @@ namespace OpenTK /// public void CreateContext(bool direct) { - implementation.CreateContext(direct); + CreateContext(direct, null); } /// @@ -112,6 +132,10 @@ namespace OpenTK public void CreateContext(bool direct, IGLContext source) { implementation.CreateContext(direct, source); + + available_contexts.Add(Context.ToInt64(), new WeakReference(this)); + if (StaticGetCurrentContext == null) + StaticGetCurrentContext = implementation.GetCurrentContext; } /// @@ -130,6 +154,33 @@ namespace OpenTK implementation.MakeCurrent(); } + /// + /// Gets a System.Boolean indicating whether this Context is current in the calling thread. + /// + public bool IsCurrent + { + get { return implementation.IsCurrent; } + } + + /// + /// Gets a System.IntPtr containing the handle to the OpenGL context which is current in the + /// calling thread, or IntPtr.Zero if no OpenGL context is current. + /// + /// A System.IntPtr that holds the handle to the current OpenGL context. + public IntPtr GetCurrentContext() + { + return implementation.GetCurrentContext(); + } + + /// + /// Raised when a Context is destroyed. + /// + public event DestroyEvent Destroy + { + add { implementation.Destroy += value; } + remove { implementation.Destroy -= value; } + } + /// /// Gets the address of an OpenGL extension function. /// @@ -162,6 +213,28 @@ namespace OpenTK set { implementation.VSync = value; } } + /// + /// Registers an OpenGL resource for disposal. + /// + /// The OpenGL resource to dispose. + public void RegisterForDisposal(IDisposable resource) + { + GC.KeepAlive(resource); + dispose_queue.Add(resource); + } + + /// + /// Disposes all registered OpenGL resources. + /// + public void DisposeResources() + { + foreach (IDisposable resource in dispose_queue) + { + resource.Dispose(); + } + dispose_queue.Clear(); + } + #endregion #region IDisposable Members @@ -171,6 +244,7 @@ namespace OpenTK /// public void Dispose() { + available_contexts.Remove(Context.ToInt64()); implementation.Dispose(); } diff --git a/Source/OpenTK/GLControl.cs b/Source/OpenTK/GLControl.cs index af9e1b52..2fa04fc7 100644 --- a/Source/OpenTK/GLControl.cs +++ b/Source/OpenTK/GLControl.cs @@ -200,7 +200,7 @@ namespace OpenTK // specific depth for the DisplayMode - we let the driver select one instead. display_mode.Color = new ColorMode(0); context = new GLContext(display_mode, info); - context.CreateContext(); + context.CreateContext(true, null); idle = new PlatformIdle(info); } else diff --git a/Source/OpenTK/GameWindow.cs b/Source/OpenTK/GameWindow.cs index 131e4d45..d6e3fd83 100644 --- a/Source/OpenTK/GameWindow.cs +++ b/Source/OpenTK/GameWindow.cs @@ -71,6 +71,8 @@ namespace OpenTK //InputDriver input_driver; + GLContext glContext; + #endregion #region --- Internal Properties --- @@ -126,6 +128,9 @@ namespace OpenTK glWindow.Destroy += new DestroyEvent(glWindow_Destroy); CreateWindow(mode, title); + + glContext = new GLContext(mode, glWindow.WindowInfo); + glContext.CreateContext(); //this.vsync = VSyncMode.Adaptive; this.VSync = VSyncMode.On; } @@ -199,7 +204,8 @@ namespace OpenTK mode = new DisplayMode(640, 480); this.CreateWindow(mode); } - return glWindow.Context; + //return glWindow.Context; + return glContext; } } @@ -355,22 +361,11 @@ namespace OpenTK { if (!Exists) { - try - { - glWindow.CreateWindow(mode); - this.Title = title; - //input_driver = new InputDriver(this); - } - catch (ApplicationException expt) - { - Debug.Print(expt.ToString()); - throw; - } + glWindow.CreateWindow(mode); + this.Title = title; } else - { throw new InvalidOperationException("A render window already exists for this GameWindow."); - } } #endregion diff --git a/Source/OpenTK/Platform/DummyGLContext.cs b/Source/OpenTK/Platform/DummyGLContext.cs index d5f0ad5d..73e2e6de 100644 --- a/Source/OpenTK/Platform/DummyGLContext.cs +++ b/Source/OpenTK/Platform/DummyGLContext.cs @@ -12,6 +12,7 @@ namespace OpenTK.Platform { /// /// An empty IGLContext implementation to be used inside the Visual Studio designer. + /// This class supports OpenTK, and is not intended for use by OpenTK programs. /// internal sealed class DummyGLContext : IGLContext { @@ -37,6 +38,20 @@ namespace OpenTK.Platform public void SwapBuffers() { } public void MakeCurrent() { } + public bool IsCurrent { get { return true; } } + public IntPtr GetCurrentContext() { return IntPtr.Zero; } + + public event DestroyEvent Destroy; + + public void RegisterForDisposal(IDisposable resource) + { + throw new NotImplementedException("Use the general GLContext class instead."); + } + + public void DisposeResources() + { + throw new NotImplementedException("Use the general GLContext class instead."); + } public IntPtr GetAddress(string function) { return IntPtr.Zero; } public IEnumerable GetDisplayModes() { return null; } diff --git a/Source/OpenTK/Platform/IGLContext.cs b/Source/OpenTK/Platform/IGLContext.cs index b90f4afd..85eb275a 100644 --- a/Source/OpenTK/Platform/IGLContext.cs +++ b/Source/OpenTK/Platform/IGLContext.cs @@ -30,28 +30,6 @@ namespace OpenTK.Platform /// DisplayMode Mode { get; } - /// - /// Creates an OpenGL context. - /// - void CreateContext(); - - /// - /// Creates an OpenGL context with a direct or indirect rendering mode. This parameter is ignored - /// on Windows platforms (direct mode only). - /// - /// Set to true for direct rendering or false otherwise. - /// - /// - /// Direct rendering is the default rendering mode for OpenTK, since it can provide higher performance - /// in some circumastances. - /// - /// - /// The 'direct' parameter is a hint, and will ignored if the specified mode is not supported (e.g. setting - /// indirect rendering on Windows platforms). - /// - /// - void CreateContext(bool direct); - /// /// Creates an OpenGL context with the specified direct/indirect rendering mode and sharing state with the /// specified IGLContext. @@ -71,6 +49,23 @@ namespace OpenTK.Platform /// void MakeCurrent(); + /// + /// Gets a System.Boolean indicating whether this Context is current in the calling thread. + /// + bool IsCurrent { get; } + + /// + /// Gets a System.IntPtr containing the handle to the OpenGL context which is current in the + /// calling thread, or IntPtr.Zero if no OpenGL context is current. + /// + /// A System.IntPtr that holds the handle to the current OpenGL context. + IntPtr GetCurrentContext(); + + /// + /// Raised when a Context is destroyed. + /// + event DestroyEvent Destroy; + /// /// Gets the address of an OpenGL extension function. /// @@ -92,5 +87,24 @@ namespace OpenTK.Platform /// Gets or sets a value indicating whether VSyncing is enabled. /// bool VSync { get; set; } + + /// + /// Registers an OpenGL resource for disposal. + /// + /// The OpenGL resource to dispose. + /// + /// You may not destroy OpenGL resources in finalizers, since they run in + /// a different thread. To avoid this problem, use this method to register + /// a resource for disposal during the finalizer call, and call DisposeResources() + /// from the main thread to dispose it. + /// + void RegisterForDisposal(IDisposable resource); + + /// + /// Disposes all registered OpenGL resources. + /// + void DisposeResources(); } + + public delegate void DestroyEvent(T sender, EventArgs e); } diff --git a/Source/OpenTK/Platform/INativeGLWindow.cs b/Source/OpenTK/Platform/INativeGLWindow.cs index f03d5b64..c82bff58 100644 --- a/Source/OpenTK/Platform/INativeGLWindow.cs +++ b/Source/OpenTK/Platform/INativeGLWindow.cs @@ -27,7 +27,7 @@ namespace OpenTK.Platform string Title { get; set; } bool Visible { get; set; } bool IsIdle { get; } - IGLContext Context { get; } + //IGLContext Context { get; } IInputDriver InputDriver { get; } event CreateEvent Create; diff --git a/Source/OpenTK/Platform/Windows/WinGLContext.cs b/Source/OpenTK/Platform/Windows/WinGLContext.cs index 6a6e7294..bb8b3b50 100644 --- a/Source/OpenTK/Platform/Windows/WinGLContext.cs +++ b/Source/OpenTK/Platform/Windows/WinGLContext.cs @@ -21,9 +21,9 @@ namespace OpenTK.Platform.Windows { /// /// Provides methods to create and control an opengl context on the Windows platform. - /// 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. /// - internal sealed class WinGLContext : OpenTK.Platform.IGLContext, IDisposable + internal sealed class WinGLContext : IGLContext { private IntPtr deviceContext; private IntPtr renderContext; @@ -153,7 +153,7 @@ namespace OpenTK.Platform.Windows } #endregion - + #region --- IGLContext Members --- #region public IntPtr Context @@ -212,14 +212,11 @@ namespace OpenTK.Platform.Windows // Do not rely on OpenTK.Platform.Windows.Wgl - the context is not ready yet, // and Wgl extensions will fail to load. renderContext = Wgl.Imports.CreateContext(deviceContext); - if (renderContext != IntPtr.Zero) - { - Debug.WriteLine(String.Format("done! (id: {0})", renderContext)); - } - else - { + if (renderContext == IntPtr.Zero) throw new ApplicationException("Could not create OpenGL render context (Wgl.CreateContext() return 0)."); - } + + Debug.WriteLine(String.Format("done! (id: {0})", renderContext)); + Wgl.Imports.MakeCurrent(deviceContext, renderContext); Wgl.LoadAll(); GL.LoadAll(); @@ -267,6 +264,36 @@ namespace OpenTK.Platform.Windows #endregion + #region public bool IsCurrent + + public bool IsCurrent + { + get { return Wgl.GetCurrentContext() == this.renderContext; } + } + + #endregion + + #region public IntPtr GetCurrentContext() + + public IntPtr GetCurrentContext() + { + return Wgl.GetCurrentContext(); + } + + #endregion + + public event DestroyEvent Destroy; + + public void RegisterForDisposal(IDisposable resource) + { + throw new NotImplementedException("Use the general GLContext class instead."); + } + + public void DisposeResources() + { + throw new NotImplementedException("Use the general GLContext class instead."); + } + #region public DisplayMode[] GetDisplayModes() public IEnumerable GetDisplayModes() @@ -337,7 +364,6 @@ namespace OpenTK.Platform.Windows public void Dispose() { - //Debug.Print("Manually disposing WinGLContext {0}.", this.renderContext); Dispose(true); GC.SuppressFinalize(this); } @@ -346,9 +372,7 @@ namespace OpenTK.Platform.Windows { if (!disposed) { - // Clean unmanaged resources here - // The following call uses the Debug and Wgl classes, making it unsafe? - ReleaseResources(); + DestroyContext(); if (calledManually) { @@ -363,10 +387,13 @@ namespace OpenTK.Platform.Windows Dispose(false); } - #region private void ReleaseResources() + #region private void DestroyContext() - private void ReleaseResources() + private void DestroyContext() { + if (Destroy != null) + Destroy(this, EventArgs.Empty); + if (renderContext != IntPtr.Zero) { Wgl.Imports.MakeCurrent(IntPtr.Zero, IntPtr.Zero); @@ -387,6 +414,7 @@ namespace OpenTK.Platform.Windows } } + /* if (opengl32Handle != IntPtr.Zero) { if (!Functions.FreeLibrary(opengl32Handle)) @@ -396,6 +424,7 @@ namespace OpenTK.Platform.Windows } opengl32Handle = IntPtr.Zero; } + */ } #endregion diff --git a/Source/OpenTK/Platform/Windows/WinGLNative.cs b/Source/OpenTK/Platform/Windows/WinGLNative.cs index 2db807cf..1c74408c 100644 --- a/Source/OpenTK/Platform/Windows/WinGLNative.cs +++ b/Source/OpenTK/Platform/Windows/WinGLNative.cs @@ -27,7 +27,6 @@ namespace OpenTK.Platform.Windows { #region --- Fields --- - private WinGLContext glContext; private DisplayMode mode = new DisplayMode(); private WinRawInput driver; @@ -190,15 +189,6 @@ namespace OpenTK.Platform.Windows #endregion - #region public IGLContext Context - - public IGLContext Context - { - get { return glContext; } - } - - #endregion - #region public bool Fullscreen public bool Fullscreen @@ -286,7 +276,7 @@ namespace OpenTK.Platform.Windows #endregion - #region private void CreateWindow(DisplayMode mode) + #region public void CreateWindow(DisplayMode mode) public void CreateWindow(DisplayMode windowMode) { @@ -322,7 +312,7 @@ namespace OpenTK.Platform.Windows left_border = -rect.left; bottom_border = rect.bottom - windowMode.Height; right_border = rect.right - windowMode.Width; - + cp.Width = rect.right - rect.left; cp.Height = rect.bottom - rect.top; cp.Caption = "OpenTK Game Window"; @@ -331,17 +321,14 @@ namespace OpenTK.Platform.Windows // which is raised CreateHandle() CreateHandle(cp); - if (this.Handle != IntPtr.Zero && glContext != null) + if (this.Handle != IntPtr.Zero) { 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())); - } + else throw new ApplicationException(String.Format( + "Could not create native window and/or context. Handle: {0}", + this.Handle)); Debug.Unindent(); } @@ -359,17 +346,6 @@ namespace OpenTK.Platform.Windows Debug.Print("Window created: {0}", window); - try - { - glContext = new WinGLContext(this.mode, this.WindowInfo); - glContext.CreateContext(); - } - catch (ApplicationException expt) - { - Debug.Print("Could not create opengl context, error: {0}", expt.ToString()); - throw; - } - if (this.Create != null) this.Create(this, e); } @@ -510,7 +486,6 @@ namespace OpenTK.Platform.Windows if (calledManually) { // Safe to clean managed resources - glContext.Dispose(); //base.DestroyHandle(); } disposed = true; diff --git a/Source/OpenTK/Platform/X11/X11GLContext.cs b/Source/OpenTK/Platform/X11/X11GLContext.cs index c868991f..45168354 100644 --- a/Source/OpenTK/Platform/X11/X11GLContext.cs +++ b/Source/OpenTK/Platform/X11/X11GLContext.cs @@ -16,9 +16,9 @@ namespace OpenTK.Platform.X11 { /// /// Provides methods to create and control an opengl context on the X11 platform. - /// 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. /// - internal sealed class X11GLContext : OpenTK.Platform.IGLContext + internal sealed class X11GLContext : IGLContext { private IntPtr context; private DisplayMode mode; @@ -235,11 +235,20 @@ namespace OpenTK.Platform.X11 #endregion - public bool IsCurrent() + public bool IsCurrent { + //return GetCurrentContext() == context; + get { throw new NotImplementedException(); } + } + + public IntPtr GetCurrentContext() + { + //return Glx.GetCurrentContext(); throw new NotImplementedException(); } + public event DestroyEvent Destroy; + #region public IntPtr GetAddress(string function) public IntPtr GetAddress(string function) @@ -249,6 +258,16 @@ namespace OpenTK.Platform.X11 #endregion + public void RegisterForDisposal(IDisposable resource) + { + throw new NotImplementedException("Use the general GLContext class instead."); + } + + public void DisposeResources() + { + throw new NotImplementedException("Use the general GLContext class instead."); + } + public IEnumerable GetDisplayModes() { throw new Exception("The method or operation is not implemented."); diff --git a/Source/OpenTK/Platform/X11/X11GLNative.cs b/Source/OpenTK/Platform/X11/X11GLNative.cs index 6d60e9b3..89fe5f51 100644 --- a/Source/OpenTK/Platform/X11/X11GLNative.cs +++ b/Source/OpenTK/Platform/X11/X11GLNative.cs @@ -25,7 +25,6 @@ namespace OpenTK.Platform.X11 { #region --- Fields --- - private X11GLContext glContext; private WindowInfo window = new WindowInfo(); private DisplayMode mode = new DisplayMode(); private X11Input driver; @@ -66,9 +65,8 @@ namespace OpenTK.Platform.X11 // Open the display to the X server, and obtain the screen and root window. window.Display = API.OpenDisplay(null); // null == default display if (window.Display == IntPtr.Zero) - { throw new Exception("Could not open connection to X"); - } + window.Screen = API.DefaultScreen(window.Display); window.RootWindow = API.RootWindow(window.Display, window.Screen); @@ -240,15 +238,6 @@ namespace OpenTK.Platform.X11 #endregion - #region public IGLContext Context - - public OpenTK.Platform.IGLContext Context - { - get { return glContext; } - } - - #endregion - #region public IntPtr Handle /// @@ -361,88 +350,83 @@ namespace OpenTK.Platform.X11 public void CreateWindow(DisplayMode mode) { if (exists) - { throw new ApplicationException("Render window already exists!"); - } - else - { - Debug.Print("Creating GameWindow with mode: {0}", mode.ToString()); - Debug.Indent(); - glContext = new X11GLContext(mode, window); - //glContext.PrepareContext(window); - window.VisualInfo = (glContext.Info as X11.WindowInfo).VisualInfo; + Debug.Print("Creating GameWindow with mode: {0}", mode.ToString()); + Debug.Indent(); - // Create a window on this display using the visual above - Debug.Write("Opening render window... "); - - XSetWindowAttributes attributes = new XSetWindowAttributes(); - attributes.background_pixel = IntPtr.Zero; - attributes.border_pixel = IntPtr.Zero; - attributes.colormap = - API.CreateColormap(window.Display, window.RootWindow, window.VisualInfo.visual, 0/*AllocNone*/); - window.EventMask = - EventMask.StructureNotifyMask | EventMask.SubstructureNotifyMask | EventMask.ExposureMask | - EventMask.KeyReleaseMask | EventMask.KeyPressMask;/* | + //glContext = new X11GLContext(mode, window); + //glContext.PrepareContext(window); + //window.VisualInfo = (glContext.Info as X11.WindowInfo).VisualInfo; + //window.VisualInfo = Marshal.PtrToStructure(Glx.ChooseVisual(window.Display, window.Screen, + + // Create a window on this display using the visual above + Debug.Write("Opening render window... "); + + XSetWindowAttributes attributes = new XSetWindowAttributes(); + attributes.background_pixel = IntPtr.Zero; + attributes.border_pixel = IntPtr.Zero; + attributes.colormap = + API.CreateColormap(window.Display, window.RootWindow, window.VisualInfo.visual, 0/*AllocNone*/); + window.EventMask = + EventMask.StructureNotifyMask | EventMask.SubstructureNotifyMask | EventMask.ExposureMask | + EventMask.KeyReleaseMask | EventMask.KeyPressMask;/* | EventMask.PointerMotionMask | /* Bad! EventMask.PointerMotionHintMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask;*/ - attributes.event_mask = (IntPtr)window.EventMask; + attributes.event_mask = (IntPtr)window.EventMask; - uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask | - (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel; + uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask | + (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel; - window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow, - 0, 0, mode.Width, mode.Height, 0, window.VisualInfo.depth/*(int)CreateWindowArgs.CopyFromParent*/, - (int)CreateWindowArgs.InputOutput, window.VisualInfo.visual, (UIntPtr)mask, ref attributes); + window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow, + 0, 0, mode.Width, mode.Height, 0, window.VisualInfo.depth/*(int)CreateWindowArgs.CopyFromParent*/, + (int)CreateWindowArgs.InputOutput, window.VisualInfo.visual, (UIntPtr)mask, ref attributes); - if (window.Handle == IntPtr.Zero) - { - throw new ApplicationException("XCreateWindow call failed (returned 0)."); - } - - // Set the window hints - XSizeHints hints = new XSizeHints(); - hints.x = 0; - hints.y = 0; - hints.width = mode.Width; - hints.height = mode.Height; - hints.flags = (IntPtr)(XSizeHintsFlags.USSize | XSizeHintsFlags.USPosition); - Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints); + if (window.Handle == IntPtr.Zero) + throw new ApplicationException("XCreateWindow call failed (returned 0)."); - // Register for window destroy notification - IntPtr wm_destroy_atom = Functions.XInternAtom(window.Display, - "WM_DELETE_WINDOW", true); - XWMHints hint = new XWMHints(); - Functions.XSetWMProtocols(window.Display, window.Handle, new IntPtr[] { wm_destroy_atom }, 1); + // Set the window hints + XSizeHints hints = new XSizeHints(); + hints.x = 0; + hints.y = 0; + hints.width = mode.Width; + hints.height = mode.Height; + hints.flags = (IntPtr)(XSizeHintsFlags.USSize | XSizeHintsFlags.USPosition); + Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints); - Top = Left = 0; - Right = Width; - Bottom = Height; + // Register for window destroy notification + IntPtr wm_destroy_atom = Functions.XInternAtom(window.Display, + "WM_DELETE_WINDOW", true); + XWMHints hint = new XWMHints(); + Functions.XSetWMProtocols(window.Display, window.Handle, new IntPtr[] { wm_destroy_atom }, 1); - //XTextProperty text = new XTextProperty(); - //text.value = "OpenTK Game Window"; - //text.format = 8; - //Functions.XSetWMName(window.Display, window.Handle, ref text); - //Functions.XSetWMProperties(display, window, name, name, 0, /*None*/ null, 0, hints); + Top = Left = 0; + Right = Width; + Bottom = Height; - Debug.Print("done! (id: {0})", window.Handle); + //XTextProperty text = new XTextProperty(); + //text.value = "OpenTK Game Window"; + //text.format = 8; + //Functions.XSetWMName(window.Display, window.Handle, ref text); + //Functions.XSetWMProperties(display, window, name, name, 0, /*None*/ null, 0, hints); - (glContext.Info as X11.WindowInfo).Handle = window.Handle; - glContext.CreateContext(true, null); - glContext.MakeCurrent(); + Debug.Print("done! (id: {0})", window.Handle); - API.MapRaised(window.Display, window.Handle); - mapped = true; + //(glContext.Info as X11.WindowInfo).Handle = window.Handle; + //glContext.CreateContext(true, null); + //glContext.MakeCurrent(); - driver = new X11Input(window); + API.MapRaised(window.Display, window.Handle); + mapped = true; - //GL.LoadAll(); - //Glu.LoadAll(); + driver = new X11Input(window); - Debug.Unindent(); - Debug.WriteLine("GameWindow creation completed successfully!"); - exists = true; - } + //GL.LoadAll(); + //Glu.LoadAll(); + + Debug.Unindent(); + Debug.WriteLine("GameWindow creation completed successfully!"); + exists = true; } #endregion @@ -612,8 +596,8 @@ namespace OpenTK.Platform.X11 { if (manuallyCalled) { - if (glContext != null) - glContext.Dispose(); + //if (glContext != null) + // glContext.Dispose(); // Kills connection to the X-Server. We don't want that, // 'cause it kills the ExampleLauncher too.