Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Selection problem

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2006
    Posts
    8

    Selection problem

    Hi, I'm having a problem when I try to use the select function. I always get hits=0, it doesn't matter where I click. Here's the code, but it has changed several times.Originally I followed the tutorial in the Red book and several other places,but after that I have changed the code several times. Here's the latest version:
    Code :
    void MainWindow::selectElement()
        {
            GLuint select_buf[SELECT_BUFSIZE]; 
            GLuint hits;
            GLint viewport[4];
     
            glGetIntegerv (GL_VIEWPORT, viewport); 
     
            glSelectBuffer(SELECT_BUFSIZE, select_buf);
            glRenderMode(GL_SELECT);
            glInitNames();
            glPushName(-1);
    int height, width;
           height=w->height();
            width=w->width();
     
            gluPickMatrix((GLdouble)mouseX, 
                     (GLdouble)viewport[3]-mouseY, 
                    5.0, 5.0, 
                     viewport);
     
            glMatrixMode(GL_PROJECTION);
            glPushMatrix();
            glLoadIdentity();
            GLfloat x= (GLfloat) width/height;
           glFrustum(-x,x,-1.0,1.0,1.0,1.0);
            glMatrixMode(GL_MODELVIEW);
            for(int i = 0; i < spisyk.size(); i++){
            glLoadName(i);
            spisyk[i]->draw();
            }
     
     
           glPopMatrix();
           glFlush(); 
            hits = glRenderMode(GL_RENDER); 
     
            GLuint hitnames[256];
            unsigned int hi = 0;
            GLuint name, numnames, z1, z2,j=0;;
     
            if (hits>0)
     
                {
     
            numnames = select_buf[j++];
            z1 = select_buf[j++];
            z2 = select_buf[j++];
            int i=0;
            while(i<numnames)
            {
                hitnames[i]=select_buf[j];
                cout << hitnames[i]<< endl;
                i++;
            }
     
            }
     
            cout << hits << "  hitа  "<< endl;
        }
    Any help will be greatly appreciated.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,SkƄne,Sweden
    Posts
    1,651

    Re: Selection problem

    You call gluPickMatrix(...) before you call glMatrixMode( GL_PROJECTION) and that looks a bit odd to me.

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2006
    Posts
    8

    Re: Selection problem

    Thanks, it works now

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Selection problem

    You also push the projection matrix but pop the modelview matrix.
    If you had added glGetError during debugging you should have received stack underflow errors immediately and overflow errors after you called this more often than the projection matrix stack size which is rather small.

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2006
    Posts
    8

    Re: Selection problem

    Thanks again !
    I'm quite new to OpenGL and didn't even know about the glGetError.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •