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

setshade.c Example C Language Program

/*
Example setshade.c:
Moves a smooth-shaded polygon in and out of the graphics port.
Press LEFTMOUSE to exit.
*/
#include <gl/gl.h>
#include <gl/device.h>
main()
{    
  unsigned short i;
  Coord x;
  prefposition(XMAXSCREEN/4,XMAXSCREEN*3/4,YMAXSCREEN/4,YMAXSCREEN*3/4);
  winopen("setshade/clip test");
  doublebuffer();
  gconfig();
  get_cmap();
  for (i=0; i<128; i++)
    mapcolor(128+i, 2*i, 0, 2*i);
  makeobj(1);
  color(128+127);
  pmv2i(100,-100);
  color(128+0);
  pdr2i(100,100);
  color(128+127);
  pdr2i(-100,100);
  color(128+0);
  pdr2i(-100,-100);
  pclos();
  closeobj();
  while (!getbutton(LEFTMOUSE)) {
    for (x = -150.0; x < 150.0; x++) {
      color(CYAN);
      clear();
      pushmatrix();
      translate(x,150.0,0.0);
      rotate(300,'z');
      callobj(1);
      popmatrix();
      swapbuffers();
      if (getbutton(LEFTMOUSE))
        break;
    }
    for (x=150.0; x>-150.0; x--) {
      color(CYAN);
      clear();
      pushmatrix();
      translate(x,150.0,0.0);
      rotate(300,'z');
      callobj(1);
      popmatrix();
      swapbuffers();
      if (getbutton(LEFTMOUSE))
        break;
    }
  }
  restore_cmap();
  gexit();
}
#define lo_end 128
#define hi_end 255
static Int16 CarrayR[hi_end+1], CarrayG[hi_end+1], CarrayB[hi_end+1];
get_cmap()
{
  getmcolors ((Int16)lo_end,(Int16)hi_end, CarrayR, CarrayG, CarrayB);
}
restore_cmap()
{
  mapcolors ((Int16)lo_end,(Int16)hi_end, CarrayR, CarrayG, CarrayB);
}
/*
  Changes:
  - This needed the pclos() call after defining the polygon
  - The mapcolor were changed to mapcolors
  - The getmcolor were changed to getmcolors
  - The mapcolors needs casting to an integer
  - loop constructs removed from restore_cmap and get_cmap
  - the index variable was removed
*/

Related Information


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