[ Previous | Next | Contents | Glossary | Home | Search ]
GL3.2 for AIX: Graphics Library (GL) Technical Reference

pick1.c Example C Language Program

/*
 *  pick1.c:
 *
 *A sample picking program. Use LEFTMOUSE to "pick" the
 *background, a circle, or the square.
 */
#include <gl/gl.h>
#include <gl/device.h>
#define PICKS 1
main()
{
   short namebuffer[50];
   long numpicked;
   short val, i, j, k;
   Device dev;    
   initialize();    
   while (TRUE) {        
      dev = qread(&val);        
      if (val == 0)
         continue;
      switch (dev) {
      case ESCKEY:
         gexit();
         exit(0);
      case REDRAW:
         reshapeviewport();
         color(BLACK);
         clear();
         callobj(PICKS);
         break;            
      case LEFTMOUSE:
         pick(namebuffer, 50);
         ortho2(-0.5, XMAXSCREEN + 0.5, -0.5, 
             YMAXSCREEN + 0.5);
         callobj(PICKS);
         numpicked = endpick(namebuffer);
         printf("hits: %d; ",numpicked);
         j = 0;
         for (i = 0; i < numpicked; i++) {
            printf(" ");
            k = namebuffer[j++];
            printf("%d ", k);
            for (;k; k--)
               printf("%d ", namebuffer[j++]);
            printf("|");
         }
         printf("\n");
         break;
      default:
         break;
      }
   }
}
initialize()
{
   int gid;    
   prefposition(XMAXSCREEN/4,XMAXSCREEN*3/4,
       YMAXSCREEN/4,YMAXSCREEN*3/4);
   gid = winopen("pick1");    
   ortho2(-0.5, XMAXSCREEN + 0.5, -0.5, YMAXSCREEN + 0.5);    
   qdevice(ESCKEY);
   qdevice(REDRAW);
   qdevice(LEFTMOUSE);
   qdevice(MIDDLEMOUSE);
   qenter(REDRAW,gid);    
   initnames();
   makeobj(PICKS);
   color(RED);
   loadname(1);
   rectfi(20,20,100,100);
   loadname(2);
   pushname(3);
   circi(50,500,50);
   loadname(4);
   circi(50,530,60);
   loadname(5);
   move2i(30,30);
   draw2i(32,32);
   closeobj();
}

Related Information

The endpick subroutine, initnames subroutine, loadname subroutine, pick subroutine, pushname subroutine.


[ Previous | Next | Contents | Glossary | Home | Search ]