Share GLXContext

How can I create a share GLContext on Linux using GLUT (freeglut), I have the following code:



GLXContext tmp;
GLuint id;


int main(int argc, char **argv)
{
	XVisualInfo *vi;
	GLint attribs[] = { GLX_RGBA, None };

	glutInit(&argc, argv);
	glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH );

	...
	...

	tmp = glXGetCurrentContext();

	vi = glXChooseVisual( XOpenDisplay(0), DefaultScreen( XOpenDisplay(0) ), attribs );

	tmp = glXCreateContext( XOpenDisplay(0), vi, tmp, GL_TRUE );

	thread_handle = pthread_create( &thread, NULL, callback,(void *)this );

	glutMainLoop();

	return 0;
}


void render(void)
{
	...
	...

	if( id )
	{ glCallList( id ); }

	printf("r:%d
", id);
	...
	...
}


void *callback( void *ptr )
{
	glXMakeCurrent( XOpenDisplay(0), DefaultScreen( XOpenDisplay(0) ), tmp );

	while(1)
	{
		if( !id )
		{
			id = glGenLists(1);

			glNewList( id, GL_COMPILE );
			...
			...
			glEndList();
		}
		printf("c:%d
", id);
	}
}


The problem is that the call with glGenLists will NEVER generate an ID, I tried with textures etc… same results. The code compile find and there’s no crash but no ID’s are generated in the thread, I’ve already check that the pointer enter the thread callback and the render, no problem the prints work but… What Im trying to do is to create a shared context so I can load my resources (textures, lists, vbo, etc…) in another thread and use the main context to draw the main rendering loop.

Any idea of what is wrong?

Tks in advance,

Cheers!

In order to auto reply my question:


#ifdef __linux__

	static Display *dpy = NULL;
	static int scr = 0;

	GLXContext GetCurrentContext( GLvoid )
	{ return glXGetCurrentContext(); }


	GLXContext CreateContext( GLXContext _ctx )
	{
		XVisualInfo *vi;
		XVisualInfo tmp;
		
		int nvis;
		long mask;
		
		dpy = glXGetCurrentDisplay();
		scr = glXGetCurrentDrawable();
		
		vi = XGetVisualInfo( dpy, mask, &tmp, &nvis );
		
		return glXCreateContext( dpy, vi, _ctx, GL_TRUE ); 
	}

	GLvoid SetCurrentContext( GLXContext _ctx )
	{ glXMakeCurrent( dpy, scr, _ctx ); }
	
	
	GLvoid DestroyContext( GLXContext _ctx )
	{ glXDestroyContext( dpy, _ctx ); }
#endif

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.