Code:
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glColor3f(1.0f,1.0f,1.0f); // Set The Color To White
glDisable(GL_CULL_FACE); // Disable culling.
(*currentCam).draw();
glBindTexture(GL_TEXTURE_2D, texture[2]); // Map Texture to the Box
// Draw the Room ie Crate
glBegin(GL_QUADS);
// Front Face
glNormal3f( 0.0f, 0.0f, 9.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-9.0f, -5.0f, 9.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 9.0f, -5.0f, 9.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 9.0f, 5.0f, 9.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-9.0f, 5.0f, 9.0f);
// Back Face
glNormal3f( 0.0f, 0.0f,-9.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-9.0f, -5.0f, -9.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-9.0f, 5.0f, -9.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 9.0f, 5.0f, -9.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 9.0f, -5.0f, -9.0f);
// Top Face
glNormal3f( 0.0f, 9.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-9.0f, 5.0f, -9.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-9.0f, 5.0f, 9.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 9.0f, 5.0f, 9.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 9.0f, 5.0f, -9.0f);
// Bottom Face
glNormal3f( 0.0f,-9.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-9.0f, -5.0f, -9.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 9.0f, -5.0f, -9.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 9.0f, -5.0f, 9.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-9.0f, -5.0f, 9.0f);
// Right face
glNormal3f( 9.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 9.0f, -5.0f, -9.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 9.0f, 5.0f, -9.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 9.0f, 5.0f, 9.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 9.0f, -5.0f, 9.0f);
// Left Face
glNormal3f(-9.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-9.0f, -5.0f, -9.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-9.0f, -5.0f, 9.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-9.0f, 5.0f, 9.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-9.0f, 5.0f, -9.0f);
glEnd();
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW); // Enable counter clockwise culling.
glLoadIdentity();
funzo+=.1f;
boxer.rot(funzo, 0.0f, funzo);
lister.drawObjects(currentCam); // Draw the linked list of objects
glLoadIdentity();
return TRUE; // Keep Going
}
Then, the drawObjects code is:
Code:
Object *getSelectedObject(GLint x, GLint y)
{
Object *temp=NULL; // Will hold the selected object
GLuint select[98]; // Will hold the selection buffer.
GLint viewport[4]; // Will hold the viewport.
GLint clickTest; // Will store the click test.
int objectSelected; // This will store the ID of the selected object.
glDisable( GL_LIGHTING );
glSelectBuffer(512, select);
// Place the viewport in the array viewport.
glGetIntegerv(GL_VIEWPORT, viewport);
glMatrixMode(GL_PROJECTION); // Change to the projection matrix.
glInitNames(); // Set up the names for selection
glPushName(0); // Push 0 onto the stack
glPushMatrix();
// Change the render mode to GL_SELECT.
glRenderMode(GL_SELECT);
glLoadIdentity();
// Here we place the view volume around the mouse pointer. This will
// allow us to know if there is anything under the mouse.
gluPickMatrix(x, viewport[3] - y, 2, 2, viewport);
gluPerspective(45.0f,(GLfloat)windowWidth/(GLfloat)windowHeight,NEAR_CLIP,FAR_CLIP);
DrawGLScene(); // Draw the objects..
clickTest = glRenderMode(GL_RENDER); // Test if a object was clicked.
// If a hit occured, display the info.
if(clickTest > 0)
{
// Get the ID of the object that was selected from the bottom of the stack.
objectSelected = select[3];
logg("**Hit on object " + objectSelected);
// Now we have the objectID that was selected, so return it
temp=lister.getItem(objectSelected);
}
else
logg("Didn't hit an object!");
glMatrixMode(GL_PROJECTION); // Change to the projection matrix.
glPopMatrix();
glMatrixMode(GL_MODELVIEW); // Change to modelview matrix.
glEnable(GL_LIGHTING);
return temp;
}
Every time I send it getSelectedObject(windowWidth/2,windowHeight/2), I get no hit, even if an object on the list is blocking the whole viewport.