[Mono-osx] MonoMac and OpenTK?

ajselvig ajselvig at gmail.com
Thu Feb 3 23:23:04 EST 2011


Has anyone had any success using MonoMac with an NSOpenGLView (assumedly
along with OpenTK)? I made a naive attempt at getting to work by subclassing
NSOpenGLView, creating an OpenTK dummy context in PrepareOpenGL(), and
calling some rendering code in Update(). However, I haven't been able to get
this to do anything except: 
 - throw a NullReferenceException in the first OpenTK call, or
 - throw a System.InvalidOperationException: No GraphicsContext is current
on the calling thread.

The subclass code I'm using is below. Has anyone had any luck integrating
these two? If someone can get me pointed in the right direction, I'd be
interested in contributing a tutorial once I get it working.

Thanks.

	public class GlView : NSOpenGLView
	{
		public GlView() : base(new RectangleF(0, 0, 200, 200),
NSOpenGLView.DefaultPixelFormat)
		{
			
		}
		
		public GraphicsContext Context {
			get;
			set;
		}
		
		public override void PrepareOpenGL()
		{
			base.PrepareOpenGL();
			OpenGLContext.MakeCurrentContext();
			
			// this throws: NullReferenceException
			Context = GraphicsContext.CreateDummyContext(new
ContextHandle(OpenGLContext.CGLContextObj));
			
			// this throws: No GraphicsContext is current on the calling thread
			//Context = GraphicsContext.CreateDummyContext();
		}
		
		public override void Reshape()
		{
			base.Reshape();
			GL.Clear(ClearBufferMask.ColorBufferBit);
			
		}
		
		public override void Update ()
		{
			base.Update ();
			OpenGLContext.MakeCurrentContext();
			
			Console.WriteLine ("update");
			
			GL.MatrixMode(MatrixMode.Modelview);
			GL.LoadIdentity();
			
			GL.Color3(1f, 0f, 0f);
			GL.Begin(BeginMode.Lines);
			GL.Vertex2(0, 0);
			GL.Vertex2(150, 100);
			GL.End();
		}		
	}
-- 
View this message in context: http://mono.1490590.n4.nabble.com/MonoMac-and-OpenTK-tp3259455p3259455.html
Sent from the Mono - OSX mailing list archive at Nabble.com.


More information about the Mono-osx mailing list