OpenGL is not thread safe. I understand that (or maybe not). I have heard that all OpenGL calls have to be made in the original thread. I don't understand why that would be. It seems to me that as long as you don't call multiple OpenGL calls simultaneously, that it would work. However, by observation, it seems that it is true. I still don't understand why, though.
Here is a simple application that seems, to me, like it should work. But it segfaults.
Code:
// Compile this program with "gcc -o tmp tmp.c `sdl-config --libs` -lGL"
#include "SDL/SDL.h"
#include "SDL/SDL_thread.h"
#include "GL/gl.h"
#include <unistd.h>
int my_thread(void * data) {
glGetString(GL_VERSION );
}
int main(int argc, char ** argv) {
SDL_Init(SDL_INIT_VIDEO);
SDL_SetVideoMode(320, 240, 32, SDL_OPENGL);
SDL_Thread * test = SDL_CreateThread(my_thread, NULL);
SDL_WaitThread(test, NULL);
SDL_Quit();
return 0;
}
Can someone explain why this program segfaults? Is there a simple way to fix it? Is there any way at all that opengl calls can be made in non-primary threads?