home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Graphics / SPD / Sources / drv_hp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-10  |  2.1 KB  |  91 lines  |  [TEXT/R*ch]

  1. /*
  2.  * drv_hp.c - a budget displayer for HP workstations, by Eric Haines
  3.  *
  4.  * A real kludge, I admit - do want you want in gopen().
  5.  *
  6.  * I assume you're in X windows and start with a graphics window:
  7.     xwcreate -depth 24 -g 480x512+0+0 GraphWin
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <starbase.c.h>
  12. #include "drv.h"
  13.  
  14. #define    ClrList(c) (float)((c)[0]), (float)((c)[1]), (float)((c)[2])
  15. static int FD = -1 ;
  16. static double X_res, Y_res ;
  17.  
  18. void
  19. display_clear()
  20. {
  21.     /* Insert code to clear the graphics display here */
  22.     clear_control( FD, CLEAR_VDC_EXTENT ) ;
  23.     clear_view_surface( FD ) ;
  24. }
  25.  
  26. void
  27. display_init(xres, yres, bk_color)
  28.     int xres, yres;
  29.     COORD3 bk_color;
  30. {
  31.     /* Insert code to open/initialize the graphics display here */
  32.     if ( -1 == ( FD =
  33.     gopen( "/dev/screen/GraphWin", OUTINDEV, NULL, INIT|ACCELERATED) ) ) {
  34.  
  35.     fprintf( stderr, "could not open device for output!\n" ) ;
  36.     return ;
  37.     }
  38.     shade_mode( FD, CMAP_FULL|INIT, FALSE ) ;
  39.     mapping_mode( FD, TRUE ) ;
  40.     background_color( FD, ClrList( bk_color ) ) ;
  41.     display_clear() ;
  42.     X_res = xres ;
  43.     Y_res = yres ;
  44. }
  45.  
  46. void
  47. display_close(wait_flag)
  48.     int wait_flag ;
  49. {
  50.     /* Insert code to close the graphics display here */
  51.     gclose( FD ) ;
  52. }
  53.  
  54. /* currently not used for anything, so you don't have to implement */
  55. void
  56. display_plot(x, y, color)
  57.     int x, y;
  58.     COORD3 color;
  59. {
  60.     float clist[2] ;
  61.  
  62.     /* Insert code to plot a single pixel here */
  63.     marker_color( FD, ClrList( color ) ) ;
  64.     clist[0] = (float)x/X_res ;
  65.     clist[1] = (float)y/Y_res ;
  66.     polymarker2d( FD, clist, 1, FALSE ) ;
  67. }
  68.  
  69. /* weirdly enough, x and y are centered around the origin */
  70. void
  71. display_line(x0, y0, x1, y1, color)
  72.     int x0, y0, x1, y1;
  73.     COORD3 color;
  74. {
  75.     /* Insert line drawing code here */
  76.     line_color( FD, ClrList( color ) ) ;
  77.     move2d( FD, (float)(((double)x0+X_res*0.5)/X_res),
  78.         (float)(((double)y0+Y_res*0.5)/Y_res) ) ;
  79.     draw2d( FD, (float)(((double)x1+X_res*0.5)/X_res),
  80.         (float)(((double)y1+Y_res*0.5)/Y_res) ) ;
  81. }
  82.  
  83. int
  84. kbhit()
  85. {
  86.     /* Insert keyboard hit (i.e. interrupt operation) test code here */
  87.  
  88.     /* currently always no interrupt */
  89.     return( 0 ) ;
  90. }
  91.