Results 1 to 10 of 10

Thread: glLoadName trouble(again)

  1. #1
    Guest

    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\n", hits);

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

    glMatrixMode(GL_PROJECTION);

    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    }

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: glLoadName trouble(again)

    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.

  3. #3
    Guest

    Re: glLoadName trouble(again)

    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.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: glLoadName trouble(again)

    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.

  5. #5
    Guest

    Re: glLoadName trouble(again)

    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.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: glLoadName trouble(again)

    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.

  7. #7
    Guest

    Re: glLoadName trouble(again)

    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??

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: glLoadName trouble(again)

    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.

  9. #9
    Guest

    Re: glLoadName trouble(again)

    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.

  10. #10
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    282

    Re: glLoadName trouble(again)

    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_boa...ML/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\n", 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).]

Similar Threads

  1. glLoadName() - Help
    By BGwra in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-17-2010, 06:23 AM
  2. glPushName vs glLoadName
    By David Doria in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 11-08-2008, 12:35 PM
  3. hit record an glLoadName()
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-13-2005, 06:02 PM
  4. glLoadName trouble
    By in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-04-2002, 08:11 AM
  5. glLoadName.. is there a limit
    By mohsin in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 03-01-2001, 09:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean