glLoadName trouble(again)

sorry it took me this long to reply.when i try to load in names for objects it never seems to load in from 3 onwards. all the objects are named 2 apart from the last object which is named 1. any help would be great.

here is my picking code. it is implemented on a mouse click.

if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
{
GLuint selectBuff[BUFSIZE];
GLint hits, viewport[4];

// Select buffer parameters
glSelectBuffer(BUFSIZE, selectBuff);
glGetIntegerv(GL_VIEWPORT, viewport);

// Enter to selection mode

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glRenderMode(GL_SELECT);
glLoadIdentity();
// Set-up pick matrix
gluPickMatrix(x, viewport[3]-y, 0.1,0.1, viewport);

glOrtho(0, 0, 0, 0, 0, 0);

glMatrixMode(GL_MODELVIEW);

// Render all scene and fill selection buffer
display();

hits=glRenderMode(GL_RENDER);

printf ("hits = %d

", hits);

// Get first model, in selection buffer stack
if(hits > 0) 
	picked = selectBuff[3];

glMatrixMode(GL_PROJECTION);

glPopMatrix();
glMatrixMode(GL_MODELVIEW);

}

glOrtho(0, 0, 0, 0, 0, 0);

That is not a valid function call, and will result in an error. This is what the spec says.

void Ortho( double l, double r, double b, double t, double n, double f );

If l is equal to r, b is equal to t, or n is equal to f, the error INVALID_VALUE results.

oh yea,should have known that but i changed it and now call glFrustum(-7, 7, -5, 5, 0, 50); instead but i still get the same problem.

That function call won’t make things any better, cause that too is invalid. Again, taken from the OpenGL spec.

void Frustum( double l, double r, double b, double t, double n, double f );

If either n or f is less than or equal to zero, l is equal to r, b is equal to t, or n is equal to f, the error INVALID VALUE results.

do i need this function call for the purposes of picking or can i leave it out. i dont need it u see for anything else.

I haven’t done any selection yet, but as far as I understand it, you need the same projection matrix as when you render your geometry. That is, if you want to pick is as it’s rendered on the window.

Have you tried the Red Book yet? Check out chapter 13.

its definately something to do with the viewing matrix. when i call glOrtho (0.0, 10.0, 0.0, 10.0, 0.0, 1.0); all the objects get called 1 but when i dont call anything one object is called 1 and the rest 2. any ideas??

When you change the projection matrix, you change what’s being projected onto the viewing plane, and you get different hits.

By the way, when you say all object are called 1, do you mean all object including those who are not supposed to be called 1?

As I said in my previous post, have a look in the Red Book.

yes, only one should be called 1, and the rest 2,3,4,5 etc. would it be anything to do with the depth as when you click on the screen but not on an object you also get a 1.

Gussy get the red book. It’s invaluable for picking. Try http://www.ime.usp.br/~massaro/opengl/redbook/ for the pdf file.

As for your code…

  1. If I am right you’re supposed to call glRenderMode(GL_SELECT) before switching to the projection matrix. All examples I see usually put it immediately after the glSelectBuffer() call.

  2. If this is the same code as posted in your previous thread http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/008062.html use the same projection matrix setup you previously used. I.e. the same call (glOrtho(), glFrustrum() or whatever) used when setting up your projection matrix (usually in the reshape() function).

  3. I don’t think you are processing the hit buffer correctly. Your code…

    hits=glRenderMode(GL_RENDER);
    
    printf ("hits = %d
    

", hits);

   // Get first model, in selection buffer stack
   if(hits > 0) 
   picked = selectBuff[3];

Only processes the first name in the selection buffer. If your objects overlap, its going to be the first object in the picking region that was drawn regardless of how many objects are under the mouse. Worse yet, if you are not using depth buffering the variable picked will show the bottom most object and not the top most object, since later objects will have drawn over the first one.

If your objects overlap you can test for correct results by drawing them side by side then picking them.

[This message has been edited by Furrage (edited 04-05-2002).]