home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / aix / 8823 < prev    next >
Encoding:
Text File  |  1992-08-14  |  1.9 KB  |  71 lines

  1. Path: sparky!uunet!gatech!news.byu.edu!yvax.byu.edu!cunyvm!rohvm1!rs0thp
  2. Newsgroups: comp.unix.aix
  3. Subject: Screen Capture of GL window (gltoppm) Almost..
  4. Message-ID: <92227.144843RS0THP@rohvm1.rohmhaas.com>
  5. From: Dr. Thomas Pierce <RS0THP@rohvm1.rohmhaas.com>
  6. Date: Fri, 14 Aug 1992 14:48:43 EDT
  7. Organization: Rohm and Haas Company
  8. Lines: 61
  9.  
  10.  
  11. I earlier posted a request to capture the GL window generated by
  12. my molecular modeling codes. They use the sabine card and 24 bits
  13. graphics which is pretty to view, but a &^%$#( to try and save or plot.
  14.  
  15. I'd like to get the window in a pnm type format and then to
  16. colorsposcript or IBM 24 xwd format. (Enhanced X?).
  17.  
  18. I received a program (included) that does not work for me. Core dumps.
  19. Has anyone used this on IBM 3.2 (Fred are you out there?).
  20.  
  21. Please help.
  22.  
  23. #include <malloc.h>
  24. #include <stdio.h>
  25. #include <gl/gl.h>
  26. #include <gl/device.h>
  27.  
  28. GLtoppm(char *fname)
  29. /* Read the active GL-window and write a ppm file */
  30. /* Fred Hucht 1992 */
  31. {
  32.    Int16 *buf,  R[256], G[256], B[256];
  33.    Int32 dx, dy, dxdy, i;
  34.    register Int32 ix, iy;
  35.    FILE *tn;
  36.  
  37.    getsize  (&dx, &dy);
  38.    dxdy = dx*dy;
  39.    buf = malloc(sizeof (Int16) * dxdy);
  40.    readsource(SRC_AUTO);
  41.    printf("Reading %d of %d Pixels.\n",rectread (0, 0, dx-1, dy-1, buf),dxdy);
  42.    clear(); sleep(1); rectwrite (0, 0, dx-1, dy-1, buf); /* Little joke...
  43.                                       Delete this line if you don't like it. */
  44.  
  45.    getmcolors(0,255,R,G,B); /* Load colormap. Change 255 to 2^24-1 for 24 Bit.
  46. */
  47.    printf("Writing ppm-file '%s'\n",fname);
  48.    tn = fopen(fname, "w+");
  49.    fprintf(tn,"P6\n%d %d\n255\n",dx,dy); /* Write ppm-Header. */
  50.    for (iy = dy-1; iy >= 0; iy--) for (ix = 0; ix < dx; ix++)
  51.    {
  52.     i = iy * dx + ix;
  53.     putc( (char)R[buf[i]],tn); /* Write RGB bytes */
  54.     putc( (char)G[buf[i]],tn);
  55.     putc( (char)B[buf[i]],tn);
  56.    }
  57.    fclose(tn);
  58.    free(buf);
  59.    printf("Ready !!\n");
  60. }
  61.  
  62. main(argc,argv)
  63. int
  64.   argc;
  65.  
  66. char
  67.   **argv[];
  68. {
  69.   GLtoppm(argv[1]);
  70. }
  71.