Selection buffer

Hi, I’m about to go mad because of this fu…ing selection buffer. I started a project just when I was learning the beginnings of OpenGL (two months ago or so) and used an orthographic projection. I use the resize code directly from the superbible like this:
void ChangeSize(int w, int h)
{
GLfloat nRange = 300.0f;
// Prevent a divide by zero
if(h == 0)
h = 1;
fAspect = (GLfloat)w/(GLfloat)h;

// Set Viewport to window dimensions
glViewport(0, 0, w, h);

// Reset coordinate system
glMatrixMode(GL_PROJECTION);

So far so good, but know I’m trieing to use selection mode and it is just…
my process function looks like this, but somehow it just doesn’t work. The Quad I’m trieing to hit is in the upper right corner, but whenever I hit the mousebutton in the negativ y plane, really just somewhere there the selection buffer regesters this as a call. Here is my process code:
void ChangeSize(int w, int h)
{
GLfloat nRange = 300.0f;
// Prevent a divide by zero
if(h == 0)
h = 1;
fAspect = (GLfloat)w/(GLfloat)h;

// Set Viewport to window dimensions
glViewport(0, 0, w, h);

// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if (w <= h) 
	glOrtho (-300, 300, -300*h/w, 300*h/w, -300*2.0f, 300*2.0f);
else 
	glOrtho (-300*w/h, 300*w/h, -300, 300, -300*2.0f, 300*2.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

PLEASE HELP ME A DUMB NEWBIE!!!
glLoadIdentity();

if (w <= h) 
	glOrtho (-300, 300, -300*h/w, 300*h/w, -300*2.0f, 300*2.0f);
else 
	glOrtho (-300*w/h, 300*w/h, -300, 300, -300*2.0f, 300*2.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

Sorry, somehow I mixed it all up pasting the code and so on. OK here is the right question:

Hi, I’m about to go because of this fu…ing selection buffer. I started a project just when I was learning the beginnings of OpenGL (two months ago or so) and used an orthographic projection. I use the resize code directly from the superbible like this:
void ChangeSize(int w, int h)
{
GLfloat nRange = 300.0f;
// Prevent a divide by zero
if(h == 0)
h = 1;
fAspect = (GLfloat)w/(GLfloat)h;

// Set Viewport to window dimensions
glViewport(0, 0, w, h);

// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if (w <= h) 
	glOrtho (-300, 300, -300*h/w, 300*h/w, -300*2.0f, 300*2.0f);
else 
	glOrtho (-300*w/h, 300*w/h, -300, 300, -300*2.0f, 300*2.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

So far so good, but know I’m trying to use selection mode and it is just…
my process function looks like this, but somehow it just doesn’t work. The Quad I’m trying to hit is in the upper right corner, but whenever I hit the mousebutton in the negativ y plane, really just somewhere there the selection buffer regesters this as a call. Here is my process code:

#define BUFFER_LENGTH 64
void ProcessSelection(int xPos, int yPos)
{
GLuint selectBuff[BUFFER_LENGTH]; // Space for selection buffer
GLint hits, viewport[4]; // Hit counter and viewport storeage
glSelectBuffer(BUFFER_LENGTH, selectBuff); // Setup selection buffer
glGetIntegerv(GL_VIEWPORT, viewport); // Get the viewport
glMatrixMode(GL_PROJECTION); // Switch to projection and save the matrix
glPushMatrix();
glRenderMode(GL_SELECT); // Change render mode

// Establish new clipping volume to be unit cube around
// mouse cursor point (xPos, yPos) and extending two pixels
// in the vertical and horzontal direction
glLoadIdentity();
gluPickMatrix(xPos, viewport[3] - yPos, 20,20, viewport);
gluPerspective(90.0f, 600, 1.0, 0.0);	// Apply perspective matrix
RenderScene();	// Draw the scene
hits = glRenderMode(GL_RENDER);	// Collect the hits
if(hits == 1)	// If a single hit occured, display the info.
	ProcessPlanet(selectBuff[0]);

glMatrixMode(GL_PROJECTION);	// Restore the projection matrix
glPopMatrix();
glMatrixMode(GL_MODELVIEW);	// Go back to modelview for normal rendering

}

PLEASE HELP ME A DUMB NEWBIE!!!

My first thought is that the projection matrix that you’re using for selection, doesn’t match the projection matrix you are using when you’re not selecting. At looks like you are using the glOrtho function to setup your projection matrix in the resize event and when you are selecting you are using gluPerspective.

Also, try commenting out the glRenderMode(GL_SELECT) line. This should allow you to view what the scene looks like while you are picking. It is possible it is not what you expect.

[This message has been edited by Pat (edited 08-01-2001).]