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

draw.c Example C Language Program

/*
draw.c
An absolutely minimal line drawing program.
*/
#include <gl/gl.h>
#include <gl/device.h>
main()
{
   Device dev;
   short val;
   unsigned short xpos, ypos;    
   initialize();    
   while(TRUE) {        
      dev = qread(&val);        
      switch(dev) {               /* wait for mouse down */
      case ESCKEY:                /* quit */
         gexit();
         exit(0);
      case REDRAW:
         reshapeviewport();
         color(BLACK);
         clear();
         color(RED);
         break;
      case MIDDLEMOUSE:           /* move */
         qread(&xpos);
         qread(&ypos);
         move2i(xpos, ypos);
         qread(&val);              /* these three reads clear out */
         qread(&val);              /* the queue */
         qread(&val);
         break;            
      case LEFTMOUSE:             /* draw */
         qread(&xpos);
         qread(&ypos);
         draw2i(xpos, ypos);
         qread(&val);
         qread(&val);
         qread(&val);
         break;
      }
   }
}
initialize()
{
   int gid;
   float xmax,ymax;   
   prefposition(XMAXSCREEN/4, XMAXSCREEN*3/4, YMAXSCREEN/4, 
       YMAXSCREEN*3/4);
   gid = winopen("draw");   
   xmax = .5 + (float) XMAXSCREEN;
   ymax = .5 + (float) YMAXSCREEN;
   ortho2(xmax/4.0,xmax*3.0/4.0,ymax/4.0,ymax*3.0/4.0);   
   qdevice(ESCKEY);
   qdevice(LEFTMOUSE);
   qdevice(MIDDLEMOUSE);
   tie(LEFTMOUSE, MOUSEX, MOUSEY);
   tie(MIDDLEMOUSE, MOUSEX, MOUSEY);   
   color(BLACK);
   clear();
   color(RED);
}

Related Information

The getdrawmode subroutine .

Understanding the Frame Buffer in GL in GL3.2 Version 4 for AIX: Programming Concepts explains the use of different buffers.


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]