Selection Buffer problems

Started by
1 comment, last by KShots 17 years, 9 months ago
Hello all... I've been wrestling with this one for... well, way too long (put my project on hold for nearly a year). Anyways, I've been trying to use the OpenGL selection buffer in my application (a model editor for my game engine) and I'm getting some funky results. First, I'll list some sources of information I've been using: 1. RMS "Using the OpenGL Selection Buffer" 2. OpenGL FAQ Ok, now that you have an idea of what I'm trying to do, here's what's going on. I can click directly on an object I'm trying to select (the whole object shares one name). My hits variable comes back as a '1' (meaning there was one hit) (hits = glRenderMode(GL_RENDER)). However, when I browse the selection buffer, it says that there are no objects in the buffer. What gives? I'll go ahead and post some of the code here. The execution would start at "RenderSelectModel" in the code (after a button has been pressed)
void GLViewPort::RenderSelectModel()
{
	StartPicking();
	GLuint Position(0);
	GLuint hitnames [SELECT_BUFSIZE];
	qDebug() << "Select buffer size = " << SELECT_BUFSIZE;
	GLuint hi(0);
	GLuint * bufp = 0;
	GLuint numnames;
	for(MyModels->SetBeginning(); !MyModels->CheckEnd(); (*MyModels)++, Position++)
	{
		/*if(!(Position % SELECT_BUFSIZE))
		{
			if(Position)
			{
				glFlush();
				hits = StopPicking();
				for(unsigned int j = 0; j < hits; j++)
				{
					numnames = *bufp++;
					bufp += 2;
					while(numnames--)
					{
						hitnames[hi++] = *bufp++;
					}
				}
				glRenderMode(GL_SELECT);
			}
			bufp = select_buf;
		}*/
		const TriangleOctree * TT = MyModels->GetConst().GetTTree();
		glPushMatrix();
		const Vector3D * Translation = &MyModels->GetConst().GetTranslation();
		const Vector3D * Rotation = &MyModels->GetConst().GetRotation();
		const Vector3D * Scale = &MyModels->GetConst().GetScale();
		glTranslatef((*Translation)(0), (*Translation)(1), (*Translation)(2));
		glRotatef((*Rotation)(0), (*Rotation)(1), (*Rotation)(2), (*Rotation)(3));
		glScalef((*Scale)(0), (*Scale)(1), (*Scale)(2));
		glLoadName(Position);
		DrawInternalTree(TT);
		glPopMatrix();
	}
	hits = StopPicking();
	bufp = select_buf;
	for(unsigned int j = 0; j < hits; j++)
	{
		numnames = *bufp++;
		bufp += 2;
		while(numnames--)
		{
			hitnames[hi++] = *bufp++;
		}
	}
	// OK, all objects have been drawn, and hits have been noted in the "hitnames" variable. The size of this array is
	// recorded under the variable "hi"
	if(SelectedModel)
	{
		if(!SelectedModel->RemoveLink())
		{
			delete SelectedModel;
		}
	}
	if(hi)
	{
		SelectedModel = MyModels->GetDP(hitnames[0]);
		SelectedModel->AddLink();
	}
	CheckError();
}
SELECT_BUFSIZE = 16, in case anyone was wondering. There is a grand total of one model in my model list. Here's the "StartPicking()" and "StopPicking()" functions:
void GLViewPort::StartPicking()
{
	glSelectBuffer(SELECT_BUFSIZE, select_buf);
	glRenderMode(GL_SELECT);
	glInitNames();
	setupView();
	CheckError();
}

int GLViewPort::StopPicking()
{
	// restoring the original projection matrix
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glFlush();

	CheckError();
	// returning to normal rendering mode
	return glRenderMode(GL_RENDER);
}

void GLViewPort::setupView()
{
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    GLint Viewport[4];
    glGetIntegerv(GL_VIEWPORT, Viewport);
    glLoadIdentity();
    gluPickMatrix((GLdouble)PressX, (GLdouble)(Viewport[3] - PressY), pickRegionSize, pickRegionSize, Viewport);
    gluPerspective(45.0F, GLfloat (Viewport[2]) / Viewport[3], 0.1F, 1000.0F);
    glMatrixMode(GL_MODELVIEW);
    MyCamera.DoCamera();
    CheckError();
}
I'm kinda stuck on this one... anyone see anything blatantly wrong? Thanks
The great pop-tart GAWD of Mt. Kellogs
Advertisement
<bump> Wow, that got buried quick. Anyone ever worked with a selection buffer before? Got better ideas? Thanks
The great pop-tart GAWD of Mt. Kellogs
<Bump>Last try... anyone have any ideas what I'm doing wrong here? Thanks
The great pop-tart GAWD of Mt. Kellogs

This topic is closed to new replies.

Advertisement