Advertisement Jump to content
Sign in to follow this  

OpenGL OGL and Pthreads on OSX

This topic is 3861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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");
	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?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!