OGL and Pthreads on OSX

Started by
-1 comments, last by KernelSanders 15 years, 10 months ago
I can't get anything with opengl to play nice with pthreads. I've searched the forum and from what I've seen opengl is fine with threads as long as only one uses it at a time. To test it out I took the hello world program from the Red Book and threw it into a second thread. Here is my main/gl_main functions.
int main(int argc, char **argv){
	
	g_argc = &argc; g_argv = argv;
	pthread_t thread;
	pthread_create(&thread, NULL, &gl_main, NULL);
		
	char c;
	printf("Will exit if you enter a char\n");	scanf("%c", &c);
}

void *gl_main(void *arg){	
	glutInit(g_argc, g_argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(250, 250);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("Hello, world");
	init();
	glutDisplayFunc(display);
	glutMainLoop();
	return NULL;
}
g_argc/v are global vars to hold argc/v and gl_main is identical to the hello world's main function except it is declared as returning void * with a void * argument. The other methods are identical to the Red book (I can post them if needed). When I run the program all I get is an empty white box (no titlebar, no contents). The program takes ~100% CPU time, and stops responding after a few seconds (still loads the CPU). Simple debugging tells me glutMainLoop gets called, it just doesn't seem to do anything. If I nix the second thread and call gl_main directly everything works fine. What's going wrong?

This topic is closed to new replies.

Advertisement