
Help problem with changing to version 0.9-8.1 from 0.3.14 and GLWidget
Posted Monday, 3 August, 2009 - 21:38 by alanb inHi,
I have been using a very old version of opentk (0.3.14) with GLWidget for quite a while in some software Im writing. Yesterday I hit a bug in this old version so decided to upgrade. I downloaded 0.9.8.1 and built it ok on opensuse 11.1. Thought everything would be ok if I just swapped the dlls in my project, I renamed the imports to OpenTK.Graphics.OpenGL; etc and built my project. No compilation errors. However when I run I get
Unhandled Exception: System.InvalidOperationException: No GraphicsContext available in the calling thread.
at OpenTK.Graphics.GL.LoadAll () [0x00000]
So could someone tell me how things have changed or how to solve my problem? Looking at your example code I also suspect that GL.LoadAll() is deprecated but again dont know what the changes are. I saw your example using windows forms + GLcontrol. However I have a lot of time invested in my Gtk based project so swapping over to windows forms would be impossible. I am not writing a major 3D game or anything like that I just want a Gdk window to display some simple 3D paths so have not spent any time on openGL other than to learn the basics. I am prepared to change over to GLControl if that can be embedded in a Gtk Widget so my question is can it? I use monodevelop and tried browsing the opentk dll but couldnt see any reference to the control. Also monodevelop reported nothing available when I tried to add items to the toolbox from opentk.dll and opentk.utilities.dll.
I would rather progress than go back to the earlier versions so any help would be appreciated.
Thanks
Alan


Comments
Re: Help problem with changing to version 0.9-8.1 from ...
Your code should work fine after a simple change: add a call to GraphicsContext.CreateDummyContext() as soon as you create the OpenGL context through your Gtk Widget.
OpenTK 0.9.8 is much stricter than 0.3.14 regarding OpenGL. One of the changes is that it now requires the creation of an OpenGL context prior to the use of OpenGL commands. Since you are creating the context from an external library, you need to inform OpenTK of the context's existence - hence the CreateDummyContext() method.
Another change is that the debug version of OpenTK.dll will now check for OpenGL errors automatically. This is *very* useful while developing an application, as it makes debugging much easier. Just remember to switch to the release OpenTK.dll when distributing your application (the debug version carries a hefty performance hit).
Edit: as part of the ongoing documentation effort, I have added a page that explains how to use external contexts with OpenTK.
Re: Help problem with changing to version 0.9-8.1 from ...
I understand in principle what you are saying however practice is another matter as I did not write the GLWidget code. I have looked through the GLWidget code and tried putting GraphicsContext.CreateDummyContext() in several places but I still get the same error message. Perhaps you could suggest where, as I see no place which has an explicit call to CreateContext(). I have taken some liberties with the GLWidget code included below in that I have deleted all the windows stuff leaving just the X part. When I know where to put the call to CreateDummyContext() I will reinstate the complete version.
Thanks
Alan
Re: Help problem with changing to version 0.9-8.1 from ...
IIRC CreateDummyContext method requires an active context on the current thread. So, calling such method should be no problem after MakeCurrent call.
Re: Help problem with changing to version 0.9-8.1 from ...
I'll see what I can work out and get the GLWidget site updated with relevant information. It will be a few days.
Re: Help problem with changing to version 0.9-8.1 from ...
It's been a few days. Still have not found the time. :(
Re: Help problem with changing to version 0.9-8.1 from ...
After creating a GLContext using the GLWidget code and making the context current, I call CreateDummyContext and get
System.NullReferenceException: Object reference not set to an instance of an object.
at OpenTK.Platform.Windows.Wgl.GetCurrentContext()
at OpenTK.Platform.Windows.WinFactory.b__0()
at OpenTK.Graphics.GraphicsContext.CreateDummyContext()
On a related note, I would like to get GLWidget to create a context using the underlying context code that OpenTK uses.
Related Post: http://www.opentk.com/node/903
I used MonoDevelop on Windows and I am not seeing the issue I previously mentioned. I will have to test some things.
Re: Help problem with changing to version 0.9-8.1 from ...
Isn't this related to http://www.opentk.com/node/993 ?
Re: Help problem with changing to version 0.9-8.1 from ...
Any chance for a stack trace from a debug version of OpenTK? It might help.
There are two ways to make GLWidget work with OpenTK directly: either make it depend on OpenTK or create a third, "glue" assembly that acts as the bridge between OpenTK and GLWidget. The actual code will resemble EGL: you'll need to fill a WinWindowInfo, X11WindowInfo or CarbonWindowInfo struct and pass it to the GraphicsContext constructor (along with any other parameters you wish to set, e.g. OpenGL version).These structs hold platform-specific information that is used to contsruct the context (a window handle and a DC for WinWindowInfo, a window handle, display connection and visual for X11WindowInfo etc). GLWidget should already have this information available, so the actual implementation should be relatively simple.
In both cases, we'll need to make a few changes in OpenTK to expose some internal types to the world - let me take a look.
Edit @objarni: good memory, this is the issue. I'll track this down.
Re: Help problem with changing to version 0.9-8.1 from ...
Ok, the necessary classes and enums are now public (SVN trunk). This code can be changed as needed to accommodate the GLWidget - please let me know if you need any help with this task. I am going to hunt down the GetCurrentContext bug now.
Re: Help problem with changing to version 0.9-8.1 from ...
Ok, this issue should be fixed now.