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 2 of 2

Thread: Problem with Feedback Mode / Selection / glPassthrough

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2000
    Posts
    2

    Problem with Feedback Mode / Selection / glPassthrough

    The programm I wrote draws the planet earth. This sphere is constructed as icosahedron (12 faces) containing 12 pentagons and loads of hexagons.
    Before I draw a pentagon or a hexagon I pass a token via glPassthrough in order to recognize later on the selected element - of coz outside glBegin, glEnd.

    Unfortunately the feedback-result does not work. Without Feedbackmode I see exactly just a piece of the whole globe. But as soons as I am in Feedback Mode and I select an element the feddbackbuffer simply contains the elements
    in the same order as they were put in.

    when the planet is draw the tokens are 1 2 3 4 5 6 7 8 9 etc.
    when elements are selected i would expect for
    example just 7, 8 and 9 but instead I get the full list from 1 2 3 4 5 6 etc.

    I already spent ages on that topic - If somebody has a hint - thanks!


    //################################################## ##############################
    // MY PROBLEM ! !
    //################################################## ##############################
    void vOrbit::checkHits( int x, int y )
    {
    GLfloat feedbackBuf[BUFSIZE];
    GLint size;
    GLint viewport[4];
    GLdouble matrix[16];

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glGetIntegerv( GL_VIEWPORT, viewport );
    glGetDoublev( GL_PROJECTION_MATRIX, matrix );

    glRenderMode( GL_FEEDBACK );
    glMatrixMode( GL_PROJECTION );
    glPushMatrix();
    glLoadIdentity();

    gluPickMatrix( (double)x, (double)(viewport[3]-y), 200.0, 200.0, viewport );
    gluPerspective(45.0, (GLfloat)viewport[3]/(GLfloat)viewport[2] ,1.0, 200.0);

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    glSetCamera();

    planeta.drawPlanet(-1); // glCallList(glList);

    glMatrixMode(GL_PROJECTION);
    glPopMatrix(); // Projection Matrix
    glMatrixMode(GL_MODELVIEW);

    size = glRenderMode( GL_RENDER );
    cout << "! vOrbit::checkHits() size = " << size << " at (x,y)=(" << x << ", " << y << ")." << endl;
    if (size!=0) proces****s( size, feedbackBuf );

    glutSwapBuffers();
    }


    //################################################## ##############################
    void vOrbit: roces****s( int size, GLfloat *buffer )
    {
    int count;
    GLfloat token=0.0;
    GLfloat *ptr = buffer;
    int i=0;
    int flag=0;
    Vector3<float> r,p;

    if (size==-1) size=BUFSIZE;

    count=size;

    while (count>0)
    {
    token=buffer[size-count]; count--;

    if (token==GL_PASS_THROUGH_TOKEN)
    {
    cout << "* vOrbit: roces****s() Pass_Through_Token = " << buffer[size-count] << endl;
    count--;
    }
    else if (token==GL_POLYGON_TOKEN)
    {
    i= (int)buffer[size-count]; count--;

    cout << "* vOrbit: roces****s() POLYGON = " << token << " Number = " << i << endl;

    while(i && (count>0))
    {
    cout << "* vOrbit: roces****s() (x,y,z,count)=(" << buffer[size-count] << ", "
    << buffer[size-count+1] << ", " << buffer[size-count+2] << ", " << count << " )." << endl;

    count-=3;
    i--;
    }
    }
    else
    {
    cout << "* vOrbit: roces****s() Unknown Token found: " << token << endl;
    return;
    }
    }
    }

    . . .

    //################################################## ##############################
    // Position Camera in the scene with variables zoom, xrot,yrot and zrot
    //################################################## ##############################
    void vOrbit::glSetCamera( void )
    {
    glLoadIdentity();

    glTranslatef( 0.0, 0.0, zoom );
    glRotatef(xRot, 1.0, 0.0, 0.0 );
    glRotatef(yRot, 0.0, 1.0, 0.0 );
    glRotatef(zRot, 0.0 , 0.0 , 1.0 );
    }

    //################################################## ##############################
    void vOrbit::glDisplay( )
    {
    //cout << "vOrbit::glDisplay()" << flush << endl;

    glShadeModel( GL_SMOOTH );
    glClear(GL_COLOR_BUFFER_BIT);

    glSetCamera();

    glBegin (GL_LINES);
    glColor3f(1.0, 0.0, 0.0);
    glVertex3f(-10.0, 0.0, 0.0);
    glVertex3f( 10.0, 0.0, 0.0);

    glColor3f(0.0, 1.0, 0.0);
    glVertex3f( 0.0, 0.0,-10.0);
    glVertex3f( 0.0, 0.0, 10.0);

    glColor3f(0.0, 0.0, 1.0);
    glVertex3f( 0.0,-10.0, 0.0);
    glVertex3f( 0.0, 10.0, 0.0);
    glEnd();

    if (glList<0)
    {
    glList=glGenLists(1);
    planeta.drawPlanet(glList);
    }
    glCallList(glList);
    glutSwapBuffers();
    }

    . . .

    . . .

    //################################################## ##############################
    void vOrbit::glMouse(int button, int state, int x, int y)
    { . . .
    if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
    checkHits(x,y);
    . . .
    }

    //################################################## ##############################
    void vOrbit::glReshape( int width, int height )
    {
    GLfloat h = (GLfloat) width / (GLfloat) height;

    glViewport( 0, 0, width, height );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();

    gluPerspective(45.0, h ,1.0, 200.0);
    glMatrixMode( GL_MODELVIEW );

    }

    //################################################## ##############################
    //
    //################################################## ##############################
    void vOrbit::glInit( void )
    {
    GLfloat pos0[] = { 20.0, 20.0, 100.0 };
    GLfloat specular0[] = { 0.5, 0.5, 0.5, 0.15 };
    GLfloat shininess0[]= { 10.0, 10.0, 10.0 };
    GLfloat diffuse0[] = { 0.5, 0.5, 0.5, 0.5 };

    glClearColor (0.0, 0.0, 0.5, 1.0);
    glLightModelf( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_LIGHT_MODEL_AMBIENT);


    glLightfv(GL_LIGHT0, GL_POSITION, pos0);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse0);
    glMaterialfv(GL_FRONT, GL_SPECULAR, specular0 );
    glMaterialfv(GL_FRONT, GL_SHININESS, shininess0);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);


    glPolygonMode(GL_FRONT, GL_FILL);
    glEnable(GL_DITHER);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glCullFace(GL_BACK);
    glFrontFace(GL_CCW);
    glEnable(GL_CULL_FACE);

    glDisable(GL_ALPHA_TEST);
    glDisable(GL_BLEND);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glColorMaterial(GL_FRONT, GL_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);

    glEnable( GL_DEPTH_TEST );
    }

    //################################################## ##############################
    void vOrbit::glReset( void )
    {
    glLightModelf( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_LIGHT_MODEL_AMBIENT);
    glInit();
    }

  2. #2
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Italy
    Posts
    77

    Re: Problem with Feedback Mode / Selection / glPassthrough

    Ensure you call glSelectBuffer before entering feedback mode.
    Actually, I can't see the call here in your code.
    --
    Paolo M.

Posting Permissions

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