Building display lists in a seperate thread

Hello,

I’m trying to put my program’s initialization (loading files, building display lists, creating bounding boxes etc) in a seperate thread so it doesn’t delay showing the user inter interface.

The current code if the init procedure in my main class is as follows:


//Initialization
	public void init(GLAutoDrawable drawable) {
		final GL gl = drawable.getGL();
		OpenGL OGL = new OpenGL();
		
		//Enable openGL
		OGL.EnableOpenGL(gl);
		
		//Initialize everything
		gameloop.Initialize(gl);
		
		//Allow window to react to mouse and keyboard input
		drawable.addMouseListener(this);
		drawable.addMouseMotionListener(this);
		drawable.addKeyListener(this);
	}

I tried changing it to this:


//Initialization
	public void init(GLAutoDrawable drawable) {
		final GL gl = drawable.getGL();
		OpenGL OGL = new OpenGL();
		
		//Enable openGL
		OGL.EnableOpenGL(gl);
		
		//Initialize everything
		new Thread(new Runnable() {
			public void run() {
				gameloop.Initialize(gl);
			}
		}).start();
		
		//Allow window to react to mouse and keyboard input
		drawable.addMouseListener(this);
		drawable.addMouseMotionListener(this);
		drawable.addKeyListener(this);
	}

This resulted in the model not being displayed anymore. Replacing the real contents of gameloop.Initialize with
gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f); revealed that the problem was that is wasn’t building the display lists for the correct gl object. The old version displayed the red background, the threaded version had the blue background defined in EnableOpenGL.

Does anyone know how I can get around this problem?

Thanks in advance,
FalconNL

You should only make GL-calls from 1 thread. You can load files in other threads, and notify the render-thread when all preprocessing is done (like PNG -> RGBA).

So there isn’t really a solution, expect doing all hard work in other threads, and let those communicate with the render-thread, which does the gl-calls.

Maybe this thread is of interest to you.