Re: XForms: selection doesn't work with glcanvas?

From: Praveen Thiagarajan (
Date: Thu Jun 21 2001 - 12:51:29 EDT

  • Next message: H Tjandrasa: "XForms: Toggle Switch object"

    # To subscribers of the xforms list from Praveen Thiagarajan <> :

    On Thu, 21 Jun 2001, Dianna Xu wrote:

    > # To subscribers of the xforms list from Dianna Xu
    <> :
    > Hi,
    > Has anyone successfully programmed openGL's selection (via
    > glRenderMode(GL_SELECT) in an xforms openGL canvas? I have been trying
    > get it to work for 3 days.
    > Finainally in a moment's desperation tonight, I rewrote the code using
    > glut to manage the gl window and events, just for the heck of it. and
    > guess what, the selection worked! All functions were almost identical,
    > except for minor details like event masks. Does this mean that selection
    > will not work under xforms glcanvas? This will be a major setdown
    > I switched from glut to xforms in the first place in the hope that the
    > GUI will be much easier to handle.
    > Any help greatly appreciated!
    > -Di

    I have used opengl's selection successfully in an xforms glcanvas. What I
    do is pretty much the same as the sample code in the red book except a
    few modifications to get the keymask. If your code works in glut check
    the following code it might help solve ur problem

    int mbutton_cb(FL_OBJECT *ob, Window win, int w, int h, XEvent *xev,
                   void *ud)
      FL_Coord x, y;
      unsigned int keymask;
      GLuint selectBuf[BUFSIZE];
      GLint hits;
      GLint viewport[4];

      fl_get_win_mouse(fl_get_canvas_id(ui->canvas), &x, &y, &keymask);
      switch(xev->xbutton.button) {
      case Button1:
        glGetIntegerv(GL_VIEWPORT, viewport);

        glSelectBuffer(BUFSIZE, selectBuf);
        (void) glRenderMode(GL_SELECT);



        gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y),
                      2.0, 2.0, viewport);
        if (!orthographic_mode) {
          gluPerspective(45.0, (GLfloat) w/h, 0.1, 10000.0);
          glTranslatef( 0.0, 0.0, -60.0 );
        } else {
          glOrtho (0.0, (GLdouble) w, 0.0, (GLdouble) h, -1.0, 10000.0);
          glTranslatef((GLdouble) w/2, (GLdouble) h/2, 0.0 );

        hits = glRenderMode(GL_RENDER);
        if (debug)
        processHits(hits, selectBuf);


    To unsubscribe, send the message "unsubscribe" to or see
    XForms Home Page:
    List Archive:

    This archive was generated by hypermail 2b29 : Thu Jun 21 2001 - 13:02:29 EDT