
Tao.SDL or CS-SDL with OpenTK?
Posted Wednesday, 28 September, 2011 - 04:10 by terinfire inHi all! Another Tao Framework developer moving over to OpenTK (if possible).
I'm having some issues, and maybe I've done something funny.
I'd like to make OpenGL calls and use OpenGL, but have SDL handle the Window, etc. Ported my Tao code over and everything compiles. My initial stuff with the Compatibility compiled/ran/worked. Tried moving it over to the native OpenTK framework without using the compatibility and I'm having a lot of problems.
On the first OpenGL call, it blows up with an NullReferenceException...
The following code used to work (again, until I ported over to OpenTK):
if ( Sdl.SDL_InitSubSystem( Sdl.SDL_INIT_VIDEO | Sdl.SDL_OPENGL ) != 0 ) { Debug.WriteLine( "Couldn't initialize video subsystem." ); return; } Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_DOUBLEBUFFER, 1 ); Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_BUFFER_SIZE, ColorDepth ); Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_RED_SIZE, 8 ); Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_GREEN_SIZE, 8 ); Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_BLUE_SIZE, 8 ); m_Video = Sdl.SDL_SetVideoMode( Width, Height, ColorDepth, Flags ); if ( m_Video == IntPtr.Zero ) { Debug.WriteLine( "Couldn't start video mode." ); return; } GL.Enable( EnableCap.Texture2D ); // NullRefException right here
I have a lot of sub-systems that spin-up. My guess is that OpenTK hasn't necessarily spun-up like it should. A lot of the examples I've seen actually have OpenTK manage the window, and that's what I'm trying to avoid doing. No inner exception is available either...
Any thoughts? Hopefully I'm not going to have to roll back to Tao's framework... Oy.


Comments
Re: Tao.SDL or CS-SDL with OpenTK?
You need to inform OpenTK that you manage your own OpenGL context, like this:
This will use the existing context to initialize the OpenGL bindings and everything should work fine afterwards (please post if it doesn't!) See the GraphicsContext documentation for more details.
Tao initializes itself implicitly at the first OpenGL function call. While this is more convenient when using different systems like Tao.SDL/GLUT/etc, it is very easy to initialize the bindings without a context (causing random crashes). Back when the Tao forums existed, every second post was about this issue - which is why OpenTK requires explicit initialization when using an external window library.
Re: Tao.SDL or CS-SDL with OpenTK?
Hey, thank you for the response. Unfortunately, I'm still having the same error.
I supplied the ContextHandle to OpenTK when creating the context. If I don't do the above code and just let it do a CreateDummyContext parameterless, I get the following error:
No GraphicsContext is current on the calling thread.Not sure what's going on. I tried some of this last night after seeing it. Just wondering if maybe there are some dependency DLL's that aren't in my bin folder or what...
Re: Tao.SDL or CS-SDL with OpenTK?
> OpenTK.dll!OpenTK.Platform.Windows.Wgl.GetCurrentContext() Line 26 C#
OpenTK.dll!OpenTK.Platform.Windows.WinFactory.CreateGetCurrentGraphicsContext.AnonymousMethod__0() Line 68 + 0x5 bytes C#
OpenTK.dll!OpenTK.Graphics.GraphicsContext.CreateDummyContext() Line 282 + 0xe bytes C#
Delegates' member variables are all null.
I'm getting this error from the call:
OpenTK.Graphics.GraphicsContext.CreateDummyContext();