Problem with selecting object

Hello,

I bought OpenGL Superbible 3rd edition and I am turning all the examples from C into Java. So far I was successful. I turned all examples to chapter 12 except those from chapter using NURBS. :-[
Chapter 12 is about discovering which object is on position where mouse is clicked. My problem is in gluPickMatrix () method which should describe the new viewing volume. Here’s the code.

private void processSelection (int xPos, int yPos)
	{
		GLU glu = new GLU ();
		double aspect;
		
		// Hit counter and viewport storage
		int hits, viewport [] = new int [4];
		
		// Setup selection buffer
		globalGL.glSelectBuffer (BUFFER_LENGTH, selectBuff);
		
		// Get the viewport
		globalGL.glGetIntegerv (GL.GL_VIEWPORT, viewport, 0);
		
		// Switch to projection and save the matrix
		globalGL.glMatrixMode (GL.GL_PROJECTION);
		globalGL.glPushMatrix ();
		
		// Change render mode
		globalGL.glRenderMode (GL.GL_SELECT);
		
		/*
		 * Establish new clipping volume to be unit cube around
		 * mouse cursor point (xPos, yPos) and extending two pixels
		 * in the vertical and horizontal directon
		 */
		globalGL.glLoadIdentity ();
		[b]glu.gluPickMatrix (xPos, viewport [3] - yPos, 2, 2, viewport, 0);[/b]
		
		// Apply perspective matrix
		aspect = (double) viewport [2] / viewport [3];
		glu.gluPerspective (45, aspect, 1, 425);
		
		// Draw the scene
		renderScene (globalGL);
		
		// Collect the hits
		hits = globalGL.glRenderMode (GL.GL_RENDER);
		
		// If a single hit occured, display the info.
		if (hits == 1)
			processPlanet (selectBuff.get (3));
		else
			glut.glutSetWindowTitle ("Nothing was clicked on!");
		
		// Restore the projection matrix
		globalGL.glMatrixMode (GL.GL_PROJECTION);
		globalGL.glPopMatrix ();
		
		// Go back to modelview for normal rendering
		globalGL.glMatrixMode (GL.GL_MODELVIEW);
	}

It throws: " javax.media.opengl.GLException: No OpenGL context current on this thread"

Can someone tell me where I do it wrong? Or if it isn’t posible this way how to pick object drawn at scene?

Thanks.

You have to do gl/glu operations when the gl context is being current. Best way is to do it at the next display() invocation. Se the following related thread for more information: http://www.java-gaming.org/forums/index.php?topic=12475.msg99927#msg99927

Thank you!!! It’s working. Finally, I can get on with it. ;D

BTW If someone is interested in Java code for OpenGL SuperBible 3rd edition, feel free to send me PM and I can give it to you.