Sign in to follow this  

Picking - Correct number of hits returned, but selection buffer is garbage

This topic is 3372 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

Hi, I'm trying to implement picking (in an Ortho view). I've got to the point where the correct number of hits are being returned by glRenderMode(GL_RENDER), but the selection buffer is either full of 0's or garbage. I'm using (four) wxWidgets' wxGLCanvas for my drawing. Picking stuffs:
unsigned int SelectionBuffer[4096] = {0};
			GLuint NumHits = 0;
			GLint Viewport[4];

			glSelectBuffer(4096, SelectionBuffer);
			glGetIntegerv(GL_VIEWPORT, Viewport);
			glRenderMode(GL_SELECT);
			glInitNames();
			glPushName(0);

			glMatrixMode(GL_PROJECTION);
			glPushMatrix();
				glLoadIdentity();
				
				gluPickMatrix(X, Viewport[3] - Y, 5, 5, Viewport);

				if(Type == VIEW_PERSPECTIVE)
				{
					float ratio_w_h = (float)GetWidth()/(float)GetHeight();
					gluPerspective(45, ratio_w_h, 0.1f, 1000.0f);
				} else glOrtho(-Zoom, Zoom, -Zoom * (float)GetHeight() / (float)GetWidth(), Zoom * (float)GetHeight() / (float)GetWidth(), -Zoom, Zoom);

				glMatrixMode(GL_MODELVIEW);

				CurrentGizmo.Render();

				NumHits = glRenderMode(GL_RENDER);

				//Back to normal rendering mode
				glMatrixMode(GL_PROJECTION);
			glPopMatrix();

			//Collect first name
			unsigned int Result = 0;
			cout << "NumHits: " << NumHits << "\n";
			if(NumHits > 0)
			{
				Result = SelectionBuffer[7];
			}

			cout << "Result: " << Result << "\n";

Rendering my Gizmo:
void Gizmo::Render()
{
	glMultMatrixf(GetMatrix().GetAsFloatArray());

	//Get axis
	SYM::SYM_VECTOR3 AxisX = GetMatrix().RotateVector(SYM::SYM_VECTOR3(Length, 0.0f, 0.0f));
	SYM::SYM_VECTOR3 AxisY = GetMatrix().RotateVector(SYM::SYM_VECTOR3(0.0f, Length, 0.0f));
	SYM::SYM_VECTOR3 AxisZ = GetMatrix().RotateVector(SYM::SYM_VECTOR3(0.0f, 0.0f, Length));

	glLineWidth(2.0f);

	switch(Mode)
	{
		case GIZMO_TRANSLATE:

			glDisable(GL_DEPTH_TEST);
			glBegin(GL_LINES);
			
				glColor3ub(ColourX.r, ColourX.g, ColourX.b);
				glLoadName(GIZMO_X);
				glVertex3f(0.0f, 0.0f, 0.0f);
				glVertex3f(AxisX.x, AxisX.y, AxisX.z);

				glColor3ub(ColourY.r, ColourY.g, ColourY.b);
				glLoadName(GIZMO_Y);
				glVertex3f(0.0f, 0.0f, 0.0f);
				glVertex3f(AxisY.x, AxisY.y, AxisY.z);

				glColor3ub(ColourZ.r, ColourZ.g, ColourZ.b);
				glLoadName(GIZMO_Z);
				glVertex3f(0.0f, 0.0f, 0.0f);
				glVertex3f(AxisZ.x, AxisZ.y, AxisZ.z);

			glEnd();
			glEnable(GL_DEPTH_TEST);
			break;

		case GIZMO_ROTATE:
			break;
	}

	glLineWidth(1.0f);
	glColor3ub(0, 0, 0);
}

I've Googled around for common problems: I push a blank name to the stack before using the gLoadName() business, the selection buffer size is reasonable (else I'd get -1 for NumHits), and I've tried commenting out glRenderMode(GL_SELECT) so I can "see what the Pick Matrix sees", and all is well. SelectionBuffer is usually all 0's, occasionally there's some garbage in there after some playing around. As far as I understand, getting the name is as simple as SelectionBuffer[HitNum * 4 + 3], so ignoring the blank push I use 7 in the above code to retrieve the first useful name. Thanks in advance for any suggestions.

Share this post


Link to post
Share on other sites

This topic is 3372 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this