Selec Buffer

I know how to use selec buffer stuff but I don’t know how to get names from select buffer variable… can anybody help me?

see the red book or check the faq
also theres examples that come with glut

I apologize in advance is the formatting of the code is all wacky. This code iterates all the hits in the select buffer, then for each hit, retrieves all the names associated with the hit. (You’d have multiple names for a hit if you have hierarchical names, like body/head/left_eyeball/iris.) During the iteration, the name of the nearest element is tracked (hierarchy is ignored here). z1 and z2 are the near and far z values for a given hit. Hope this helps.

// Switch back to render mode (from selection mode)
// and get the number of hits registered in the select buffer.
numHits = glRenderMode(GL_RENDER);

GLint i;
GLuint j, names, *ptr, z1, z2, zmin = 0xFFFFFFFF;
GLuint nElement, nNearestElement = 0;

ptr = (GLuint *) selectBuffer;
for (i = 0; i < numHits; i++) {	// for each hit
	names = *ptr; ptr++;
	z1 = *ptr; ptr++;
	z2 = *ptr; ptr++;
	for (j = 0; j < names; j++) {	// for each name
		nElement = *ptr;
		if (z1 < zmin) {
			zmin = z1;
			nNearestElement = nElement;
		if (z2 < zmin) {
			zmin = z2;
			nNearestElement = nElement;