Results 1 to 2 of 2

Thread: [Picking] hit-value returning all Objects

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2006
    Location
    Germany
    Posts
    3

    [Picking] hit-value returning all Objects

    I cant get picking working in my application. The Hit-Value returns all Objects on screen.
    Here some excerpts from my code:

    Code :
     void OglCode::draw(){
     
    glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);	
    glLoadIdentity();					
    glShadeModel (GL_SMOOTH);
     
     
    glLightfv( GL_LIGHT0, GL_POSITION, g_LightPosition);
    glLightfv( GL_LIGHT0, GL_DIFFUSE, g_LightDiffuse);
    glLightfv( GL_LIGHT0, GL_AMBIENT, g_LightAmbient);
     
     
    glLightfv( GL_LIGHT1, GL_POSITION,g1_LightPosition);
    glLightfv( GL_LIGHT1, GL_DIFFUSE, g1_LightDiffuse);
    glLightfv( GL_LIGHT1, GL_AMBIENT, g1_LightAmbient);
     
    glPushMatrix();
    glRotatef(view_rotx, 1.0f, 0.0f,0.0f);
    glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
    glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
     
    if(mode == GL_SELECT){
     
    for(int i = 0;i<Listcount;i++){
    			    glPushMatrix();
    			    glLoadName(i);
    			    glCallList(i);
    			    glPopMatrix();
    			    }
     
    			    }
     
    else{
    drawCoordinateGizmo();
    drawGrid();
     
    for(int i =0;i<POPSIZE;i++){
    drawApex(Population[i]);
    			}
     
    for(int i = 0;i<Listcount;i++){
    glPushMatrix();
    glCallList(i);
    glPopMatrix();
    		               }
     
    }
     
    glPopMatrix();
    this->swapBuffers();
    }
    Code :
     void OglCode::proces****s(int x, int y){
     
    const int buffsize= POPSIZE;
    GLuint select_buf[buffsize]; //selection buffer
    int hits; //number of hits
    glSelectBuffer(buffsize, select_buf);
     
    //set up view matrix here - ie do whatever transformations
    glRenderMode(GL_SELECT);
    glInitNames();
    glPushName(0);
     
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
     
    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);
     
    gluPickMatrix((GLdouble)mousex,
                   (GLdouble)(viewport[3]-mousey),
                    1, 1,
                    viewport);
    				glFrustum(-verhaeltnis, verhaeltnis, -1.0, 1.0, 4.0, 15.0);
     
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    this->swapBuffers();			
    draw();
     
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glLoadIdentity();
     
    glFlush(); //flush the pipeline
    hits = glRenderMode(GL_RENDER); //switch back to RENDER mode
    mode = GL_RENDER;
    }
    Maybe i should mention that i use QT and QGLWidget....

  2. #2
    Member Contributor
    Join Date
    Jun 2006
    Posts
    97

    Re: [Picking] hit-value returning all Objects

    When posting code in the hope that others will debug it for you, you should try to post a minimal complete, compilable reproduction case, so that interested parties can simply paste it into an empty project and tinker with it, without having to guess at the missing code (a fruitless endeavour at best).

    Posting incomplete snippets, particularly for more complex operations, is of little value, as it leaves the reader with little else to do but pour over the code, line-by-line, looking for errors, or speculate on the numerous pitfalls you may have encountered.

    Short of reducing your app to one postable here, consider starting with some documentation and a working demo.
    http://www.rush3d.com/reference/open...chapter12.html
    http://www.opengl.org/resources/faq/.../selection.htm
    http://www.lighthouse3d.com/opengl/picking/

    QT (QuickTime?) and QGLWidget have nothing to do with OpenGL picking. I would advise you to debug your app outside that environment if you suspect it to be at fault. You could use GLUT, for example, which is very well tested and stable on a variety of platforms.
    http://www.xmission.com/~nate/glut.html

    I hope this helps.

Similar Threads

  1. Picking Objects
    By imported_Alvaro in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-05-2012, 03:59 AM
  2. Selection and Picking for VBO objects
    By rakeshthp in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-05-2010, 12:25 PM
  3. Problems with Picking objects
    By Kumar K in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-11-2004, 11:08 PM
  4. picking objects
    By billy in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 12-28-2000, 05:32 AM
  5. picking objects on the viewport
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-15-2000, 09:20 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