<div>Hi Alex, </div><div><br></div>You context is not shared between threads as its indicated in the error. This is nothing new and you can find lot more information if you google for <div><br></div><div>"OpenGL share context between threads" </div>
<div><br></div><div>It works in second case because Qt is doing the job of signalling the function in other thread in thread safe manner. </div><div><br></div><div>But looking at your sample code, I am not sure what kind of interaction issues you are having... </div>
<div><br></div><div>Do you really need two threads? If you do (as I guess you might be loading data in one and displaying in other), there could be ways around it.. </div><div><br></div><div>May be this link helps giving you more insight: </div>
<div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><a href="http://hacksoflife.blogspot.com/2009/08/creating-opengl-textures-or-vbos-on.html">http://hacksoflife.blogspot.com/2009/08/creating-opengl-textures-or-vbos-on.html</a> </div>
<div><br></div><div><br></div><div><br><div class="gmail_quote">On Tue, Dec 14, 2010 at 8:45 AM, Alex Southern <span dir="ltr"><<a href="mailto:mrapsouthern@gmail.com">mrapsouthern@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br>
<br>
Im running a QThread event loop and trying to execute a vtkInteractorWindow->Render() command after each iteration. I have tried two approaches so far but neither work well.<br>
<br>
The First approach, gives a VTK error and is based on something like this:<br>
At the initialization stage I pass a pointer to iren. Then in the run() function I execute iren->Render();<br>
<br>
class myThread : public QThread<br>
{<br>
Q_OBJECT<br>
<br>
public:<br>
vtkRenderWindowInteractor *iren;<br>
void run();<br>
{<br>
for (int i = 0; i < 2000; i++)<br>
{<br>
// process some data<br>
iren->Render();<br>
}<br>
}<br>
};<br>
<br>
This compiles but gives the error in the vtkOutputWindow on each call of Render()....<br>
<br>
ERROR: In ..\..\Source\VTKGit\Rendering\vtkWin32OpenGLRenderWindow.cxx, line 247<br>
vtkWin32OpenGLRenderWindow (05153168): wglMakeCurrent failed in MakeCurrent(), error: The requested resource is in use.<br>
<br>
The second approach gives no errors, but results in a very jerky interaction. It is implemented by emitting a signal from the for loop after every iteration. The threads myRender() signal is connected to a updateRenderWindow() slot function i.e.<br>
<br>
class myThread : public QThread<br>
{<br>
Q_OBJECT<br>
<br>
public:<br>
void run()<br>
{<br>
for (int i = 0; i < 2000; i++)<br>
{<br>
// process some data<br>
emit myRender();<br>
}<br>
}<br>
signals:<br>
void myRender();<br>
};<br>
<br>
class myWindow : public QMainWindow<br>
{<br>
Q_OBJECT<br>
<br>
public:<br>
myThread Td;<br>
vtkRenderWindowInteractor *iren;<br>
<br>
public slots:<br>
void updateRenderWindow()<br>
{<br>
iren->Render();<br>
}<br>
}<br>
<br>
<br>
Does anyone have any suggestions as to how I can improve either of these methods to give a better interaction?<br>
<br>
Thanks<br>
Alex<br>
<br>
<br>
<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>| Aashish Chaudhary <br>| R&D Engineer <br>| Kitware Inc. <br>| <a href="http://www.kitware.com">www.kitware.com</a> <br>
</div>