OpenGL doesn't work when using threads?

Started by
6 comments, last by Cone83 21 years, 11 months ago
Everything worked fine in my game until i decidet to use multible threads (but it is an OpenGL problem, I think). I created a seperat thread to load my textures to be able to print status informations while loading (didn''t work otherwise). Now the strange problem: Sometimes (ca. every 10th start) one texture, or sometimes even more, aren''t loadet. If I bind them it produces the same result like binding the ID 0. The even bigger problem: gluBuild2DMipmaps normally returns 0 for all textures. So there is no way to detect if a texture is loadet correcty (and retry it). Does anybody has some idears? btw.: If I call the function for loading the textures normally, and not with pthread_create (yes, I''m a linux programmer) everything works fine. So it must be a thread problem.
Advertisement
OpenGL is not thread-safe. If you want to use OpenGL in a multithreaded app, you must make sure that all GL calls are in the same thread.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
1GB+ of documentation.... wglMakeCurrent explicitly explains how to use OpenGL in a multi-threaded application....

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
@jenova: Maybe nothing is more troublesome than the offort of reading to most people! If you had read my article you would know that I''m NOT programming for windows. So I have no use for your wgl* functions and msdn.microsoft.com.
Thanx, it seems to work now. I created a global bool variable, which is true, if an other OpenGL function is processing. If so, the thread waits for it to change.
most wgl functions have a counter part in the glx system, this is one of them, a quick google would have shown this up

http://www.cevis.uni-bremen.de/~uwe/opengl/glXMakeCurrent.html

so, before you go slating someone for pointing you in the right direction, which he did, try considering that kinda thing.
Also - nowhere in your post does it say that you aren''t using windows. The closest thing is when you say your a Linux programmer. Which does not automatically mean it aint a windows app.

Landsknecht
My sig used to be, "God was my co-pilot but we crashed in the mountains and I had to eat him..."
But folks whinned and I had to change it.
You should only have to protect shared resources by a mutex. This program tests if your OpenGL implementation is thread-safe
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/mesa3d/Mesa/xdemos/glthreads.c?rev=1.2

This topic is closed to new replies.

Advertisement