
<solved>GLControl + thread
Posted Monday, 7 September, 2009 - 11:09 by avogatro inData:
hardware: Geforce8600GT + Athlon X2 5000
OS: Archlinux i686 32 bit
driver: NVIDIA beta 190.18
opentk: 0.9.8.2
mono:
Mono JIT compiler version 2.4.2.3
TLS: __thread
GC: Included Boehm (with typed GC)
SIGSEGV: altstack
Notifications: epoll
Architecture: x86
Disabled: none
HI:
I use GLcontrol to print moving text on a Windows Form(ontop, with fix location).
I use the Application_Idle methode. but the speed is not very constant .
A normal loop without checking "glcontrol.isIdle" is much more smooth.
Without threading, it works.
But I need to run the loop in a thread becauseI I have to be able to kill the the run loop at any time.
public void Run() { long timestamp; long timedelta; bool should_render = false; long delta = 320000; int tempconter = 0 ; while (!this.exiting){ timestamp = Stopwatch.GetTimestamp(); if (last_timestamp == 0){ last_timestamp = Stopwatch.GetTimestamp(); continue; } timedelta = timestamp-last_timestamp; should_render = false; if (timedelta > delta) { posX-=speed; if (posX<=-fontWidth){ posX= this.Width; } timedelta -= delta; should_render = true; } //posX-=tempconter; if (should_render == true) { this.render(); last_timestamp = Stopwatch.GetTimestamp(); } else Thread.Sleep(2); } private void render() { GL.ShadeModel(ShadingModel.Smooth); GL.Enable( EnableCap.DepthTest ); GL.Enable(EnableCap.LineSmooth); GL.ClearDepth(1.0); GL.ClearColor(0.0F,0.0F,0.0F,0.0F); GL.DepthFunc(DepthFunction.Lequal); GL.Hint(HintTarget.PerspectiveCorrectionHint,HintMode.Nicest); GL.Enable(EnableCap.CullFace); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); this.glControl.MakeCurrent(); //GraphicsContext.CurrentContext(). GL.ClearColor(Color.Black); GL.Clear(ClearBufferMask.ColorBufferBit|ClearBufferMask.DepthBufferBit); this.printer.Begin(); this.printer.Print(text, the_font, fontColor, new RectangleF(posX,0,fontWidth,this.Height*0.9F), TextPrinterOptions.Default,TextAlignment.Center); this.printer.End(); this.glControl.SwapBuffers(); } }
the Problem:
function glcontrol.MakeCurrent(), don't work in a thread
Error:
Unhandled Exception: OpenTK.Graphics.GraphicsContextException: Failed to make context current. at OpenTK.Platform.X11.X11GLContext.MakeCurrent (IWindowInfo window) [0x000e3] in /home/moi/Projects/opentk-0.9.8-2/Source/OpenTK/Platform/X11/X11GLContext.cs:219 at OpenTK.Graphics.GraphicsContext.MakeCurrent (IWindowInfo info) [0x00000] in /home/moi/Projects/opentk-0.9.8-2/Source/OpenTK/Graphics/GraphicsContext.cs:387 at OpenTK.GLControl.MakeCurrent () [0x00000] in /home/moi/Projects/opentk-0.9.8-2/Source/OpenTK/GLControl.cs:191 at (wrapper remoting-invoke-with-check) OpenTK.GLControl:MakeCurrent () at RollingText.RollingText.render () [0x00000] in /home/moi/Projects/opentk-0.9.8-2/Fonttest/RollingText.cs:144 at RollingText.RollingText.Run () [0x00087] in /home/moi/Projects/opentk-0.9.8-2/Fonttest/RollingText.cs:238
I checkt the documentation http://www.opentk.com/doc/graphics/graphicscontext :
However function GraphicsContext.MakeCurrent(null, null) don't exist.
so i can't make the context non-current on the main thread.
Can someone help me?


Comments
Re: GLControl + thread
If this method doesn't exist, this is a bug (and a serious one at that).
Edit: clarified the documentation,
MakeCurrent()is an instance method.Re: GLControl + thread
well
this.glControl.Context.MakeCurrent(null,null);[Task:File=/home/moi/Projects/opentk-0.9.8-2/Fonttest/RollingText.cs, Line=73, Column=36, Type=Error, Priority=Normal, Description=No overload for method `MakeCurrent' takes `2' arguments(CS1501)]
Re: GLControl + thread
Ok, this is a documentation bug (edit: fixed), try with a single argument:
Re: GLControl + thread
OpenTK.Platform.IWindowInfo as null ...
error
Re: GLControl + thread
Tracking as issue #1154: IGraphicsContext.MakeCurrent(null) throws NullReferenceException on X11 implementation.
Re: GLControl + thread
This code works as expected in 0.9.9-2b. Please upgrade to this version of OpenTK.
Re: GLControl + thread
How can I do something like this:
I need extra Thread, but i can't use the function glControl.context.makeCurrent();
error:
Re: GLControl + thread
This code should work correctly in OpenTK 0.9.9-2 and higher.
However, you should disconnect the Application_Idle handler prior to launching the new thread:
Otherwise you will launch a new thread every time Application.Idle is raised (not good!)
Re: GLControl + thread
I did what you say:
0.9.9.2b
I deactivatet the textprinter.
so it's now just a winform under X11,
with a main loop in a thread.
this is the error, maybe the stack helps:
Re: GLControl + thread
I'm looking into the issue.