PDA

View Full Version : Glut and multi threading



SED
10-18-2000, 01:11 PM
Has anyone coded a worker thread using Glut under Windoze? I've just recently got into threads. Ive done a few with MFC using AfxBeginThread() and the WIN32 API using _beginthread(), _endthread(). Its by far the best way Ive tried to do animations.

Someone posted on rendering material removeal using csg. I fooled around with it a bit last night, using Glut. I used the Idle func to do the animations, but of course, this just eats up the processor time and the gui is dead while the tool is animating.

I'm trying to use _beginthread() _endthread(), found in processes.h, with Glut. The thread does execute and terminate as it should. The problem is, my screen doesnt refresh. My render callback *does* get called, but nothing moves.

I know the Interpolation code is good, because I had it working, but I was calling it from my glutIdleFunc(), not using a worker thread.

Heres the code if anyone has a multi threaded bent, and can give me a suggestion http://www.opengl.org/discussion_boards/ubb/smile.gif http://personal.lig.bellsouth.net/lig/s/_/s_dolan/CppSource/cnc_csg.cpp

Sean

BTW I tried passing a pointer to a struct to the thread as well, same results.

genglish
10-20-2000, 08:11 AM
I don't think the rendering context can be shared between threads. What you need to do is use the second thread for only the math and the first thread to render the results. Either that or ditch GLUT and set up your context in the second thread manually.

Good luck

SED
10-23-2000, 09:38 PM
I played around with this, trying to figure it out.. Would this not be okeeday to use with Glut?

struct threadStuff
{
bool closing;
bool busy;
void (*Render)();
HWND hwnd;
}tS;

VOID Interpolate(PVOID pVoid)
{
threadStuff* ptS = (threadStuff*)pVoid;

for(//iterate)
{
//Do parsing & math stuff
ptS->Render();
InvalidateRect(ptS->hwnd, NULL, FALSE);
if (ptS->closing)
break;
}

ptS->busy = false;
cout << "Exiting thread" << endl;
_endthread();
}

void Menu(int index)
{
if (!tS.busy)
{
tS.hwnd = GetActiveWindow();
tS.Render = RenderMain;
cout << "Starting thread" << endl;
tS.busy = true;
_beginthread(Interpolate, 0, &tS);
}
}

Of course I took alot of stuff out, error checking, early exit stuff etc.
Its not caused me any problems.

Sean