Personal Iris lighting problems

Robert Ringrose ringrose at fibula.ai.mit.edu
Thu Mar 14 04:52:52 AEST 1991


In article <1991Mar13.062945.5092 at odin.corp.sgi.com> howardl at sgi.com (Howard Look) writes:
>
>Using mmode(MPROJECTION) is not a usual thing to do.
No kidding, but is there another way to access the projection matrix so
you can go from points on the screen to points in world coordinates?

>Here is an example of a rotating infinite light source. The light is
>made to rotate by binding while a rotation is part of the current matrix.
>The light is only bound once.

[Example program deleted]

Howard:

I have taken your example program and made a few changes so that it
illustrates the bug I am running into.

As it is here, the lights do not move.  If, however, you uncomment the
line mmode(MPROJECTION), marked with a "+++" comment, the light source
begins to move, despite the fact that the very next line returns you
to MVIEWING mode.

Once again, I am running this on a Personal Iris 4D/25 and have no idea
if other SGI workstations have the same problem.


	- Robert Ringrose


"There's always one more bu6"
--------------- Cut here -------------------

/*
 * lights.c
 * Compile with
 * cc lights.c -o lights -lsphere -lgl_s -lm
 */

#include <gl/gl.h>
#include <gl/device.h>
#include <gl/sphere.h>

/* macro to count the number of properties in an array */
#define NP(array) ((sizeof(array)/(sizeof(array[0]))))

void initialize(void);
void drawscene(void);

/* size of the window */
int xmax, ymax;

/* different light positions */
#define EYE 1
#define WORLD 2
#define MOVING 3

int light_position = WORLD;
int moving_eye = FALSE;

float light_model[] =
{
	AMBIENT, 0.1, 0.1, 0.1,
	ATTENUATION, 1.0, 0.0,
	LOCALVIEWER, 0.0,
	LMNULL
};

float white_light[] =
{
	AMBIENT, 0.2, 0.2, 0.2,
	POSITION, 2.0, 2.0, -2.0, 0.0,
	LCOLOR, 1.0, 1.0, 1.0,
	LMNULL
};

float green_plastic[] =
{
	DIFFUSE, 0.1, 1.0, 0.1,
	SPECULAR, 1.0, 1.0, 1.0,
	SHININESS, 10.0,
	LMNULL
};
	
float yellow_plastic[] =
{
	DIFFUSE, 1.0, 1.0, 0.1,
	SPECULAR, 1.0, 1.0, 1.0,
	SHININESS, 10.0,
	LMNULL
};
	

void
main ()
{
	Boolean exitflag = FALSE;
    short attached=0;               /* attached to window */
    short value;                  
    int dev;                      /* input device */
	
    initialize();

    while (exitflag == FALSE)
      {
	drawscene();
		
	while ((exitflag == FALSE) && (qtest() || !attached))
	  {
	    dev = qread (&value);
	    if ((dev == ESCKEY) && (value == 0))
	      {
		exitflag = TRUE;
	      }
	    else if (dev == REDRAW)
	      {
		reshapeviewport();
	      }
	    else if (dev == INPUTCHANGE)
	      {
		attached = value;	
	      }   /*  end while qtest or not attached  */
	  }
      }   
    exit(0);
}   /*  end main()  */


void
initialize(void)
{
    int gid;
	
    xmax = getgdesc(GD_XPMAX);
    ymax = getgdesc(GD_YPMAX);
    prefposition( xmax/4, xmax*3/4, ymax/4, ymax*3/4 );
    gid = winopen ("light1");
    minsize (xmax/10, ymax/10);
    keepaspect (xmax, ymax);
    winconstraints();

	RGBmode();
	doublebuffer();
    gconfig ();

	zbuffer(TRUE);
	
	qdevice(ESCKEY);
	qenter(REDRAW,gid);

	/* double matrix mode since using lighting */
	mmode(MVIEWING);

	/* define the light model, light source, and material */
	lmdef(DEFLMODEL, 1, NP(light_model), light_model);
	lmdef(DEFLIGHT, 1, NP(white_light), white_light);
	lmdef(DEFMATERIAL, 1, NP(green_plastic), green_plastic);
	lmdef(DEFMATERIAL, 2, NP(yellow_plastic), yellow_plastic);

	/* bind the light model */
	lmbind(LMODEL, 1);
}


void
drawscene(void)
{
  static int angle = 0;
  static float unit[] = {0.0,0.0,0.0,1.0};


  czclear(0x0, getgdesc(GD_ZMAX));

  lmbind(LIGHT0, 1);

  pushmatrix();
  perspective(450, (float)xmax/(float)ymax, 1.0, 10.0);

  polarview(5.0, 0, 0, 0);

  rotate(-900, 'x');
/* +++ */
/*  mmode(MPROJECTION); */
  mmode(MVIEWING);

  pushmatrix();
  translate(-1.0, 0.0, 0.0);
  lmbind(MATERIAL,1);
  sphdraw(unit);
  popmatrix();
  
  pushmatrix();
  translate(1.0, 0.0, 0.0);
  
  lmbind(MATERIAL,2);
  sphdraw(unit);

  /* turn off material so later objects will not be lit */
  lmbind(MATERIAL,0);
  
  popmatrix();
	   
  popmatrix();
  
  swapbuffers();
}



More information about the Comp.sys.sgi mailing list