[comp.graphics] Help needed with Sun graphics routines.

sz@cci632.UUCP (Stephen Zehl) (09/29/90)

-
	Hopefully this will be a simple question for someone out there who
wouldn't mind taking a second to help out a new Sun user.

	I'm learning how to draw on my Sun IPC, and in fact I've had good
luck at drawing my Mandelbrot sets using the <cgidefs.h> package, except that
calculating 30,000 x 30,000 pixels takes many many hours.  I recently ran into
the suntool graphics package and have been able to draw, but only in B/W.
I'm having trouble learning how to manipulate the PIX_SRC bit map field to 
change colors. (Or at least this is how I believe I should do it.) Is the
problem that I have to set up a color table first?  How would I go about doing 
that?  Below you will find a simple program I wrote to draw some lines, could 
someone modify it to make the lines colored. (I always learn best from 
examples.)  Thanks a million.
				Steve.

 CCCC  CCCC IIII     Stephen Zehl          Internet: cci632!sz@cs.rochester.EDU
CC    CC     II   Computer Consoles. Inc.    or 
CC    CC     II    Rochester, New York.    Usenet:  rutgers!rochester!cci632!sz
 CCCC  CCCC IIII       DISCLAIMER: I speak for myself, not for my employer.

----------------------------------------------------------------------------
#include <suntool/sunview.h>
#include <suntool/canvas.h>

main()
{
Frame	frame;
Canvas 	canvas;
Pixwin	*pw;
int i;

frame = window_create(NULL,FRAME,0);
canvas = window_create(frame,CANVAS,0);

pw=canvas_pixwin(canvas);

for (i=5; i<=700; i+=7)
{
pw_vector(pw,5,i,700-i,5, PIX_SRC,1);
pw_vector(pw,5,700-i,i,5, PIX_SRC,1);

pw_vector(pw,i,5,700,i, PIX_SRC,1);
pw_vector(pw,700,700-i,700-i,5, PIX_SRC,1);

pw_vector(pw,700,i,700-i,700, PIX_SRC,1);
pw_vector(pw,i,700,700,700-i, PIX_SRC,1);

pw_vector(pw,5,700-i,700-i,700, PIX_SRC,1);
pw_vector(pw,5,i,i,700, PIX_SRC,1);
}

window_main_loop(frame);
exit(0);
}

guansy@cs.tamu.edu (Sheng-Yih Guan) (09/30/90)

>Below you will find a simple program I wrote to draw some lines, could 
>someone modify it to make the lines colored. (I always learn best from 
>examples.)  Thanks a million.


/* What you need to do is: 			 		*/
/*   1. change the colormap in the routine setup_colourmap	*/
/*   2. change pw_vector(pw,5,i,700-i,5, PIX_SRC,1)		*/
/*	==> pw_vector(pw,5,i,700-i,5, PIX_SRC, 0<=anyvalue<=255)*/
/*   3. cc <inputfile>  -lsuntool -lsunwindow -lpixrect -lm 	*/
/* This program has been tested.  It compliles o.k.  But, need  */
/* to be tested on a color monitor.				*/


#include <suntool/sunview.h>
#include <suntool/canvas.h>
#include <stdio.h>


Frame	 frame, any_frame;
Canvas 	 canvas, test_canvas;
Pixwin	 *pw, *test_pw;
int      colour;
int	 mono_override;
unsigned char  red[256], green[256], blue[256];
colormap_t colormap;
int      iscolour();

main()
{
int i;

frame = window_create(NULL,FRAME,0);
canvas = window_create(frame,CANVAS,0);

pw=canvas_pixwin(canvas);

for (i=5; i<=700; i+=7)
{
pw_vector(pw,5,i,700-i,5, PIX_SRC,1);
pw_vector(pw,5,700-i,i,5, PIX_SRC,1);

pw_vector(pw,i,5,700,i, PIX_SRC,1);
pw_vector(pw,700,700-i,700-i,5, PIX_SRC,1);

pw_vector(pw,700,i,700-i,700, PIX_SRC,1);
pw_vector(pw,i,700,700,700-i, PIX_SRC,1);

pw_vector(pw,5,700-i,700-i,700, PIX_SRC,1);
pw_vector(pw,5,i,i,700, PIX_SRC,1);
}

/* the following objects are temporary created for testing if the 
   workstation is colour or not */
any_frame = window_create(NULL, FRAME, FRAME_NO_CONFIRM, TRUE, 0);
test_canvas = window_create(any_frame, CANVAS, 0);
test_pw = canvas_pixwin(test_canvas);
colour = iscolour(test_pw);
window_destroy(any_frame);



if (colour) 
  {
  setup_colourmap(pw);
  }


window_main_loop(frame);
exit(0);
}

int
iscolour(pw)
Pixwin *pw;
  {

  return ((pw->pw_pixrect->pr_depth > 1) ? TRUE : FALSE);
  }


static char    cmsname[BUFSIZ];

setup_colourmap(fpw)
  {
  register int i;

  for (i = 0; i < 256; i++) 
    {
    red[i] = green[i] = blue[i] = -1;
    }


  if (colormap.type == RMT_NONE || colormap.length == 0) 
    {
    /*sprintf(cmsname, "greyscale%d", pr->pr_depth);*/
    sprintf(cmsname, "greyscale%d", 8);

    pw_setcmsname(fpw, cmsname);

    for (i = 1; i < 255; i++) 
      {
      red[i] = i;
      green[i] = i;
      blue[i] = i;
      }
    if (mono_override) 
      {
      red[255] = blue[255] = green[255] = 255;
      red[0] = blue[0] = green[0] = 0;
      }
    pw_putcolormap(fpw, 0, 256, red, green, blue);
    } 
  else 
    {
    pw_setcmsname(fpw, "non_greyscale");
    pw_putcolormap(fpw, 0, colormap.length, colormap.map[0], 
                   colormap.map[1], colormap.map[2]);
    }
  window_set(frame, FRAME_INHERIT_COLORS, TRUE, 0);
  }

 _       _   _                            ___________          
|  \    /_| / /    Visualization Lab     /____  ____/         
 \  \  //  / /   Computer Science Dept       / /  _   _    _   _   
  | | //  / /     Texas A&M University      / /  / | | \  / | | | ||
  | |//  / / College Station, TX 77843-3112/ /  / /| |  \//|| | | ||
  /  /  / /____    Tel: (409)845-0531     / /  / -|| | |\/ || | !_!| 
 !__/  /______/ stanley@visual1.tamu.edu /_/  /_/ || !_!   || !____!



CSNET: stanley%visual1.tamu.edu@relay.cs.net
Internet: stanley@visual1.tamu.edu