PDA

View Full Version : OpenGL and POSIX threads (or suggestions for loading a screen?)



torisutan
09-21-2003, 03:21 AM
I am working with loading large files into an openGL application, and i was hoping to put together a nice loading screen while the user waits (instead of having windows say the window is not responding :P). So, i downloaded the POSIX threads for Win32 package, and got that running fine. However when i attempted to run an OpenGL application using threads my program failed to work.

program flow went generally like this:

usual window creation, gl context grabbing etc. rendering works fine when called from the message loop. then to add threads, i created an infinite loop in the render function, and created a thread using that function. And everything stoped. the render function did nothing. from what i could figure out, the GL context buggered itself up for some reason, so opengl had nothing to write to.

anyways, has anyone got threads and openGL to behave? (examples appreciated)

or has anyone got any other ideas on how to acheive a loading menu, without having to add calls to the render function all thru the file reading function?

Thanks in advance
--Tristan

zeckensack
09-21-2003, 03:35 AM
I much prefer working without threads.

You can implement an incremental loading function. Say, your loader has a list of tasks to do (list of files, stuff to initialize). So you can initialize a loader with this list of tasks, then make it return after finishing given number of tasks, or after a given amount of time. It would return a bool (or, preferred, a float representation of progress), so that the caller can tell when loading has finished.

You'd then call the loader from within your main loop. As long as loading hasn't finished, you'd load a bit, then render a progress indicator, swap, repeat.
When loading is done, you transition to a different state where you know loading is done (think "runlevel", if that rings a bell).

marcus256
09-21-2003, 09:26 PM
GLFW (an OpenGL toolkit) has a built in threading package that is very similar to the POSIX threading package, and it works very well. I suspect that you have done something wrong in your threading code (there are a few things to consider when writing multi-threaded apps).

My suggestion is that you read the GLFW Users Guide (see the GLFW homepage (http://hem.passagen.se/opengl/glfw/) ), which has a chapter on threading (for the GLFW API, of course, but the problems/solutions are similar for all multi threading environments).


[This message has been edited by marcus256 (edited 09-21-2003).]