My selection doesnt work if i change Matrix Mode

Does somebody know how could i make work again ? I need to change Matrix Mode

Hi !

Check your code, you can change the matrix mode when you want, just make sure you reset the matrices before you change them and so on (glLoadIdentity), also make sure you don’t mess up with gluPickMatrix if you are using it, it has to placed so you don’t modify the wrong matrix.

Mikael

thats the code, i reset the matrix(glLoadIdentity), than i move camera by (glTranslatef and glRotatef) than i draw the panel(following source code) and than glInitNames();
glPushName(0);
glLoadName(10);
some next drawing
/--------------------------------------
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,100,0,500,-100,100);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
//–
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,100,1);
glVertex3f(100,100,1);
glVertex3f(100,0,1);
glVertex3f(0,0,1);
glEnd();
//–
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

it still doesnt work

I had a problem implementing “Picking” in my OpenGL App as well. Here’s a copy of my procedure that responds to the mouse click in my Application.

procedure ProcessPick(xPos, yPos : Integer);
var
SelectionBuffer: array[0…512] of GLUint;
Hits : GLint;
ViewPort: TVector4i;
begin
// Get the current Viewport info
glGetIntegerv(GL_VIEWPORT, @Viewport);

// Assign a selection buffer and switch to selection mode.
glSelectBuffer(512, @SelectionBuffer);
glRenderMode(GL_SELECT);

// Initialize the Name stack and set it to 0
glInitNames;
glPushName(0);

// Switch to Projection view and Save the Modelview matrix, then reset the matrix
glMatrixMode(GL_PROJECTION);
glPushMatrix;
glLoadIdentity;

// Translate the viewing volume to 1x1 pixels at the current location
gluPickMatrix(xPos, Viewport[3]- yPos, 1, 1, Viewport);

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0,
             (Viewport[2]-Viewport[0])/(Viewport[3] - Viewport[1]),
             0.1,100.0);

// Switch to Model view and draw the scene
glMatrixMode(GL_MODELVIEW);
DrawToScreen(GL_SELECT);

// Switch back to Projection view and restore the Model matrix
glMatrixMode(GL_PROJECTION);
glPopMatrix();

// Switch back to Model view so that drawing can continue
glMatrixMode(GL_MODELVIEW);

// Switch back to Render mode and get the number of hits (Objects under cursor)
Hits := glRenderMode(GL_RENDER);

// If there was a hit
if Hits > 0 then
begin
// Tell the object its been selected (hit)
if SelectionBuffer[3] = Donut.ID then
Donut.Hit := not Donut.Hit;
end;

end;

Hopes this helps.

The selection works, it doesnt work just when i draw the following source code (exactly just when i change matrix mode)
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,100,0,500,-100,100);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
//–
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(0,100,1);
glVertex3f(100,100,1);
glVertex3f(100,0,1);
glVertex3f(0,0,1);
glEnd();
//–
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();