PDA

View Full Version : Selection objects via mouse is driven me crazy



Sickboy
11-25-2003, 01:15 AM
Hi guys.
I try to get the code to work, but i don´t see why it doesn´t work. The function will be called by "OnMouseClick" in MFC and receive X and Y Pos of the Mouse which are ok.

Please don´t send me any tutorial links. I got enough and thought that i understand them http://www.opengl.org/discussion_boards/ubb/smile.gif

void COpenGL::select_object(int xPos, int yPos)
{

GLuint buffer[BUFFER_LENGTH];
GLint hits, viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport); // Get the viewport
glSelectBuffer(BUFFER_LENGTH,buffer); // buffer muss für jedes Object das ausgewählt wird 4 byte bereitstellen
(void) glRenderMode(GL_SELECT); // Change render mode

glInitNames();
glPushName(0);

glMatrixMode(GL_PROJECTION); // Switch to projection and save the matrix
glPushMatrix();
glLoadIdentity();

gluPickMatrix( (GLdouble) xPos,(GLdouble) (viewport[3] - yPos),5,5,viewport);
// TEST ***************************
glLoadName (0);
glPushName (1);
glColor3f (0.0, 1.0, 1.0);
glRectf ( 0.0, 0.0, 1.0, 1.0);
glPopName ();
glPushName (2);
glColor3f (1.0, 0.0, 1.0);
glRectf ( -1.0, -1.0, 0.0, 0.0);
glPopName ();
// TEST END ***********************

glMatrixMode(GL_PROJECTION); // Restore the projection matrix
glPopMatrix();
glFlush();

hits = glRenderMode(GL_RENDER);
if (hits > 0) TRACE("HIT FOUND\n");
}

Thx in advance
daSickboy

Sickboy
11-25-2003, 01:52 AM
I think i can specify my problem.
When i trace the viewport array i get
values about: -858993460 for all 4 entries

how can this happen when i write:
glGetIntegerv(GL_VIEWPORT, viewport);
TRACE("viewport =%i, %i, %i, %i\n",viewport[0],viewport[1],viewport[2],viewport[3]);

Do i need to create a viewport ?
And how ?

Please help
daSickboy

Deiussum
11-25-2003, 05:33 AM
Not sure of your problem, but here are some things to try:

Make sure you've got a valid rendering context. I'm assuming you do or you wouldn't be seeing anything drawn Make sure you are setting your viewport in your resize function with glViewport. It seems strange that glGetInteger would return the values you are seeing. Alternately, you could just save the viewport settings on your own in the resize rather than getting them with glGetInteger Make sure that what you are drawing in the selection buffer has the same transformations as what you are drawing in the scene.

Sickboy
11-25-2003, 06:30 AM
I forgot the rendering content.
Thx
daSickboy